author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 16 Nov 2009 09:37:06 +0100 | |
branch | stable |
changeset 3853 | e8af6f586882 |
parent 3826 | 0c0c051863cb |
child 3877 | 7ca53fc72a0a |
child 4212 | ab6573088b4a |
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 |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
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 |
|
10 |
||
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() |
|
21 |
schema.add_relation_def(mock_object(subject='Card', name='in_state', object='State', cardinality='1*')) |
|
1787 | 22 |
|
0 | 23 |
rqlhelper = RQLHelper(schema, special_relations={'eid': 'uid', |
24 |
'has_text': 'fti'}) |
|
25 |
||
26 |
def setup_module(*args): |
|
27 |
repotest.do_monkey_patch() |
|
28 |
||
29 |
def teardown_module(*args): |
|
30 |
repotest.undo_monkey_patch() |
|
1787 | 31 |
|
0 | 32 |
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
|
33 |
return {1: 'CWUser', |
0 | 34 |
2: 'Card'}[eid] |
35 |
||
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
|
36 |
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
|
37 |
class FakeVReg: |
0 | 38 |
schema = schema |
39 |
@staticmethod |
|
40 |
def solutions(sqlcursor, mainrqlst, kwargs): |
|
41 |
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
|
42 |
class rqlhelper: |
0 | 43 |
@staticmethod |
44 |
def annotate(rqlst): |
|
45 |
rqlhelper.annotate(rqlst) |
|
46 |
@staticmethod |
|
47 |
def simplify(mainrqlst, needcopy=False): |
|
48 |
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
|
49 |
rewriter = RQLRewriter(mock_object(vreg=FakeVReg, user=(mock_object(eid=1)))) |
0 | 50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
or snippet |
0 | 55 |
for snippet in snippets] |
56 |
rqlhelper.compute_solutions(rqlst.children[0], {'eid': eid_func_map}, kwargs=kwargs) |
|
57 |
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
|
58 |
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
|
59 |
existingvars) |
0 | 60 |
test_vrefs(rqlst.children[0]) |
61 |
return rewriter.rewritten |
|
62 |
||
63 |
def test_vrefs(node): |
|
64 |
vrefmap = {} |
|
65 |
for vref in node.iget_nodes(nodes.VariableRef): |
|
66 |
vrefmap.setdefault(vref.name, set()).add(vref) |
|
67 |
for var in node.defined_vars.itervalues(): |
|
68 |
assert not (var.stinfo['references'] ^ vrefmap[var.name]) |
|
69 |
assert (var.stinfo['references']) |
|
70 |
||
71 |
class RQLRewriteTC(TestCase): |
|
72 |
"""a faire: |
|
73 |
||
74 |
* optimisation: detecter les relations utilisees dans les rqlexpressions qui |
|
75 |
sont presentes dans la requete de depart pour les reutiliser si possible |
|
1787 | 76 |
|
0 | 77 |
* "has_<ACTION>_permission" ? |
78 |
""" |
|
1787 | 79 |
|
0 | 80 |
def test_base_var(self): |
81 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
|
82 |
'P name "read", P require_group G') |
|
83 |
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
|
84 |
rewrite(rqlst, {('C', 'X'): (card_constraint,)}, {}) |
0 | 85 |
self.failUnlessEqual(rqlst.as_string(), |
86 |
u"Any C WHERE C is Card, B eid %(D)s, " |
|
87 |
"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
|
88 |
"F name 'read', F require_group E, A is State, E is CWGroup, F is CWPermission)") |
1787 | 89 |
|
0 | 90 |
def test_multiple_var(self): |
91 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
|
92 |
'P name "read", P require_group G') |
|
93 |
affaire_constraints = ('X ref LIKE "PUBLIC%"', 'U in_group G, G name "public"') |
|
94 |
kwargs = {'u':2} |
|
95 |
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
|
96 |
rewrite(rqlst, {('C', 'X'): (card_constraint,), ('S', 'X'): affaire_constraints}, |
0 | 97 |
kwargs) |
98 |
self.assertTextEquals(rqlst.as_string(), |
|
99 |
"Any S WHERE S documented_by C, C eid %(u)s, B eid %(D)s, " |
|
100 |
"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
|
101 |
"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
|
102 |
"(EXISTS(S ref LIKE 'PUBLIC%')) OR (EXISTS(B in_group G, G name 'public', G is CWGroup)), " |
0 | 103 |
"S is Affaire") |
104 |
self.failUnless('D' in kwargs) |
|
1787 | 105 |
|
0 | 106 |
def test_or(self): |
107 |
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
|
108 |
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
|
109 |
rewrite(rqlst, {('C', 'X'): (constraint,)}, {'u':1}) |
0 | 110 |
self.failUnlessEqual(rqlst.as_string(), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
111 |
"Any S WHERE S owned_by C, C eid %(u)s, S is IN(CWUser, CWGroup), A eid %(B)s, " |
0 | 112 |
"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
|
113 |
"E in_state D, D name 'subscribed'), D is State, E is CWUser)") |
0 | 114 |
|
115 |
def test_simplified_rqlst(self): |
|
116 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
|
117 |
'P name "read", P require_group G') |
|
118 |
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
|
119 |
rewrite(rqlst, {('2', 'X'): (card_constraint,)}, {}) |
0 | 120 |
self.failUnlessEqual(rqlst.as_string(), |
121 |
u"Any 2 WHERE B eid %(C)s, " |
|
122 |
"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
|
123 |
"E name 'read', E require_group D, A is State, D is CWGroup, E is CWPermission)") |
0 | 124 |
|
125 |
def test_optional_var(self): |
|
126 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
|
127 |
'P name "read", P require_group G') |
|
128 |
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
|
129 |
rewrite(rqlst, {('C', 'X'): (card_constraint,)}, {}) |
0 | 130 |
self.failUnlessEqual(rqlst.as_string(), |
131 |
"Any A,C WHERE A documented_by C?, A is Affaire " |
|
132 |
"WITH C BEING " |
|
133 |
"(Any C WHERE C in_state B, D in_group F, G require_state B, G name 'read', " |
|
134 |
"G require_group F, D eid %(A)s, C is Card)") |
|
135 |
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
|
136 |
rewrite(rqlst, {('C', 'X'): (card_constraint,)}, {}) |
0 | 137 |
self.failUnlessEqual(rqlst.as_string(), |
138 |
"Any A,C,T WHERE A documented_by C?, A is Affaire " |
|
139 |
"WITH C,T BEING " |
|
140 |
"(Any C,T WHERE C in_state B, D in_group F, G require_state B, G name 'read', " |
|
141 |
"G require_group F, C title T, D eid %(A)s, C is Card)") |
|
1787 | 142 |
|
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
|
143 |
def test_relation_optimization_1_lhs(self): |
0 | 144 |
# since Card in_state State as monovalued cardinality, the in_state |
145 |
# relation used in the rql expression can be ignored and S replaced by |
|
146 |
# 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
|
147 |
snippet = ('X in_state S, S name "hop"') |
0 | 148 |
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
|
149 |
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
|
150 |
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
|
151 |
"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
|
152 |
"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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
"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
|
159 |
"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
|
160 |
|
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
161 |
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
|
162 |
# 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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
"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
|
168 |
"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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {}) |
0 | 173 |
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
|
174 |
"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
|
175 |
"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
|
176 |
|
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
177 |
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
|
178 |
# 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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
"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
|
184 |
"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
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
"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
|
191 |
"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
|
192 |
|
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 |
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
|
194 |
# 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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
"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
|
200 |
"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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
"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
|
207 |
"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
|
208 |
"C is WorkflowTransition") |
0 | 209 |
|
210 |
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
|
211 |
# CWUser doesn't have require_permission |
0 | 212 |
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
|
213 |
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
|
214 |
self.assertRaises(Unauthorized, rewrite, rqlst, {('T', 'X'): (trinfo_constraint,)}, {}) |
1787 | 215 |
|
0 | 216 |
def test_unsupported_constraint_2(self): |
217 |
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
|
218 |
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
|
219 |
rewrite(rqlst, {('T', 'X'): (trinfo_constraint, 'X wf_info_for Y, Y in_group G, G name "managers"')}, {}) |
0 | 220 |
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
|
221 |
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
|
222 |
"EXISTS(U in_group B, B name 'managers', B is CWGroup), T is TrInfo") |
0 | 223 |
|
224 |
def test_unsupported_constraint_3(self): |
|
225 |
self.skip('raise unauthorized for now') |
|
226 |
trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"') |
|
227 |
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
|
228 |
rewrite(rqlst, {('T', 'X'): (trinfo_constraint, 'X in_group G, G name "managers"')}, {}) |
0 | 229 |
self.failUnlessEqual(rqlst.as_string(), |
230 |
u'XXX dunno what should be generated') |
|
1787 | 231 |
|
0 | 232 |
def test_add_ambiguity_exists(self): |
233 |
constraint = ('X concerne Y') |
|
234 |
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
|
235 |
rewrite(rqlst, {('X', 'X'): (constraint,)}, {}) |
0 | 236 |
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
|
237 |
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 | 238 |
|
0 | 239 |
def test_add_ambiguity_outerjoin(self): |
240 |
constraint = ('X concerne Y') |
|
241 |
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
|
242 |
rewrite(rqlst, {('X', 'X'): (constraint,)}, {}) |
0 | 243 |
# ambiguity are kept in the sub-query, no need to be resolved using OR |
244 |
self.failUnlessEqual(rqlst.as_string(), |
|
1787 | 245 |
u"Any X,C WHERE X? documented_by C, C is Card WITH X BEING (Any X WHERE X concerne A, X is Affaire)") |
246 |
||
247 |
||
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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
|
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
'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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
'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
|
273 |
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
|
274 |
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
|
275 |
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
|
276 |
'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
|
277 |
|
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
|
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_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
|
286 |
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
|
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(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
|
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, 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
|
295 |
|
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 |
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
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
|
1787 | 303 |
|
0 | 304 |
if __name__ == '__main__': |
305 |
unittest_main() |