[saem-devel] [PATCH 1 of 3 seda] [views] Fix bad rql of vocabulary function

Philippe Pepiot philippe.pepiot at logilab.fr
Thu Feb 23 10:59:19 CET 2017


On 02/22/2017 03:11 PM, Sylvain Thenault wrote:
> # HG changeset patch
> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
> # Date 1487766805 -3600
> #      Wed Feb 22 13:33:25 2017 +0100
> # Node ID c8e46f1c1627828307f37a01e1192fa4ee3407e3
> # Parent  9e88b1141bb9c2fc607b199c511afd06a7ae5a0d
> [views] Fix bad rql of vocabulary function
>
> and add a test to avoid this in the future.
>
> diff --git a/test/test_views.py b/test/test_views.py
> --- a/test/test_views.py
> +++ b/test/test_views.py
> @@ -21,11 +21,13 @@ from six import text_type
>
>  from cubicweb.devtools.testlib import CubicWebTC
>  from cubicweb.web import INTERNAL_FIELD_VALUE
>
>  from cubes.seda.xsd2yams import RULE_TYPES
> -from cubes.seda.views import export, clone, mgmt_rules
> +# XXX we need this prior to import archiveunit until we use a recent version of lgc.registry
> +from cubes.seda import site_cubicweb  # noqa
> +from cubes.seda.views import archiveunit, clone, export, mgmt_rules

I don't understand the XXX ? Please explain.
Is this for monkeypatch on RelationRtags.__init__ ? If so, why not 
moving this import where it's needed, in views/__init__.py

>
>  import testutils
>
>
>  class ManagementRulesTC(CubicWebTC):
> @@ -541,7 +543,28 @@ class SEDATreeTC(CubicWebTC):
>                               [ref.eid])
>              alt_seq.cw_clear_all_caches()
>              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()
> diff --git a/views/archiveunit.py b/views/archiveunit.py
> --- a/views/archiveunit.py
> +++ b/views/archiveunit.py
> @@ -153,11 +153,11 @@ def do_ref_vocabulary(form, field):
>      req = form._cw
>      parent, container = parent_and_container(form.edited_entity)
>      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()]
>
>
>  for rtype in ('seda_data_object_reference_id', 'seda_target'):



More information about the saem-devel mailing list