author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 15 Apr 2010 14:07:25 +0200 | |
branch | stable |
changeset 5277 | 92b827b3830e |
parent 4766 | 162b2b127b15 |
child 5173 | 73760bbb66bd |
child 5421 | 8167de96c523 |
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 |
|
3249
280080eadb22
fix rqlannotation bug w/ identity relation in subscope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
|
0 | 108 |
def test_optional_inlined(self): |
109 |
rqlst = self._prepare('Any X,S where X from_state S?') |
|
110 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
111 |
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
|
112 |
|
0 | 113 |
def test_optional_inlined_2(self): |
114 |
rqlst = self._prepare('Any N,A WHERE N? inline1 A') |
|
115 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
116 |
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
|
117 |
|
0 | 118 |
def test_optional_1(self): |
119 |
rqlst = self._prepare('Any X,S WHERE X travaille S?') |
|
120 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
121 |
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
|
122 |
|
0 | 123 |
def test_greater_eid(self): |
124 |
rqlst = self._prepare('Any X WHERE X eid > 5') |
|
125 |
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
|
126 |
|
0 | 127 |
def test_greater_eid_typed(self): |
128 |
rqlst = self._prepare('Any X WHERE X eid > 5, X is Note') |
|
129 |
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
|
130 |
|
0 | 131 |
def test_max_eid(self): |
132 |
rqlst = self._prepare('Any MAX(X)') |
|
133 |
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
|
134 |
|
0 | 135 |
def test_max_eid_typed(self): |
136 |
rqlst = self._prepare('Any MAX(X) WHERE X is Note') |
|
137 |
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
|
138 |
|
0 | 139 |
def test_all_entities(self): |
140 |
rqlst = self._prepare('Any X') |
|
141 |
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
|
142 |
|
0 | 143 |
def test_all_typed_entity(self): |
144 |
rqlst = self._prepare('Any X WHERE X is Note') |
|
145 |
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
|
146 |
|
0 | 147 |
def test_has_text_1(self): |
148 |
rqlst = self._prepare('Any X WHERE X has_text "toto tata"') |
|
149 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
150 |
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
|
151 |
|
0 | 152 |
def test_has_text_2(self): |
153 |
rqlst = self._prepare('Any X WHERE X is Personne, X has_text "coucou"') |
|
154 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
155 |
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
|
156 |
|
0 | 157 |
def test_not_relation_1(self): |
158 |
# P can't be invariant since deambiguification caused by "NOT X require_permission P" |
|
159 |
# is not considered by generated sql (NOT EXISTS(...)) |
|
160 |
rqlst = self._prepare('Any P,G WHERE P require_group G, NOT X require_permission P') |
|
161 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
162 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, True) |
|
163 |
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
|
164 |
|
0 | 165 |
def test_not_relation_2(self): |
166 |
rqlst = self._prepare('TrInfo X WHERE X eid 2, NOT X from_state Y, Y is State') |
|
167 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
168 |
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
|
169 |
|
0 | 170 |
def test_not_relation_3(self): |
171 |
rqlst = self._prepare('Any X, Y WHERE X eid 1, Y eid in (2, 3)') |
|
172 |
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
|
173 |
|
0 | 174 |
def test_not_relation_4_1(self): |
175 |
rqlst = self._prepare('Note X WHERE NOT Y evaluee X') |
|
176 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
177 |
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
|
178 |
|
0 | 179 |
def test_not_relation_4_2(self): |
180 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X') |
|
181 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
182 |
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
|
183 |
|
0 | 184 |
def test_not_relation_4_3(self): |
185 |
rqlst = self._prepare('Any Y WHERE NOT Y evaluee X') |
|
186 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
187 |
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
|
188 |
|
0 | 189 |
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
|
190 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y is CWUser') |
0 | 191 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
192 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
193 |
||
194 |
def test_not_relation_4_5(self): |
|
195 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y eid %s, X is Note' % self.ueid) |
|
196 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
197 |
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
|
198 |
|
0 | 199 |
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
|
200 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 201 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
202 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
203 |
||
204 |
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
|
205 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 206 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
207 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
208 |
||
209 |
def test_not_relation_6(self): |
|
210 |
rqlst = self._prepare('Personne P where NOT P concerne A') |
|
211 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
212 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
|
213 |
||
214 |
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
|
215 |
rqlst = self._prepare('Any K,V WHERE P is CWProperty, P pkey K, P value V, NOT P for_user U') |
0 | 216 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
217 |
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
|
218 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
219 |
def test_exists_1(self): |
0 | 220 |
rqlst = self._prepare('Any U WHERE U eid IN (1,2), EXISTS(X owned_by U)') |
221 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
222 |
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
|
223 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
224 |
def test_exists_2(self): |
0 | 225 |
rqlst = self._prepare('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)') |
226 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
227 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
228 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
229 |
def test_exists_3(self): |
0 | 230 |
rqlst = self._prepare('Any U WHERE EXISTS(X owned_by U, X bookmarked_by U)') |
231 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
232 |
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
|
233 |
|
0 | 234 |
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
|
235 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)') |
0 | 236 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
237 |
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
|
238 |
|
0 | 239 |
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
|
240 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)') |
0 | 241 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
242 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
243 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
244 |
def test_not_exists_1(self): |
0 | 245 |
rqlst = self._prepare('Any U WHERE NOT EXISTS(X owned_by U, X bookmarked_by U)') |
246 |
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
|
247 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
0 | 248 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
249 |
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
|
250 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 251 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
252 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
253 |
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
|
254 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 255 |
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
|
256 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
257 |
def test_or_1(self): |
0 | 258 |
rqlst = self._prepare('Any X WHERE X concerne B OR C concerne X, B eid 12, C eid 13') |
259 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
260 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
261 |
def test_or_2(self): |
0 | 262 |
rqlst = self._prepare('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13') |
263 |
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
|
264 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) |
0 | 265 |
self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'created_by') |
266 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
267 |
def test_or_3(self): |
0 | 268 |
rqlst = self._prepare('Any N WHERE A evaluee N or EXISTS(N todo_by U)') |
269 |
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
|
270 |
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
|
271 |
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
|
272 |
|
0 | 273 |
def test_or_exists_1(self): |
274 |
# query generated by security rewriting |
|
275 |
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
|
276 |
'(EXISTS(A owned_by D)) ' |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
277 |
'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
|
278 |
'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
|
279 |
'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
|
280 |
'OR (EXISTS(K concerne F?, F owned_by D, F is Division, A identity K, K is Affaire)))') |
0 | 281 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
282 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, False) |
|
283 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
284 |
def test_or_exists_2(self): |
0 | 285 |
rqlst = self._prepare('Any U WHERE EXISTS(U in_group G, G name "managers") OR EXISTS(X owned_by U, X bookmarked_by U)') |
286 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
287 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, False) |
|
288 |
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
|
289 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
290 |
def test_or_exists_3(self): |
0 | 291 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
292 |
'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
|
293 |
'(EXISTS(S owned_by D)) OR (EXISTS(S documented_by N, N title "published"))') |
0 | 294 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
295 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
|
296 |
'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
|
297 |
'(EXISTS(S owned_by D)) OR (EXISTS(S documented_by N, N title "published"))') |
0 | 298 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
299 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
300 |
def test_nonregr_ambiguity(self): |
967 | 301 |
rqlst = self._prepare('Note N WHERE N attachment F') |
302 |
# N may be an image as well, not invariant |
|
303 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
304 |
self.assertEquals(rqlst.defined_vars['F']._q_invariant, True) |
|
305 |
||
0 | 306 |
if __name__ == '__main__': |
307 |
from logilab.common.testlib import unittest_main |
|
308 |
unittest_main() |