author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 20 Apr 2010 15:55:50 +0200 | |
changeset 5352 | be44c58d3ed9 |
parent 5173 | 73760bbb66bd |
child 5423 | e15abfdcce38 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
2 |
"""unit tests for modules cubicweb.server.rqlannotation |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 4 |
""" |
5 |
||
6 |
from cubicweb.devtools import init_test_database |
|
7 |
from cubicweb.devtools.repotest import BaseQuerierTC |
|
8 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
9 |
repo, cnx = init_test_database() |
0 | 10 |
|
4766
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
11 |
def teardown_module(*args): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
12 |
global repo, cnx |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
13 |
del repo, cnx |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
14 |
|
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
15 |
|
0 | 16 |
class SQLGenAnnotatorTC(BaseQuerierTC): |
17 |
repo = repo |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
18 |
|
0 | 19 |
def get_max_eid(self): |
20 |
# no need for cleanup here |
|
21 |
return None |
|
22 |
def cleanup(self): |
|
23 |
# no need for cleanup here |
|
24 |
pass |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
25 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
26 |
def test_0_1(self): |
0 | 27 |
rqlst = self._prepare('Any SEN,RN,OEN WHERE X from_entity SE, SE eid 44, X relation_type R, R eid 139, X to_entity OE, OE eid 42, R name RN, SE name SEN, OE name OEN') |
28 |
self.assertEquals(rqlst.defined_vars['SE']._q_invariant, False) |
|
29 |
self.assertEquals(rqlst.defined_vars['OE']._q_invariant, False) |
|
30 |
self.assertEquals(rqlst.defined_vars['R']._q_invariant, False) |
|
31 |
self.assertEquals(rqlst.defined_vars['SE'].stinfo['attrvar'], None) |
|
32 |
self.assertEquals(rqlst.defined_vars['OE'].stinfo['attrvar'], None) |
|
33 |
self.assertEquals(rqlst.defined_vars['R'].stinfo['attrvar'], None) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
34 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
35 |
def test_0_2(self): |
0 | 36 |
rqlst = self._prepare('Any O WHERE NOT S ecrit_par O, S eid 1, S inline1 P, O inline2 P') |
37 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
38 |
self.assertEquals(rqlst.defined_vars['O'].stinfo['attrvar'], None) |
|
39 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
40 |
def test_0_4(self): |
0 | 41 |
rqlst = self._prepare('Any A,B,C WHERE A eid 12,A comment B, A ?wf_info_for C') |
42 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
|
43 |
self.assert_(rqlst.defined_vars['B'].stinfo['attrvar']) |
|
44 |
self.assertEquals(rqlst.defined_vars['C']._q_invariant, False) |
|
45 |
self.assertEquals(rqlst.solutions, [{'A': 'TrInfo', 'B': 'String', 'C': 'Affaire'}, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
46 |
{'A': 'TrInfo', 'B': 'String', 'C': 'CWUser'}, |
0 | 47 |
{'A': 'TrInfo', 'B': 'String', 'C': 'Note'}]) |
48 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
49 |
def test_0_5(self): |
0 | 50 |
rqlst = self._prepare('Any P WHERE N ecrit_par P, N eid 0') |
51 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
52 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
53 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
54 |
def test_0_6(self): |
0 | 55 |
rqlst = self._prepare('Any P WHERE NOT N ecrit_par P, N eid 512') |
56 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
57 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
58 |
def test_0_7(self): |
0 | 59 |
rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE') |
60 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
61 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
62 |
self.assert_(rqlst.defined_vars['XE'].stinfo['attrvar']) |
|
63 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
64 |
def test_0_8(self): |
0 | 65 |
rqlst = self._prepare('Any P WHERE X eid 0, NOT X connait P') |
66 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
67 |
#self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
68 |
self.assertEquals(len(rqlst.solutions), 1, rqlst.solutions) |
|
69 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
70 |
def test_0_10(self): |
0 | 71 |
rqlst = self._prepare('Any X WHERE X concerne Y, Y is Note') |
72 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
73 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
74 |
||
75 |
def test_0_11(self): |
|
76 |
rqlst = self._prepare('Any X WHERE X todo_by Y, X is Affaire') |
|
77 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
78 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
79 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
80 |
def test_0_12(self): |
0 | 81 |
rqlst = self._prepare('Personne P WHERE P concerne A, A concerne S, S nom "Logilab"') |
82 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
83 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
|
84 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
85 |
|
0 | 86 |
def test_1_0(self): |
87 |
rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid 6') |
|
88 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
89 |
|
0 | 90 |
def test_1_1(self): |
91 |
rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid IN (6,7)') |
|
92 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
93 |
|
0 | 94 |
def test_2(self): |
95 |
rqlst = self._prepare('Any X WHERE X identity Y, Y eid 1') |
|
96 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
97 |
|
0 | 98 |
def test_7(self): |
99 |
rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE') |
|
100 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
101 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
102 |
|
5173
73760bbb66bd
[rql annotation] add test and fix for bug introduced by 5004:4cc020ee70e2. While it sounded good, it wasn't because stinfo['relations'] didn't include anymore stinfo['typerels']
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
103 |
def test_8(self): |
73760bbb66bd
[rql annotation] add test and fix for bug introduced by 5004:4cc020ee70e2. While it sounded good, it wasn't because stinfo['relations'] didn't include anymore stinfo['typerels']
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
104 |
# DISTINCT Any P WHERE P require_group %(g)s, NOT %(u)s has_group_permission P, P is CWPermission |
73760bbb66bd
[rql annotation] add test and fix for bug introduced by 5004:4cc020ee70e2. While it sounded good, it wasn't because stinfo['relations'] didn't include anymore stinfo['typerels']
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
105 |
rqlst = self._prepare('DISTINCT Any X WHERE A concerne X, NOT N migrated_from X, ' |
73760bbb66bd
[rql annotation] add test and fix for bug introduced by 5004:4cc020ee70e2. While it sounded good, it wasn't because stinfo['relations'] didn't include anymore stinfo['typerels']
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
106 |
'X is Note, N eid 1') |
73760bbb66bd
[rql annotation] add test and fix for bug introduced by 5004:4cc020ee70e2. While it sounded good, it wasn't because stinfo['relations'] didn't include anymore stinfo['typerels']
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
107 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
73760bbb66bd
[rql annotation] add test and fix for bug introduced by 5004:4cc020ee70e2. While it sounded good, it wasn't because stinfo['relations'] didn't include anymore stinfo['typerels']
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
108 |
|
3249
280080eadb22
fix rqlannotation bug w/ identity relation in subscope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
109 |
def test_diff_scope_identity_deamb(self): |
280080eadb22
fix rqlannotation bug w/ identity relation in subscope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
110 |
rqlst = self._prepare('Any X WHERE X concerne Y, Y is Note, EXISTS(Y identity Z, Z migrated_from N)') |
280080eadb22
fix rqlannotation bug w/ identity relation in subscope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
111 |
self.assertEquals(rqlst.defined_vars['Z']._q_invariant, True) |
280080eadb22
fix rqlannotation bug w/ identity relation in subscope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
112 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
280080eadb22
fix rqlannotation bug w/ identity relation in subscope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
113 |
|
0 | 114 |
def test_optional_inlined(self): |
115 |
rqlst = self._prepare('Any X,S where X from_state S?') |
|
116 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
117 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
118 |
|
0 | 119 |
def test_optional_inlined_2(self): |
120 |
rqlst = self._prepare('Any N,A WHERE N? inline1 A') |
|
121 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
122 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
123 |
|
0 | 124 |
def test_optional_1(self): |
125 |
rqlst = self._prepare('Any X,S WHERE X travaille S?') |
|
126 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
127 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
128 |
|
0 | 129 |
def test_greater_eid(self): |
130 |
rqlst = self._prepare('Any X WHERE X eid > 5') |
|
131 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
132 |
|
0 | 133 |
def test_greater_eid_typed(self): |
134 |
rqlst = self._prepare('Any X WHERE X eid > 5, X is Note') |
|
135 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
136 |
|
0 | 137 |
def test_max_eid(self): |
138 |
rqlst = self._prepare('Any MAX(X)') |
|
139 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
140 |
|
0 | 141 |
def test_max_eid_typed(self): |
142 |
rqlst = self._prepare('Any MAX(X) WHERE X is Note') |
|
143 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
144 |
|
0 | 145 |
def test_all_entities(self): |
146 |
rqlst = self._prepare('Any X') |
|
147 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
148 |
|
0 | 149 |
def test_all_typed_entity(self): |
150 |
rqlst = self._prepare('Any X WHERE X is Note') |
|
151 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
152 |
|
0 | 153 |
def test_has_text_1(self): |
154 |
rqlst = self._prepare('Any X WHERE X has_text "toto tata"') |
|
155 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
156 |
self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'has_text') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
157 |
|
0 | 158 |
def test_has_text_2(self): |
159 |
rqlst = self._prepare('Any X WHERE X is Personne, X has_text "coucou"') |
|
160 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
161 |
self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'has_text') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
162 |
|
0 | 163 |
def test_not_relation_1(self): |
164 |
# P can't be invariant since deambiguification caused by "NOT X require_permission P" |
|
165 |
# is not considered by generated sql (NOT EXISTS(...)) |
|
166 |
rqlst = self._prepare('Any P,G WHERE P require_group G, NOT X require_permission P') |
|
167 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
168 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, True) |
|
169 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
170 |
|
0 | 171 |
def test_not_relation_2(self): |
172 |
rqlst = self._prepare('TrInfo X WHERE X eid 2, NOT X from_state Y, Y is State') |
|
173 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
174 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
175 |
|
0 | 176 |
def test_not_relation_3(self): |
177 |
rqlst = self._prepare('Any X, Y WHERE X eid 1, Y eid in (2, 3)') |
|
178 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
179 |
|
0 | 180 |
def test_not_relation_4_1(self): |
181 |
rqlst = self._prepare('Note X WHERE NOT Y evaluee X') |
|
182 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
183 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
184 |
|
0 | 185 |
def test_not_relation_4_2(self): |
186 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X') |
|
187 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
188 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
189 |
|
0 | 190 |
def test_not_relation_4_3(self): |
191 |
rqlst = self._prepare('Any Y WHERE NOT Y evaluee X') |
|
192 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
193 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
194 |
|
0 | 195 |
def test_not_relation_4_4(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
196 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y is CWUser') |
0 | 197 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
198 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
199 |
||
200 |
def test_not_relation_4_5(self): |
|
201 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y eid %s, X is Note' % self.ueid) |
|
202 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
203 |
self.assertEquals(rqlst.solutions, [{'X': 'Note'}]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
204 |
|
0 | 205 |
def test_not_relation_5_1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
206 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 207 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
208 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
209 |
||
210 |
def test_not_relation_5_2(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
211 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 212 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
213 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
214 |
||
215 |
def test_not_relation_6(self): |
|
216 |
rqlst = self._prepare('Personne P where NOT P concerne A') |
|
217 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
218 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
|
219 |
||
220 |
def test_not_relation_7(self): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
221 |
rqlst = self._prepare('Any K,V WHERE P is CWProperty, P pkey K, P value V, NOT P for_user U') |
0 | 222 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
223 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
224 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
225 |
def test_exists_1(self): |
0 | 226 |
rqlst = self._prepare('Any U WHERE U eid IN (1,2), EXISTS(X owned_by U)') |
227 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
228 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
229 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
230 |
def test_exists_2(self): |
0 | 231 |
rqlst = self._prepare('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)') |
232 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
233 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
234 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
235 |
def test_exists_3(self): |
0 | 236 |
rqlst = self._prepare('Any U WHERE EXISTS(X owned_by U, X bookmarked_by U)') |
237 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
238 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
239 |
|
0 | 240 |
def test_exists_4(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
241 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)') |
0 | 242 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
243 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
244 |
|
0 | 245 |
def test_exists_5(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
246 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)') |
0 | 247 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
248 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
249 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
250 |
def test_not_exists_1(self): |
0 | 251 |
rqlst = self._prepare('Any U WHERE NOT EXISTS(X owned_by U, X bookmarked_by U)') |
252 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
253 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
0 | 254 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
255 |
def test_not_exists_2(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
256 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 257 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
258 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
259 |
def test_not_exists_distinct_1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
260 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 261 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
262 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
263 |
def test_or_1(self): |
0 | 264 |
rqlst = self._prepare('Any X WHERE X concerne B OR C concerne X, B eid 12, C eid 13') |
265 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
266 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
267 |
def test_or_2(self): |
0 | 268 |
rqlst = self._prepare('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13') |
269 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
270 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) |
0 | 271 |
self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'created_by') |
272 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
273 |
def test_or_3(self): |
0 | 274 |
rqlst = self._prepare('Any N WHERE A evaluee N or EXISTS(N todo_by U)') |
275 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
276 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
277 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
278 |
|
0 | 279 |
def test_or_exists_1(self): |
280 |
# query generated by security rewriting |
|
281 |
rqlst = self._prepare('DISTINCT Any A,S WHERE A is Affaire, S nom "chouette", S is IN(Division, Societe, SubDivision),' |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
282 |
'(EXISTS(A owned_by D)) ' |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
283 |
'OR ((((EXISTS(E concerne C?, C owned_by D, A identity E, C is Note, E is Affaire)) ' |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
284 |
'OR (EXISTS(I concerne H?, H owned_by D, H is Societe, A identity I, I is Affaire))) ' |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
285 |
'OR (EXISTS(J concerne G?, G owned_by D, G is SubDivision, A identity J, J is Affaire))) ' |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
286 |
'OR (EXISTS(K concerne F?, F owned_by D, F is Division, A identity K, K is Affaire)))') |
0 | 287 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
288 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, False) |
|
289 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
290 |
def test_or_exists_2(self): |
0 | 291 |
rqlst = self._prepare('Any U WHERE EXISTS(U in_group G, G name "managers") OR EXISTS(X owned_by U, X bookmarked_by U)') |
292 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
293 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, False) |
|
294 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
295 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
296 |
def test_or_exists_3(self): |
0 | 297 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
298 |
'WHERE C is Societe, S concerne C, C nom CS, ' |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
299 |
'(EXISTS(S owned_by D)) OR (EXISTS(S documented_by N, N title "published"))') |
0 | 300 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
301 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
|
302 |
'WHERE S is Affaire, C is Societe, S concerne C, C nom CS, ' |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
303 |
'(EXISTS(S owned_by D)) OR (EXISTS(S documented_by N, N title "published"))') |
0 | 304 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
305 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
306 |
def test_nonregr_ambiguity(self): |
967 | 307 |
rqlst = self._prepare('Note N WHERE N attachment F') |
308 |
# N may be an image as well, not invariant |
|
309 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
310 |
self.assertEquals(rqlst.defined_vars['F']._q_invariant, True) |
|
311 |
||
0 | 312 |
if __name__ == '__main__': |
313 |
from logilab.common.testlib import unittest_main |
|
314 |
unittest_main() |