19 from logilab.common.testlib import unittest_main, TestCase |
19 from logilab.common.testlib import unittest_main, TestCase |
20 from logilab.common.testlib import mock_object |
20 from logilab.common.testlib import mock_object |
21 from yams import BadSchemaDefinition |
21 from yams import BadSchemaDefinition |
22 from rql import parse, nodes, RQLHelper |
22 from rql import parse, nodes, RQLHelper |
23 |
23 |
24 from cubicweb import Unauthorized |
24 from cubicweb import Unauthorized, rqlrewrite |
25 from cubicweb.schema import RRQLExpression, ERQLExpression |
25 from cubicweb.schema import RRQLExpression, ERQLExpression |
26 from cubicweb.rqlrewrite import RQLRewriter |
|
27 from cubicweb.devtools import repotest, TestServerConfiguration |
26 from cubicweb.devtools import repotest, TestServerConfiguration |
28 |
27 |
29 |
28 |
30 def setUpModule(*args): |
29 def setUpModule(*args): |
31 global rqlhelper, schema |
30 global rqlhelper, schema |
60 def annotate(rqlst): |
59 def annotate(rqlst): |
61 rqlhelper.annotate(rqlst) |
60 rqlhelper.annotate(rqlst) |
62 @staticmethod |
61 @staticmethod |
63 def simplify(mainrqlst, needcopy=False): |
62 def simplify(mainrqlst, needcopy=False): |
64 rqlhelper.simplify(rqlst, needcopy) |
63 rqlhelper.simplify(rqlst, needcopy) |
65 rewriter = RQLRewriter(mock_object(vreg=FakeVReg, user=(mock_object(eid=1)))) |
64 rewriter = rqlrewrite.RQLRewriter( |
|
65 mock_object(vreg=FakeVReg, user=(mock_object(eid=1)))) |
66 snippets = [] |
66 snippets = [] |
67 for v, exprs in snippets_map.items(): |
67 for v, exprs in sorted(snippets_map.items()): |
68 rqlexprs = [isinstance(snippet, basestring) |
68 rqlexprs = [isinstance(snippet, basestring) |
69 and mock_object(snippet_rqlst=parse('Any X WHERE '+snippet).children[0], |
69 and mock_object(snippet_rqlst=parse('Any X WHERE '+snippet).children[0], |
70 expression='Any X WHERE '+snippet) |
70 expression='Any X WHERE '+snippet) |
71 or snippet |
71 or snippet |
72 for snippet in exprs] |
72 for snippet in exprs] |
208 rewrite(rqlst, {('C', 'X'): (c1,), |
208 rewrite(rqlst, {('C', 'X'): (c1,), |
209 ('A', 'X'): (c2,), |
209 ('A', 'X'): (c2,), |
210 }, {}) |
210 }, {}) |
211 # XXX suboptimal |
211 # XXX suboptimal |
212 self.assertEqual(rqlst.as_string(), |
212 self.assertEqual(rqlst.as_string(), |
213 "Any C,A,R WITH A,R,C BEING " |
213 "Any C,A,R WITH A,C,R BEING " |
214 "(Any A,R,C WHERE A ref R, A? inlined_card C, " |
214 "(Any A,C,R WHERE A? inlined_card C, A ref R, " |
215 "(A is NULL) OR (EXISTS(A inlined_card B, B require_permission D, " |
215 "(A is NULL) OR (EXISTS(A inlined_card B, B require_permission D, " |
216 "B is Card, D is CWPermission)), " |
216 "B is Card, D is CWPermission)), " |
217 "A is Affaire, C is Card, EXISTS(C require_permission E, E is CWPermission))") |
217 "A is Affaire, C is Card, EXISTS(C require_permission E, E is CWPermission))") |
218 |
218 |
219 # def test_optional_var_inlined_has_perm(self): |
219 # def test_optional_var_inlined_has_perm(self): |
220 # c1 = ('X require_permission P') |
220 # c1 = ('X require_permission P') |
221 # c2 = ('X inlined_card O, U has_read_permission O') |
221 # c2 = ('X inlined_card O, U has_read_permission O') |
222 # rqlst = parse('Any C,A,R WHERE A? inlined_card C, A ref R') |
222 # rqlst = parse('Any C,A,R WHERE A? inlined_card C, A ref R') |