author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Fri, 31 Jul 2009 22:37:28 +0200 | |
changeset 2613 | 5e19c2bb370e |
parent 1977 | 606923dff11b |
child 2773 | b2530e3e0afb |
child 3249 | 280080eadb22 |
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 |
||
9 |
repo, cnx = init_test_database('sqlite') |
|
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 |
|
0 | 98 |
def test_optional_inlined(self): |
99 |
rqlst = self._prepare('Any X,S where X from_state S?') |
|
100 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
101 |
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
|
102 |
|
0 | 103 |
def test_optional_inlined_2(self): |
104 |
rqlst = self._prepare('Any N,A WHERE N? inline1 A') |
|
105 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
106 |
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
|
107 |
|
0 | 108 |
def test_optional_1(self): |
109 |
rqlst = self._prepare('Any X,S WHERE X travaille 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_greater_eid(self): |
114 |
rqlst = self._prepare('Any X WHERE X eid > 5') |
|
115 |
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
|
116 |
|
0 | 117 |
def test_greater_eid_typed(self): |
118 |
rqlst = self._prepare('Any X WHERE X eid > 5, X is Note') |
|
119 |
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
|
120 |
|
0 | 121 |
def test_max_eid(self): |
122 |
rqlst = self._prepare('Any MAX(X)') |
|
123 |
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
|
124 |
|
0 | 125 |
def test_max_eid_typed(self): |
126 |
rqlst = self._prepare('Any MAX(X) WHERE X is Note') |
|
127 |
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
|
128 |
|
0 | 129 |
def test_all_entities(self): |
130 |
rqlst = self._prepare('Any X') |
|
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_all_typed_entity(self): |
134 |
rqlst = self._prepare('Any X WHERE X is Note') |
|
135 |
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
|
136 |
|
0 | 137 |
def test_has_text_1(self): |
138 |
rqlst = self._prepare('Any X WHERE X has_text "toto tata"') |
|
139 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
140 |
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
|
141 |
|
0 | 142 |
def test_has_text_2(self): |
143 |
rqlst = self._prepare('Any X WHERE X is Personne, X has_text "coucou"') |
|
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_not_relation_1(self): |
148 |
# P can't be invariant since deambiguification caused by "NOT X require_permission P" |
|
149 |
# is not considered by generated sql (NOT EXISTS(...)) |
|
150 |
rqlst = self._prepare('Any P,G WHERE P require_group G, NOT X require_permission P') |
|
151 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
152 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, True) |
|
153 |
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
|
154 |
|
0 | 155 |
def test_not_relation_2(self): |
156 |
rqlst = self._prepare('TrInfo X WHERE X eid 2, NOT X from_state Y, Y is State') |
|
157 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
158 |
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
|
159 |
|
0 | 160 |
def test_not_relation_3(self): |
161 |
rqlst = self._prepare('Any X, Y WHERE X eid 1, Y eid in (2, 3)') |
|
162 |
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
|
163 |
|
0 | 164 |
def test_not_relation_4_1(self): |
165 |
rqlst = self._prepare('Note X WHERE NOT Y evaluee X') |
|
166 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
167 |
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
|
168 |
|
0 | 169 |
def test_not_relation_4_2(self): |
170 |
rqlst = self._prepare('Any 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_3(self): |
175 |
rqlst = self._prepare('Any Y WHERE NOT Y evaluee X') |
|
176 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
177 |
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
|
178 |
|
0 | 179 |
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
|
180 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y is CWUser') |
0 | 181 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
182 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
183 |
||
184 |
def test_not_relation_4_5(self): |
|
185 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y eid %s, X is Note' % self.ueid) |
|
186 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
187 |
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
|
188 |
|
0 | 189 |
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
|
190 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
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_5_2(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('DISTINCT 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_6(self): |
|
200 |
rqlst = self._prepare('Personne P where NOT P concerne A') |
|
201 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
202 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
|
203 |
||
204 |
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
|
205 |
rqlst = self._prepare('Any K,V WHERE P is CWProperty, P pkey K, P value V, NOT P for_user U') |
0 | 206 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
207 |
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
|
208 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
209 |
def test_exists_1(self): |
0 | 210 |
rqlst = self._prepare('Any U WHERE U eid IN (1,2), EXISTS(X owned_by U)') |
211 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
212 |
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
|
213 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
214 |
def test_exists_2(self): |
0 | 215 |
rqlst = self._prepare('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)') |
216 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
217 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
218 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
219 |
def test_exists_3(self): |
0 | 220 |
rqlst = self._prepare('Any U WHERE EXISTS(X owned_by U, X bookmarked_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 |
|
0 | 224 |
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
|
225 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)') |
0 | 226 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
227 |
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
|
228 |
|
0 | 229 |
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
|
230 |
rqlst = self._prepare('DISTINCT 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, True) |
|
233 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
234 |
def test_not_exists_1(self): |
0 | 235 |
rqlst = self._prepare('Any U WHERE NOT EXISTS(X owned_by U, X bookmarked_by U)') |
236 |
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
|
237 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
0 | 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_2(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('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 241 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
242 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
243 |
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
|
244 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 245 |
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
|
246 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
247 |
def test_or_1(self): |
0 | 248 |
rqlst = self._prepare('Any X WHERE X concerne B OR C concerne X, B eid 12, C eid 13') |
249 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
250 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
251 |
def test_or_2(self): |
0 | 252 |
rqlst = self._prepare('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13') |
253 |
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
|
254 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) |
0 | 255 |
self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'created_by') |
256 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
257 |
def test_or_3(self): |
0 | 258 |
rqlst = self._prepare('Any N WHERE A evaluee N or EXISTS(N todo_by U)') |
259 |
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
|
260 |
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
|
261 |
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
|
262 |
|
0 | 263 |
def test_or_exists_1(self): |
264 |
# query generated by security rewriting |
|
265 |
rqlst = self._prepare('DISTINCT Any A,S WHERE A is Affaire, S nom "chouette", S is IN(Division, Societe, SubDivision),' |
|
266 |
'(EXISTS(A owned_by %(D)s)) ' |
|
267 |
'OR ((((EXISTS(E concerne C?, C owned_by %(D)s, A identity E, C is Note, E is Affaire)) ' |
|
268 |
'OR (EXISTS(I concerne H?, H owned_by %(D)s, H is Societe, A identity I, I is Affaire))) ' |
|
269 |
'OR (EXISTS(J concerne G?, G owned_by %(D)s, G is SubDivision, A identity J, J is Affaire))) ' |
|
270 |
'OR (EXISTS(K concerne F?, F owned_by %(D)s, F is Division, A identity K, K is Affaire)))') |
|
271 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
|
272 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, False) |
|
273 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
274 |
def test_or_exists_2(self): |
0 | 275 |
rqlst = self._prepare('Any U WHERE EXISTS(U in_group G, G name "managers") OR EXISTS(X owned_by U, X bookmarked_by U)') |
276 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
277 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, False) |
|
278 |
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
|
279 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
280 |
def test_or_exists_3(self): |
0 | 281 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
282 |
'WHERE C is Societe, S concerne C, C nom CS, ' |
|
283 |
'(EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))') |
|
284 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
|
285 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
|
286 |
'WHERE S is Affaire, C is Societe, S concerne C, C nom CS, ' |
|
287 |
'(EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))') |
|
288 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
|
289 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
290 |
def test_nonregr_ambiguity(self): |
967 | 291 |
rqlst = self._prepare('Note N WHERE N attachment F') |
292 |
# N may be an image as well, not invariant |
|
293 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
294 |
self.assertEquals(rqlst.defined_vars['F']._q_invariant, True) |
|
295 |
||
0 | 296 |
if __name__ == '__main__': |
297 |
from logilab.common.testlib import unittest_main |
|
298 |
unittest_main() |