# HG changeset patch # User Denis Laxalde # Date 1403878313 -7200 # Node ID 60a9cd1b3a4bf002f4882081d7c393ae05122c2a # Parent 79d34ba48612048142a920e8f8810852cadb0fa0 [CWEP002] Plug the computed relation rewriter in the querier Related to #3546717. diff -r 79d34ba48612 -r 60a9cd1b3a4b server/querier.py --- a/server/querier.py Thu Feb 13 13:58:28 2014 +0100 +++ b/server/querier.py Fri Jun 27 16:11:53 2014 +0200 @@ -594,6 +594,9 @@ # bother modifying it. This is not necessary on write queries since # a new syntax tree is built from them. rqlst = rqlst.copy() + # Rewrite computed relations + rewriter = RQLRelationRewriter(cnx) + rewriter.rewrite(rqlst, args) self._annotate(rqlst) if args: # different SQL generated when some argument is None or not (IS diff -r 79d34ba48612 -r 60a9cd1b3a4b test/unittest_rqlrewrite.py --- a/test/unittest_rqlrewrite.py Thu Feb 13 13:58:28 2014 +0100 +++ b/test/unittest_rqlrewrite.py Fri Jun 27 16:11:53 2014 +0200 @@ -697,7 +697,7 @@ 'WITH A, B BEING(Any X,Y WHERE X contributor Y)') rule_rewrite(rqlst, rules) self.assertEqual('Any A,B WHERE A contributor B WITH A,B BEING ' - '(Any X,Y WHERE X contributor Y)', + '(Any X,Y WHERE X contributor Y)', rqlst.as_string()) def test_rewrite_with4(self): @@ -711,7 +711,7 @@ 'D name "illustrator" WITH A,B BEING ' '(Any X,Y WHERE A is Contribution, A contributor X, ' 'A manifestation Y, A role B, B name "illustrator")', - rqlst.as_string()) + rqlst.as_string()) # Tests for the union def test_rewrite_union(self): @@ -780,6 +780,25 @@ rqlst.as_string()) +class RQLRelationRewriterTC(CubicWebTC): + + appid = 'data/rewrite' + + def test_base_rule(self): + with self.admin_access.client_cnx() as cnx: + art = cnx.create_entity('ArtWork', name=u'Les travailleurs de la Mer') + role = cnx.create_entity('Role', name=u'illustrator') + vic = cnx.create_entity('Person', name=u'Victor Hugo') + contrib = cnx.create_entity('Contribution', code=96, contributor=vic, + manifestation=art, role=role) + rset = cnx.execute('Any X WHERE X illustrator_of S') + self.assertEqual([u'Victor Hugo'], + [result.name for result in rset.entities()]) + rset = cnx.execute('Any S WHERE X illustrator_of S, X eid %(x)s', + {'x': vic.eid}) + self.assertEqual([u'Les travailleurs de la Mer'], + [result.name for result in rset.entities()]) + def rule_rewrite(rqlst, kwargs=None): rewriter = _prepare_rewriter(rqlrewrite.RQLRelationRewriter, kwargs)