author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 17 Mar 2010 09:21:58 +0100 | |
branch | stable |
changeset 4928 | cbca73dc9753 |
parent 4191 | 01638461d4b0 |
child 4766 | 162b2b127b15 |
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 |
|
11 |
class SQLGenAnnotatorTC(BaseQuerierTC): |
|
12 |
repo = repo |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
13 |
|
0 | 14 |
def get_max_eid(self): |
15 |
# no need for cleanup here |
|
16 |
return None |
|
17 |
def cleanup(self): |
|
18 |
# no need for cleanup here |
|
19 |
pass |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
20 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
21 |
def test_0_1(self): |
0 | 22 |
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') |
23 |
self.assertEquals(rqlst.defined_vars['SE']._q_invariant, False) |
|
24 |
self.assertEquals(rqlst.defined_vars['OE']._q_invariant, False) |
|
25 |
self.assertEquals(rqlst.defined_vars['R']._q_invariant, False) |
|
26 |
self.assertEquals(rqlst.defined_vars['SE'].stinfo['attrvar'], None) |
|
27 |
self.assertEquals(rqlst.defined_vars['OE'].stinfo['attrvar'], None) |
|
28 |
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
|
29 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
30 |
def test_0_2(self): |
0 | 31 |
rqlst = self._prepare('Any O WHERE NOT S ecrit_par O, S eid 1, S inline1 P, O inline2 P') |
32 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
33 |
self.assertEquals(rqlst.defined_vars['O'].stinfo['attrvar'], None) |
|
34 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
35 |
def test_0_4(self): |
0 | 36 |
rqlst = self._prepare('Any A,B,C WHERE A eid 12,A comment B, A ?wf_info_for C') |
37 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
|
38 |
self.assert_(rqlst.defined_vars['B'].stinfo['attrvar']) |
|
39 |
self.assertEquals(rqlst.defined_vars['C']._q_invariant, False) |
|
40 |
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
|
41 |
{'A': 'TrInfo', 'B': 'String', 'C': 'CWUser'}, |
0 | 42 |
{'A': 'TrInfo', 'B': 'String', 'C': 'Note'}]) |
43 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
44 |
def test_0_5(self): |
0 | 45 |
rqlst = self._prepare('Any P WHERE N ecrit_par P, N eid 0') |
46 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
47 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
48 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
49 |
def test_0_6(self): |
0 | 50 |
rqlst = self._prepare('Any P WHERE NOT N ecrit_par P, N eid 512') |
51 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
52 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
53 |
def test_0_7(self): |
0 | 54 |
rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE') |
55 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
56 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
57 |
self.assert_(rqlst.defined_vars['XE'].stinfo['attrvar']) |
|
58 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
59 |
def test_0_8(self): |
0 | 60 |
rqlst = self._prepare('Any P WHERE X eid 0, NOT X connait P') |
61 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
62 |
#self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
63 |
self.assertEquals(len(rqlst.solutions), 1, rqlst.solutions) |
|
64 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
65 |
def test_0_10(self): |
0 | 66 |
rqlst = self._prepare('Any X WHERE X concerne Y, Y is Note') |
67 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
68 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
69 |
||
70 |
def test_0_11(self): |
|
71 |
rqlst = self._prepare('Any X WHERE X todo_by Y, X is Affaire') |
|
72 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
73 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
74 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
75 |
def test_0_12(self): |
0 | 76 |
rqlst = self._prepare('Personne P WHERE P concerne A, A concerne S, S nom "Logilab"') |
77 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
78 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
|
79 |
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
|
80 |
|
0 | 81 |
def test_1_0(self): |
82 |
rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid 6') |
|
83 |
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
|
84 |
|
0 | 85 |
def test_1_1(self): |
86 |
rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid IN (6,7)') |
|
87 |
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
|
88 |
|
0 | 89 |
def test_2(self): |
90 |
rqlst = self._prepare('Any X WHERE X identity Y, Y eid 1') |
|
91 |
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
|
92 |
|
0 | 93 |
def test_7(self): |
94 |
rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE') |
|
95 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
96 |
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
|
97 |
|
3249
280080eadb22
fix rqlannotation bug w/ identity relation in subscope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
|
0 | 103 |
def test_optional_inlined(self): |
104 |
rqlst = self._prepare('Any X,S where X from_state S?') |
|
105 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
106 |
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
|
107 |
|
0 | 108 |
def test_optional_inlined_2(self): |
109 |
rqlst = self._prepare('Any N,A WHERE N? inline1 A') |
|
110 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
111 |
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
|
112 |
|
0 | 113 |
def test_optional_1(self): |
114 |
rqlst = self._prepare('Any X,S WHERE X travaille S?') |
|
115 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
116 |
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
|
117 |
|
0 | 118 |
def test_greater_eid(self): |
119 |
rqlst = self._prepare('Any X WHERE X eid > 5') |
|
120 |
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
|
121 |
|
0 | 122 |
def test_greater_eid_typed(self): |
123 |
rqlst = self._prepare('Any X WHERE X eid > 5, X is Note') |
|
124 |
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
|
125 |
|
0 | 126 |
def test_max_eid(self): |
127 |
rqlst = self._prepare('Any MAX(X)') |
|
128 |
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
|
129 |
|
0 | 130 |
def test_max_eid_typed(self): |
131 |
rqlst = self._prepare('Any MAX(X) WHERE X is Note') |
|
132 |
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
|
133 |
|
0 | 134 |
def test_all_entities(self): |
135 |
rqlst = self._prepare('Any X') |
|
136 |
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
|
137 |
|
0 | 138 |
def test_all_typed_entity(self): |
139 |
rqlst = self._prepare('Any X WHERE X is Note') |
|
140 |
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
|
141 |
|
0 | 142 |
def test_has_text_1(self): |
143 |
rqlst = self._prepare('Any X WHERE X has_text "toto tata"') |
|
144 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
145 |
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
|
146 |
|
0 | 147 |
def test_has_text_2(self): |
148 |
rqlst = self._prepare('Any X WHERE X is Personne, X has_text "coucou"') |
|
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_not_relation_1(self): |
153 |
# P can't be invariant since deambiguification caused by "NOT X require_permission P" |
|
154 |
# is not considered by generated sql (NOT EXISTS(...)) |
|
155 |
rqlst = self._prepare('Any P,G WHERE P require_group G, NOT X require_permission P') |
|
156 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
157 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, True) |
|
158 |
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
|
159 |
|
0 | 160 |
def test_not_relation_2(self): |
161 |
rqlst = self._prepare('TrInfo X WHERE X eid 2, NOT X from_state Y, Y is State') |
|
162 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
163 |
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
|
164 |
|
0 | 165 |
def test_not_relation_3(self): |
166 |
rqlst = self._prepare('Any X, Y WHERE X eid 1, Y eid in (2, 3)') |
|
167 |
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
|
168 |
|
0 | 169 |
def test_not_relation_4_1(self): |
170 |
rqlst = self._prepare('Note X WHERE NOT Y evaluee X') |
|
171 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
172 |
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
|
173 |
|
0 | 174 |
def test_not_relation_4_2(self): |
175 |
rqlst = self._prepare('Any 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_3(self): |
180 |
rqlst = self._prepare('Any Y WHERE NOT Y evaluee X') |
|
181 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
182 |
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
|
183 |
|
0 | 184 |
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
|
185 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y is CWUser') |
0 | 186 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
187 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
188 |
||
189 |
def test_not_relation_4_5(self): |
|
190 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y eid %s, X is Note' % self.ueid) |
|
191 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
192 |
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
|
193 |
|
0 | 194 |
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
|
195 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 196 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
197 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
198 |
||
199 |
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
|
200 |
rqlst = self._prepare('DISTINCT 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_6(self): |
|
205 |
rqlst = self._prepare('Personne P where NOT P concerne A') |
|
206 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
207 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
|
208 |
||
209 |
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
|
210 |
rqlst = self._prepare('Any K,V WHERE P is CWProperty, P pkey K, P value V, NOT P for_user U') |
0 | 211 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
212 |
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
|
213 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
214 |
def test_exists_1(self): |
0 | 215 |
rqlst = self._prepare('Any U WHERE U eid IN (1,2), EXISTS(X owned_by U)') |
216 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
217 |
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
|
218 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
219 |
def test_exists_2(self): |
0 | 220 |
rqlst = self._prepare('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)') |
221 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
222 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
223 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
224 |
def test_exists_3(self): |
0 | 225 |
rqlst = self._prepare('Any U WHERE EXISTS(X owned_by U, X bookmarked_by U)') |
226 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
227 |
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
|
228 |
|
0 | 229 |
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
|
230 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)') |
0 | 231 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
232 |
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
|
233 |
|
0 | 234 |
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
|
235 |
rqlst = self._prepare('DISTINCT 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, True) |
|
238 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
239 |
def test_not_exists_1(self): |
0 | 240 |
rqlst = self._prepare('Any U WHERE NOT EXISTS(X owned_by U, X bookmarked_by U)') |
241 |
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
|
242 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
0 | 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_2(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
967
diff
changeset
|
245 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 246 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
247 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
248 |
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
|
249 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 250 |
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
|
251 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
252 |
def test_or_1(self): |
0 | 253 |
rqlst = self._prepare('Any X WHERE X concerne B OR C concerne X, B eid 12, C eid 13') |
254 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
255 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
256 |
def test_or_2(self): |
0 | 257 |
rqlst = self._prepare('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13') |
258 |
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
|
259 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) |
0 | 260 |
self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'created_by') |
261 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
262 |
def test_or_3(self): |
0 | 263 |
rqlst = self._prepare('Any N WHERE A evaluee N or EXISTS(N todo_by U)') |
264 |
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
|
265 |
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
|
266 |
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
|
267 |
|
0 | 268 |
def test_or_exists_1(self): |
269 |
# query generated by security rewriting |
|
270 |
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
|
271 |
'(EXISTS(A owned_by D)) ' |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
272 |
'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
|
273 |
'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
|
274 |
'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
|
275 |
'OR (EXISTS(K concerne F?, F owned_by D, F is Division, A identity K, K is Affaire)))') |
0 | 276 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
277 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, False) |
|
278 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
279 |
def test_or_exists_2(self): |
0 | 280 |
rqlst = self._prepare('Any U WHERE EXISTS(U in_group G, G name "managers") OR EXISTS(X owned_by U, X bookmarked_by U)') |
281 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
282 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, False) |
|
283 |
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
|
284 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
285 |
def test_or_exists_3(self): |
0 | 286 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
287 |
'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
|
288 |
'(EXISTS(S owned_by D)) OR (EXISTS(S documented_by N, N title "published"))') |
0 | 289 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
290 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
|
291 |
'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
|
292 |
'(EXISTS(S owned_by D)) OR (EXISTS(S documented_by N, N title "published"))') |
0 | 293 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
294 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
295 |
def test_nonregr_ambiguity(self): |
967 | 296 |
rqlst = self._prepare('Note N WHERE N attachment F') |
297 |
# N may be an image as well, not invariant |
|
298 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
299 |
self.assertEquals(rqlst.defined_vars['F']._q_invariant, True) |
|
300 |
||
0 | 301 |
if __name__ == '__main__': |
302 |
from logilab.common.testlib import unittest_main |
|
303 |
unittest_main() |