author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 09 Dec 2009 12:22:21 +0100 | |
changeset 4072 | ead446e70c28 |
parent 3877 | 7ca53fc72a0a |
child 4252 | 6c4f109c2b03 |
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() |
|
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 |
|
126 |
def test_optional_var(self): |
|
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 " |
|
134 |
"(Any C WHERE C in_state B, D in_group F, G require_state B, G name 'read', " |
|
135 |
"G require_group F, D eid %(A)s, C is Card)") |
|
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 " |
|
141 |
"(Any C,T WHERE C in_state B, D in_group F, G require_state B, G name 'read', " |
|
142 |
"G require_group F, C title T, D eid %(A)s, C is Card)") |
|
1787 | 143 |
|
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
|
144 |
def test_relation_optimization_1_lhs(self): |
0 | 145 |
# since Card in_state State as monovalued cardinality, the in_state |
146 |
# relation used in the rql expression can be ignored and S replaced by |
|
147 |
# 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
|
148 |
snippet = ('X in_state S, S name "hop"') |
0 | 149 |
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
|
150 |
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
|
151 |
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
|
152 |
"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
|
153 |
"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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
"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
|
160 |
"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
|
161 |
|
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 |
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
|
163 |
# 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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
"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
|
169 |
"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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {}) |
0 | 174 |
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
|
175 |
"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
|
176 |
"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
|
177 |
|
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 |
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
|
179 |
# 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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
"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
|
185 |
"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
|
186 |
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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
"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
|
192 |
"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
|
193 |
|
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 |
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
|
195 |
# 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
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
"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
|
201 |
"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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
"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
|
208 |
"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
|
209 |
"C is WorkflowTransition") |
0 | 210 |
|
211 |
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
|
212 |
# CWUser doesn't have require_permission |
0 | 213 |
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
|
214 |
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
|
215 |
self.assertRaises(Unauthorized, rewrite, rqlst, {('T', 'X'): (trinfo_constraint,)}, {}) |
1787 | 216 |
|
0 | 217 |
def test_unsupported_constraint_2(self): |
218 |
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
|
219 |
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
|
220 |
rewrite(rqlst, {('T', 'X'): (trinfo_constraint, 'X wf_info_for Y, Y in_group G, G name "managers"')}, {}) |
0 | 221 |
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
|
222 |
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
|
223 |
"EXISTS(U in_group B, B name 'managers', B is CWGroup), T is TrInfo") |
0 | 224 |
|
225 |
def test_unsupported_constraint_3(self): |
|
226 |
self.skip('raise unauthorized for now') |
|
227 |
trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"') |
|
228 |
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
|
229 |
rewrite(rqlst, {('T', 'X'): (trinfo_constraint, 'X in_group G, G name "managers"')}, {}) |
0 | 230 |
self.failUnlessEqual(rqlst.as_string(), |
231 |
u'XXX dunno what should be generated') |
|
1787 | 232 |
|
0 | 233 |
def test_add_ambiguity_exists(self): |
234 |
constraint = ('X concerne Y') |
|
235 |
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
|
236 |
rewrite(rqlst, {('X', 'X'): (constraint,)}, {}) |
0 | 237 |
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
|
238 |
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 | 239 |
|
0 | 240 |
def test_add_ambiguity_outerjoin(self): |
241 |
constraint = ('X concerne Y') |
|
242 |
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
|
243 |
rewrite(rqlst, {('X', 'X'): (constraint,)}, {}) |
0 | 244 |
# ambiguity are kept in the sub-query, no need to be resolved using OR |
245 |
self.failUnlessEqual(rqlst.as_string(), |
|
1787 | 246 |
u"Any X,C WHERE X? documented_by C, C is Card WITH X BEING (Any X WHERE X concerne A, X is Affaire)") |
247 |
||
248 |
||
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
|
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 |
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
'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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
'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
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
'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
|
278 |
|
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 |
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
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
|
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 |
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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
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
|
294 |
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
|
295 |
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
|
296 |
|
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 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
|
1787 | 304 |
|
0 | 305 |
if __name__ == '__main__': |
306 |
unittest_main() |