22 from logilab.common.testlib import mock_object |
22 from logilab.common.testlib import mock_object |
23 from yams import BadSchemaDefinition |
23 from yams import BadSchemaDefinition |
24 from rql import parse, nodes, RQLHelper |
24 from rql import parse, nodes, RQLHelper |
25 |
25 |
26 from cubicweb import Unauthorized |
26 from cubicweb import Unauthorized |
27 from cubicweb.schema import RRQLExpression |
27 from cubicweb.schema import RRQLExpression, ERQLExpression |
28 from cubicweb.rqlrewrite import RQLRewriter |
28 from cubicweb.rqlrewrite import RQLRewriter |
29 from cubicweb.devtools import repotest, TestServerConfiguration |
29 from cubicweb.devtools import repotest, TestServerConfiguration |
30 |
30 |
31 config = TestServerConfiguration('data/rewrite') |
31 config = TestServerConfiguration('data/rewrite') |
32 config.bootstrap_cubes() |
32 config.bootstrap_cubes() |
348 rqlst = parse('Card C') |
348 rqlst = parse('Card C') |
349 rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'S') |
349 rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'S') |
350 self.failUnlessEqual(rqlst.as_string(), |
350 self.failUnlessEqual(rqlst.as_string(), |
351 u"Any C WHERE C is Card, EXISTS(C owned_by A, A is CWUser)") |
351 u"Any C WHERE C is Card, EXISTS(C owned_by A, A is CWUser)") |
352 |
352 |
|
353 def test_rqlexpr_not_relation1(self): |
|
354 constraint = RRQLExpression('X owned_by Z, Z login "hop"', 'X') |
|
355 rqlst = parse('Affaire A WHERE NOT EXISTS(A documented_by C)') |
|
356 rewrite(rqlst, {('C', 'X'): (constraint,)}, {}, 'X') |
|
357 self.failUnlessEqual(rqlst.as_string(), |
|
358 u'Any A WHERE NOT EXISTS(A documented_by C, EXISTS(C owned_by B, B login "hop", B is CWUser), C is Card), A is Affaire') |
|
359 |
|
360 def test_rqlexpr_not_relation2(self): |
|
361 constraint = RRQLExpression('X owned_by Z, Z login "hop"', 'X') |
|
362 rqlst = rqlhelper.parse('Affaire A WHERE NOT A documented_by C', annotate=False) |
|
363 rewrite(rqlst, {('C', 'X'): (constraint,)}, {}, 'X') |
|
364 self.failUnlessEqual(rqlst.as_string(), |
|
365 u'Any A WHERE NOT EXISTS(A documented_by C, EXISTS(C owned_by B, B login "hop", B is CWUser), C is Card), A is Affaire') |
|
366 |
353 |
367 |
354 if __name__ == '__main__': |
368 if __name__ == '__main__': |
355 unittest_main() |
369 unittest_main() |