author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 30 Mar 2010 17:50:09 +0200 | |
branch | stable |
changeset 5084 | d8f491cb046c |
parent 4908 | b3ad329cbe17 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3826
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
7 |
""" |
0 | 8 |
from logilab.common.testlib import unittest_main, TestCase |
9 |
from logilab.common.testlib import mock_object |
|
4908
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
10 |
from yams import BadSchemaDefinition |
0 | 11 |
from rql import parse, nodes, RQLHelper |
12 |
||
13 |
from cubicweb import Unauthorized |
|
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
14 |
from cubicweb.schema import RRQLExpression |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
15 |
from cubicweb.rqlrewrite import RQLRewriter |
0 | 16 |
from cubicweb.devtools import repotest, TestServerConfiguration |
17 |
||
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
18 |
config = TestServerConfiguration('data/rewrite') |
0 | 19 |
config.bootstrap_cubes() |
20 |
schema = config.load_schema() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
21 |
from yams.buildobjs import RelationDefinition |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
22 |
schema.add_relation_def(RelationDefinition(subject='Card', name='in_state', object='State', cardinality='1*')) |
1787 | 23 |
|
0 | 24 |
rqlhelper = RQLHelper(schema, special_relations={'eid': 'uid', |
25 |
'has_text': 'fti'}) |
|
26 |
||
27 |
def setup_module(*args): |
|
28 |
repotest.do_monkey_patch() |
|
29 |
||
30 |
def teardown_module(*args): |
|
31 |
repotest.undo_monkey_patch() |
|
1787 | 32 |
|
0 | 33 |
def eid_func_map(eid): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
34 |
return {1: 'CWUser', |
0 | 35 |
2: 'Card'}[eid] |
36 |
||
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
37 |
def rewrite(rqlst, snippets_map, kwargs, existingvars=None): |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
38 |
class FakeVReg: |
0 | 39 |
schema = schema |
40 |
@staticmethod |
|
41 |
def solutions(sqlcursor, mainrqlst, kwargs): |
|
42 |
rqlhelper.compute_solutions(rqlst, {'eid': eid_func_map}, kwargs=kwargs) |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
43 |
class rqlhelper: |
0 | 44 |
@staticmethod |
45 |
def annotate(rqlst): |
|
46 |
rqlhelper.annotate(rqlst) |
|
47 |
@staticmethod |
|
48 |
def simplify(mainrqlst, needcopy=False): |
|
49 |
rqlhelper.simplify(rqlst, needcopy) |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
50 |
rewriter = RQLRewriter(mock_object(vreg=FakeVReg, user=(mock_object(eid=1)))) |
0 | 51 |
for v, snippets in snippets_map.items(): |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
52 |
snippets_map[v] = [isinstance(snippet, basestring) |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
53 |
and mock_object(snippet_rqlst=parse('Any X WHERE '+snippet).children[0], |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
54 |
expression='Any X WHERE '+snippet) |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
55 |
or snippet |
0 | 56 |
for snippet in snippets] |
57 |
rqlhelper.compute_solutions(rqlst.children[0], {'eid': eid_func_map}, kwargs=kwargs) |
|
58 |
solutions = rqlst.children[0].solutions |
|
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
59 |
rewriter.rewrite(rqlst.children[0], snippets_map.items(), solutions, kwargs, |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
60 |
existingvars) |
0 | 61 |
test_vrefs(rqlst.children[0]) |
62 |
return rewriter.rewritten |
|
63 |
||
64 |
def test_vrefs(node): |
|
65 |
vrefmap = {} |
|
66 |
for vref in node.iget_nodes(nodes.VariableRef): |
|
67 |
vrefmap.setdefault(vref.name, set()).add(vref) |
|
68 |
for var in node.defined_vars.itervalues(): |
|
69 |
assert not (var.stinfo['references'] ^ vrefmap[var.name]) |
|
70 |
assert (var.stinfo['references']) |
|
71 |
||
72 |
class RQLRewriteTC(TestCase): |
|
73 |
"""a faire: |
|
74 |
||
75 |
* optimisation: detecter les relations utilisees dans les rqlexpressions qui |
|
76 |
sont presentes dans la requete de depart pour les reutiliser si possible |
|
1787 | 77 |
|
0 | 78 |
* "has_<ACTION>_permission" ? |
79 |
""" |
|
1787 | 80 |
|
0 | 81 |
def test_base_var(self): |
82 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
|
83 |
'P name "read", P require_group G') |
|
84 |
rqlst = parse('Card C') |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
85 |
rewrite(rqlst, {('C', 'X'): (card_constraint,)}, {}) |
0 | 86 |
self.failUnlessEqual(rqlst.as_string(), |
87 |
u"Any C WHERE C is Card, B eid %(D)s, " |
|
88 |
"EXISTS(C in_state A, B in_group E, F require_state A, " |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
89 |
"F name 'read', F require_group E, A is State, E is CWGroup, F is CWPermission)") |
1787 | 90 |
|
0 | 91 |
def test_multiple_var(self): |
92 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
|
93 |
'P name "read", P require_group G') |
|
94 |
affaire_constraints = ('X ref LIKE "PUBLIC%"', 'U in_group G, G name "public"') |
|
95 |
kwargs = {'u':2} |
|
96 |
rqlst = parse('Any S WHERE S documented_by C, C eid %(u)s') |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
97 |
rewrite(rqlst, {('C', 'X'): (card_constraint,), ('S', 'X'): affaire_constraints}, |
0 | 98 |
kwargs) |
99 |
self.assertTextEquals(rqlst.as_string(), |
|
100 |
"Any S WHERE S documented_by C, C eid %(u)s, B eid %(D)s, " |
|
101 |
"EXISTS(C in_state A, B in_group E, F require_state A, " |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
102 |
"F name 'read', F require_group E, A is State, E is CWGroup, F is CWPermission), " |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
103 |
"(EXISTS(S ref LIKE 'PUBLIC%')) OR (EXISTS(B in_group G, G name 'public', G is CWGroup)), " |
0 | 104 |
"S is Affaire") |
105 |
self.failUnless('D' in kwargs) |
|
1787 | 106 |
|
0 | 107 |
def test_or(self): |
108 |
constraint = '(X identity U) OR (X in_state ST, CL identity U, CL in_state ST, ST name "subscribed")' |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
109 |
rqlst = parse('Any S WHERE S owned_by C, C eid %(u)s, S is in (CWUser, CWGroup)') |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
110 |
rewrite(rqlst, {('C', 'X'): (constraint,)}, {'u':1}) |
0 | 111 |
self.failUnlessEqual(rqlst.as_string(), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
112 |
"Any S WHERE S owned_by C, C eid %(u)s, S is IN(CWUser, CWGroup), A eid %(B)s, " |
0 | 113 |
"EXISTS((C identity A) OR (C in_state D, E identity A, " |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
114 |
"E in_state D, D name 'subscribed'), D is State, E is CWUser)") |
0 | 115 |
|
116 |
def test_simplified_rqlst(self): |
|
117 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
|
118 |
'P name "read", P require_group G') |
|
119 |
rqlst = parse('Any 2') # this is the simplified rql st for Any X WHERE X eid 12 |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
120 |
rewrite(rqlst, {('2', 'X'): (card_constraint,)}, {}) |
0 | 121 |
self.failUnlessEqual(rqlst.as_string(), |
122 |
u"Any 2 WHERE B eid %(C)s, " |
|
123 |
"EXISTS(2 in_state A, B in_group D, E require_state A, " |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
124 |
"E name 'read', E require_group D, A is State, D is CWGroup, E is CWPermission)") |
0 | 125 |
|
4907
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
126 |
def test_optional_var_base(self): |
0 | 127 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
128 |
'P name "read", P require_group G') |
|
129 |
rqlst = parse('Any A,C WHERE A documented_by C?') |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
130 |
rewrite(rqlst, {('C', 'X'): (card_constraint,)}, {}) |
0 | 131 |
self.failUnlessEqual(rqlst.as_string(), |
132 |
"Any A,C WHERE A documented_by C?, A is Affaire " |
|
133 |
"WITH C BEING " |
|
4907
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
134 |
"(Any C WHERE EXISTS(C in_state B, D in_group F, G require_state B, G name 'read', " |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
135 |
"G require_group F), D eid %(A)s, C is Card)") |
0 | 136 |
rqlst = parse('Any A,C,T WHERE A documented_by C?, C title T') |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
137 |
rewrite(rqlst, {('C', 'X'): (card_constraint,)}, {}) |
0 | 138 |
self.failUnlessEqual(rqlst.as_string(), |
139 |
"Any A,C,T WHERE A documented_by C?, A is Affaire " |
|
140 |
"WITH C,T BEING " |
|
4907
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
141 |
"(Any C,T WHERE C title T, EXISTS(C in_state B, D in_group F, " |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
142 |
"G require_state B, G name 'read', G require_group F), " |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
143 |
"D eid %(A)s, C is Card)") |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
144 |
|
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
145 |
def test_optional_var_inlined(self): |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
146 |
c1 = ('X require_permission P') |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
147 |
c2 = ('X inlined_card O, O require_permission P') |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
148 |
rqlst = parse('Any C,A,R WHERE A? inlined_card C, A ref R') |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
149 |
rewrite(rqlst, {('C', 'X'): (c1,), |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
150 |
('A', 'X'): (c2,), |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
151 |
}, {}) |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
152 |
# XXX suboptimal |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
153 |
self.failUnlessEqual(rqlst.as_string(), |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
154 |
"Any C,A,R WITH A,R,C BEING " |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
155 |
"(Any A,R,C WHERE A ref R, A? inlined_card C, " |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
156 |
"(A is NULL) OR (EXISTS(A inlined_card B, B require_permission D, " |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
157 |
"B is Card, D is CWPermission)), " |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
158 |
"A is Affaire, C is Card, EXISTS(C require_permission E, E is CWPermission))") |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
159 |
|
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
160 |
# def test_optional_var_inlined_has_perm(self): |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
161 |
# c1 = ('X require_permission P') |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
162 |
# c2 = ('X inlined_card O, U has_read_permission O') |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
163 |
# rqlst = parse('Any C,A,R WHERE A? inlined_card C, A ref R') |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
164 |
# rewrite(rqlst, {('C', 'X'): (c1,), |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
165 |
# ('A', 'X'): (c2,), |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
166 |
# }, {}) |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
167 |
# self.failUnlessEqual(rqlst.as_string(), |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
168 |
# "") |
1787 | 169 |
|
4908
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
170 |
def test_optional_var_inlined_imbricated_error(self): |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
171 |
c1 = ('X require_permission P') |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
172 |
c2 = ('X inlined_card O, O require_permission P') |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
173 |
rqlst = parse('Any C,A,R,A2,R2 WHERE A? inlined_card C, A ref R,A2? inlined_card C, A2 ref R2') |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
174 |
self.assertRaises(BadSchemaDefinition, |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
175 |
rewrite, rqlst, {('C', 'X'): (c1,), |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
176 |
('A', 'X'): (c2,), |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
177 |
('A2', 'X'): (c2,), |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
178 |
}, {}) |
b3ad329cbe17
[rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4907
diff
changeset
|
179 |
|
3443
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
180 |
def test_relation_optimization_1_lhs(self): |
0 | 181 |
# since Card in_state State as monovalued cardinality, the in_state |
182 |
# relation used in the rql expression can be ignored and S replaced by |
|
183 |
# the variable from the incoming query |
|
3443
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
184 |
snippet = ('X in_state S, S name "hop"') |
0 | 185 |
rqlst = parse('Card C WHERE C in_state STATE') |
3443
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
186 |
rewrite(rqlst, {('C', 'X'): (snippet,)}, {}) |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
187 |
self.failUnlessEqual(rqlst.as_string(), |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
188 |
"Any C WHERE C in_state STATE, C is Card, " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
189 |
"EXISTS(STATE name 'hop'), STATE is State") |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
190 |
def test_relation_optimization_1_rhs(self): |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
191 |
snippet = ('TW subworkflow_exit X, TW name "hop"') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
192 |
rqlst = parse('WorkflowTransition C WHERE C subworkflow_exit EXIT') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
193 |
rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {}) |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
194 |
self.failUnlessEqual(rqlst.as_string(), |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
195 |
"Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
196 |
"EXISTS(C name 'hop'), EXIT is SubWorkflowExitPoint") |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
197 |
|
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
198 |
def test_relation_optimization_2_lhs(self): |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
199 |
# optional relation can be shared if also optional in the snippet |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
200 |
snippet = ('X in_state S?, S name "hop"') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
201 |
rqlst = parse('Card C WHERE C in_state STATE?') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
202 |
rewrite(rqlst, {('C', 'X'): (snippet,)}, {}) |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
203 |
self.failUnlessEqual(rqlst.as_string(), |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
204 |
"Any C WHERE C in_state STATE?, C is Card, " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
205 |
"EXISTS(STATE name 'hop'), STATE is State") |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
206 |
def test_relation_optimization_2_rhs(self): |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
207 |
snippet = ('TW? subworkflow_exit X, TW name "hop"') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
208 |
rqlst = parse('SubWorkflowExitPoint EXIT WHERE C? subworkflow_exit EXIT') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
209 |
rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {}) |
0 | 210 |
self.failUnlessEqual(rqlst.as_string(), |
3443
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
211 |
"Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
212 |
"EXISTS(C name 'hop'), C is WorkflowTransition") |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
213 |
|
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
214 |
def test_relation_optimization_3_lhs(self): |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
215 |
# optional relation in the snippet but not in the orig tree can be shared |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
216 |
snippet = ('X in_state S?, S name "hop"') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
217 |
rqlst = parse('Card C WHERE C in_state STATE') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
218 |
rewrite(rqlst, {('C', 'X'): (snippet,)}, {}) |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
219 |
self.failUnlessEqual(rqlst.as_string(), |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
220 |
"Any C WHERE C in_state STATE, C is Card, " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
221 |
"EXISTS(STATE name 'hop'), STATE is State") |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
222 |
def test_relation_optimization_3_rhs(self): |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
223 |
snippet = ('TW? subworkflow_exit X, TW name "hop"') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
224 |
rqlst = parse('WorkflowTransition C WHERE C subworkflow_exit EXIT') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
225 |
rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {}) |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
226 |
self.failUnlessEqual(rqlst.as_string(), |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
227 |
"Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
228 |
"EXISTS(C name 'hop'), EXIT is SubWorkflowExitPoint") |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
229 |
|
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
230 |
def test_relation_non_optimization_1_lhs(self): |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
231 |
# but optional relation in the orig tree but not in the snippet can't be shared |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
232 |
snippet = ('X in_state S, S name "hop"') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
233 |
rqlst = parse('Card C WHERE C in_state STATE?') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
234 |
rewrite(rqlst, {('C', 'X'): (snippet,)}, {}) |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
235 |
self.failUnlessEqual(rqlst.as_string(), |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
236 |
"Any C WHERE C in_state STATE?, C is Card, " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
237 |
"EXISTS(C in_state A, A name 'hop', A is State), STATE is State") |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
238 |
def test_relation_non_optimization_1_rhs(self): |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
239 |
snippet = ('TW subworkflow_exit X, TW name "hop"') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
240 |
rqlst = parse('SubWorkflowExitPoint EXIT WHERE C? subworkflow_exit EXIT') |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
241 |
rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {}) |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
242 |
self.failUnlessEqual(rqlst.as_string(), |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
243 |
"Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
244 |
"EXISTS(A subworkflow_exit EXIT, A name 'hop', A is WorkflowTransition), " |
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
245 |
"C is WorkflowTransition") |
0 | 246 |
|
247 |
def test_unsupported_constraint_1(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
248 |
# CWUser doesn't have require_permission |
0 | 249 |
trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
250 |
rqlst = parse('Any U,T WHERE U is CWUser, T wf_info_for U') |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
251 |
self.assertRaises(Unauthorized, rewrite, rqlst, {('T', 'X'): (trinfo_constraint,)}, {}) |
1787 | 252 |
|
0 | 253 |
def test_unsupported_constraint_2(self): |
254 |
trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
255 |
rqlst = parse('Any U,T WHERE U is CWUser, T wf_info_for U') |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
256 |
rewrite(rqlst, {('T', 'X'): (trinfo_constraint, 'X wf_info_for Y, Y in_group G, G name "managers"')}, {}) |
0 | 257 |
self.failUnlessEqual(rqlst.as_string(), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
258 |
u"Any U,T WHERE U is CWUser, T wf_info_for U, " |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
259 |
"EXISTS(U in_group B, B name 'managers', B is CWGroup), T is TrInfo") |
0 | 260 |
|
261 |
def test_unsupported_constraint_3(self): |
|
262 |
self.skip('raise unauthorized for now') |
|
263 |
trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"') |
|
264 |
rqlst = parse('Any T WHERE T wf_info_for X') |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
265 |
rewrite(rqlst, {('T', 'X'): (trinfo_constraint, 'X in_group G, G name "managers"')}, {}) |
0 | 266 |
self.failUnlessEqual(rqlst.as_string(), |
267 |
u'XXX dunno what should be generated') |
|
1787 | 268 |
|
0 | 269 |
def test_add_ambiguity_exists(self): |
270 |
constraint = ('X concerne Y') |
|
271 |
rqlst = parse('Affaire X') |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
272 |
rewrite(rqlst, {('X', 'X'): (constraint,)}, {}) |
0 | 273 |
self.failUnlessEqual(rqlst.as_string(), |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
274 |
u"Any X WHERE X is Affaire, ((EXISTS(X concerne A, A is Division)) OR (EXISTS(X concerne C, C is Societe))) OR (EXISTS(X concerne B, B is Note))") |
1787 | 275 |
|
0 | 276 |
def test_add_ambiguity_outerjoin(self): |
277 |
constraint = ('X concerne Y') |
|
278 |
rqlst = parse('Any X,C WHERE X? documented_by C') |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
279 |
rewrite(rqlst, {('X', 'X'): (constraint,)}, {}) |
0 | 280 |
# ambiguity are kept in the sub-query, no need to be resolved using OR |
281 |
self.failUnlessEqual(rqlst.as_string(), |
|
4907
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
282 |
u"Any X,C WHERE X? documented_by C, C is Card WITH X BEING (Any X WHERE EXISTS(X concerne A), X is Affaire)") |
1787 | 283 |
|
284 |
||
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
285 |
def test_rrqlexpr_nonexistant_subject_1(self): |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
286 |
constraint = RRQLExpression('S owned_by U') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
287 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
288 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
289 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
290 |
u"Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A)") |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
291 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
292 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'OU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
293 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
294 |
u"Any C WHERE C is Card") |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
295 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
296 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SOU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
297 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
298 |
u"Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A)") |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
299 |
|
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
300 |
def test_rrqlexpr_nonexistant_subject_2(self): |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
301 |
constraint = RRQLExpression('S owned_by U, O owned_by U, O is Card') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
302 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
303 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
304 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
305 |
'Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A)') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
306 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
307 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'OU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
308 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
309 |
'Any C WHERE C is Card, B eid %(D)s, EXISTS(A owned_by B, A is Card)') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
310 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
311 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SOU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
312 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
313 |
'Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A, D owned_by A, D is Card)') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
314 |
|
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
315 |
def test_rrqlexpr_nonexistant_subject_3(self): |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
316 |
constraint = RRQLExpression('U in_group G, G name "users"') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
317 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
318 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
319 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
320 |
u'Any C WHERE C is Card, A eid %(B)s, EXISTS(A in_group D, D name "users", D is CWGroup)') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
321 |
|
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
322 |
def test_rrqlexpr_nonexistant_subject_4(self): |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
323 |
constraint = RRQLExpression('U in_group G, G name "users", S owned_by U') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
324 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
325 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
326 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
327 |
u'Any C WHERE C is Card, A eid %(B)s, EXISTS(A in_group D, D name "users", C owned_by A, D is CWGroup)') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
328 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
329 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'OU') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
330 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
331 |
u'Any C WHERE C is Card, A eid %(B)s, EXISTS(A in_group D, D name "users", D is CWGroup)') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
332 |
|
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
333 |
def test_rrqlexpr_nonexistant_subject_5(self): |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
334 |
constraint = RRQLExpression('S owned_by Z, O owned_by Z, O is Card') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
335 |
rqlst = parse('Card C') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
336 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'S') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
337 |
self.failUnlessEqual(rqlst.as_string(), |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
338 |
u"Any C WHERE C is Card, EXISTS(C owned_by A, A is CWUser)") |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
339 |
|
1787 | 340 |
|
0 | 341 |
if __name__ == '__main__': |
342 |
unittest_main() |