[views] Fix bad rql of vocabulary function
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 22 Feb 2017 13:33:25 +0100
changeset 2367 718d4721d1e8
parent 2358 84afe93e0ba1
child 2368 2880952c1aba
[views] Fix bad rql of vocabulary function and add a test to avoid this in the future. Along the way "properly" handle monkey-patching necessary to import some seda views modules.
test/test_views.py
views/__init__.py
views/archiveunit.py
--- a/test/test_views.py	Wed Feb 08 16:10:18 2017 +0100
+++ b/test/test_views.py	Wed Feb 22 13:33:25 2017 +0100
@@ -23,7 +23,7 @@
 from cubicweb.web import INTERNAL_FIELD_VALUE
 
 from cubes.seda.xsd2yams import RULE_TYPES
-from cubes.seda.views import export, clone, mgmt_rules
+from cubes.seda.views import archiveunit, clone, export, mgmt_rules
 
 import testutils
 
@@ -543,5 +543,26 @@
             self.assertFalse(alt_seq.reverse_seda_data_object_reference)
 
 
+class FakeForm(object):
+    def __init__(self, req, edited_entity):
+        self._cw = req
+        self.edited_entity = edited_entity
+
+
+class ArchiveUnitVocabularyTC(CubicWebTC):
+
+    def test_do_ref_vocabulary(self):
+        with self.admin_access.web_request() as req:
+            transfer = req.cnx.create_entity('SEDAArchiveTransfer', title=u'Test')
+            bdo = testutils.create_data_object(transfer)
+            req.cnx.commit()
+            bdo.cw_clear_all_caches()
+            # actually expect a data object reference, but we want to test the query so any object
+            # linked to the container is fine
+            form = FakeForm(req, bdo)
+            self.assertEqual(archiveunit.do_ref_vocabulary(form, None),
+                             [(u'data object title', text_type(bdo.eid))])
+
+
 if __name__ == '__main__':
     unittest.main()
--- a/views/__init__.py	Wed Feb 08 16:10:18 2017 +0100
+++ b/views/__init__.py	Wed Feb 22 13:33:25 2017 +0100
@@ -24,6 +24,9 @@
 # XXX alias to avoid side effect: uicfg will become our uicfg submodule. Not necessary with 3.23?
 from cubicweb.web.views import uicfg as cwuicfg
 
+# XXX trigger monkey patches necessary to import this module, until we use a recent version of
+# lgc.registry supporting instantiation of rtags with explicit __module__ argument
+from .. import site_cubicweb  # noqa
 from ..xsd import XSDM_MAPPING
 from ..xsd2uicfg import FIRST_LEVEL_ETYPES
 from .widgets import SEDAMetaField
--- a/views/archiveunit.py	Wed Feb 08 16:10:18 2017 +0100
+++ b/views/archiveunit.py	Wed Feb 22 13:33:25 2017 +0100
@@ -155,7 +155,7 @@
     assert container is not None
     rset = req.execute('Any X, XUA ORDERBY XUA WHERE '
                        'X is IN(SEDABinaryDataObject, SEDAPhysicalDataObject), '
-                       ', X user_annotation XUAX container R, R eid %(root)s',
+                       'X user_annotation XUA, X container R, R eid %(root)s',
                        {'root': container.eid})
     return [(entity.dc_title(), str(entity.eid)) for entity in rset.entities()]