author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 28 Apr 2010 12:15:52 +0200 | |
branch | oldstable |
changeset 5424 | 8ecbcbff9777 |
parent 5421 | 8167de96c523 |
child 5426 | 0d4853a6e5ee |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
"""unit tests for modules cubicweb.server.rqlannotation |
20 |
""" |
|
21 |
||
22 |
from cubicweb.devtools import init_test_database |
|
23 |
from cubicweb.devtools.repotest import BaseQuerierTC |
|
24 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
25 |
repo, cnx = init_test_database() |
0 | 26 |
|
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
|
27 |
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
|
28 |
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
|
29 |
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
|
30 |
|
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
|
31 |
|
0 | 32 |
class SQLGenAnnotatorTC(BaseQuerierTC): |
33 |
repo = repo |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
34 |
|
0 | 35 |
def get_max_eid(self): |
36 |
# no need for cleanup here |
|
37 |
return None |
|
38 |
def cleanup(self): |
|
39 |
# no need for cleanup here |
|
40 |
pass |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
41 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
42 |
def test_0_1(self): |
0 | 43 |
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') |
44 |
self.assertEquals(rqlst.defined_vars['SE']._q_invariant, False) |
|
45 |
self.assertEquals(rqlst.defined_vars['OE']._q_invariant, False) |
|
46 |
self.assertEquals(rqlst.defined_vars['R']._q_invariant, False) |
|
47 |
self.assertEquals(rqlst.defined_vars['SE'].stinfo['attrvar'], None) |
|
48 |
self.assertEquals(rqlst.defined_vars['OE'].stinfo['attrvar'], None) |
|
49 |
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
|
50 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
51 |
def test_0_2(self): |
0 | 52 |
rqlst = self._prepare('Any O WHERE NOT S ecrit_par O, S eid 1, S inline1 P, O inline2 P') |
53 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
54 |
self.assertEquals(rqlst.defined_vars['O'].stinfo['attrvar'], None) |
|
55 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
56 |
def test_0_4(self): |
0 | 57 |
rqlst = self._prepare('Any A,B,C WHERE A eid 12,A comment B, A ?wf_info_for C') |
58 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
|
59 |
self.assert_(rqlst.defined_vars['B'].stinfo['attrvar']) |
|
60 |
self.assertEquals(rqlst.defined_vars['C']._q_invariant, False) |
|
61 |
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
|
62 |
{'A': 'TrInfo', 'B': 'String', 'C': 'CWUser'}, |
0 | 63 |
{'A': 'TrInfo', 'B': 'String', 'C': 'Note'}]) |
64 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
65 |
def test_0_5(self): |
0 | 66 |
rqlst = self._prepare('Any P WHERE N ecrit_par P, N eid 0') |
67 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
68 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
69 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
70 |
def test_0_6(self): |
0 | 71 |
rqlst = self._prepare('Any P WHERE NOT N ecrit_par P, N eid 512') |
72 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
73 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
74 |
def test_0_7(self): |
0 | 75 |
rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE') |
76 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
77 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
78 |
self.assert_(rqlst.defined_vars['XE'].stinfo['attrvar']) |
|
79 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
80 |
def test_0_8(self): |
0 | 81 |
rqlst = self._prepare('Any P WHERE X eid 0, NOT X connait P') |
82 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
83 |
#self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
84 |
self.assertEquals(len(rqlst.solutions), 1, rqlst.solutions) |
|
85 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
86 |
def test_0_10(self): |
0 | 87 |
rqlst = self._prepare('Any X WHERE X concerne Y, Y is Note') |
88 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
89 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
90 |
||
91 |
def test_0_11(self): |
|
92 |
rqlst = self._prepare('Any X WHERE X todo_by Y, X is Affaire') |
|
93 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
94 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
95 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
96 |
def test_0_12(self): |
0 | 97 |
rqlst = self._prepare('Personne P WHERE P concerne A, A concerne S, S nom "Logilab"') |
98 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, True) |
|
99 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
|
100 |
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
|
101 |
|
0 | 102 |
def test_1_0(self): |
103 |
rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid 6') |
|
104 |
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
|
105 |
|
0 | 106 |
def test_1_1(self): |
107 |
rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid IN (6,7)') |
|
108 |
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
|
109 |
|
0 | 110 |
def test_2(self): |
111 |
rqlst = self._prepare('Any X WHERE X identity Y, Y eid 1') |
|
112 |
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
|
113 |
|
0 | 114 |
def test_7(self): |
115 |
rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE') |
|
116 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
117 |
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
|
118 |
|
3249
280080eadb22
fix rqlannotation bug w/ identity relation in subscope
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
|
0 | 124 |
def test_optional_inlined(self): |
125 |
rqlst = self._prepare('Any X,S where X from_state 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_optional_inlined_2(self): |
130 |
rqlst = self._prepare('Any N,A WHERE N? inline1 A') |
|
131 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
132 |
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
|
133 |
|
0 | 134 |
def test_optional_1(self): |
135 |
rqlst = self._prepare('Any X,S WHERE X travaille S?') |
|
136 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
137 |
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
|
138 |
|
0 | 139 |
def test_greater_eid(self): |
140 |
rqlst = self._prepare('Any X WHERE X eid > 5') |
|
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_greater_eid_typed(self): |
144 |
rqlst = self._prepare('Any X WHERE X eid > 5, X is Note') |
|
145 |
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
|
146 |
|
0 | 147 |
def test_max_eid(self): |
148 |
rqlst = self._prepare('Any MAX(X)') |
|
149 |
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
|
150 |
|
0 | 151 |
def test_max_eid_typed(self): |
152 |
rqlst = self._prepare('Any MAX(X) WHERE X is Note') |
|
153 |
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
|
154 |
|
0 | 155 |
def test_all_entities(self): |
156 |
rqlst = self._prepare('Any X') |
|
157 |
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
|
158 |
|
0 | 159 |
def test_all_typed_entity(self): |
160 |
rqlst = self._prepare('Any X WHERE X is Note') |
|
161 |
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
|
162 |
|
0 | 163 |
def test_has_text_1(self): |
164 |
rqlst = self._prepare('Any X WHERE X has_text "toto tata"') |
|
165 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
166 |
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
|
167 |
|
0 | 168 |
def test_has_text_2(self): |
169 |
rqlst = self._prepare('Any X WHERE X is Personne, X has_text "coucou"') |
|
170 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
171 |
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
|
172 |
|
0 | 173 |
def test_not_relation_1(self): |
174 |
# P can't be invariant since deambiguification caused by "NOT X require_permission P" |
|
175 |
# is not considered by generated sql (NOT EXISTS(...)) |
|
176 |
rqlst = self._prepare('Any P,G WHERE P require_group G, NOT X require_permission P') |
|
177 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
178 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, True) |
|
179 |
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
|
180 |
|
0 | 181 |
def test_not_relation_2(self): |
182 |
rqlst = self._prepare('TrInfo X WHERE X eid 2, NOT X from_state Y, Y is State') |
|
183 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
184 |
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
|
185 |
|
0 | 186 |
def test_not_relation_3(self): |
187 |
rqlst = self._prepare('Any X, Y WHERE X eid 1, Y eid in (2, 3)') |
|
188 |
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
|
189 |
|
0 | 190 |
def test_not_relation_4_1(self): |
191 |
rqlst = self._prepare('Note X WHERE NOT Y evaluee X') |
|
192 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
193 |
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
|
194 |
|
0 | 195 |
def test_not_relation_4_2(self): |
196 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X') |
|
197 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
198 |
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
|
199 |
|
0 | 200 |
def test_not_relation_4_3(self): |
201 |
rqlst = self._prepare('Any Y WHERE NOT Y evaluee X') |
|
202 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
203 |
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
|
204 |
|
0 | 205 |
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
|
206 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y is CWUser') |
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_4_5(self): |
|
211 |
rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y eid %s, X is Note' % self.ueid) |
|
212 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
213 |
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
|
214 |
|
0 | 215 |
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
|
216 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 217 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
218 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
219 |
||
220 |
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
|
221 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 222 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
223 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
|
224 |
||
225 |
def test_not_relation_6(self): |
|
226 |
rqlst = self._prepare('Personne P where NOT P concerne A') |
|
227 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
|
228 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) |
|
229 |
||
230 |
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
|
231 |
rqlst = self._prepare('Any K,V WHERE P is CWProperty, P pkey K, P value V, NOT P for_user U') |
0 | 232 |
self.assertEquals(rqlst.defined_vars['P']._q_invariant, False) |
233 |
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
|
234 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
235 |
def test_exists_1(self): |
0 | 236 |
rqlst = self._prepare('Any U WHERE U eid IN (1,2), EXISTS(X owned_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 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
240 |
def test_exists_2(self): |
0 | 241 |
rqlst = self._prepare('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)') |
242 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
243 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
|
244 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
245 |
def test_exists_3(self): |
0 | 246 |
rqlst = self._prepare('Any U WHERE EXISTS(X owned_by U, X bookmarked_by U)') |
247 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
248 |
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
|
249 |
|
0 | 250 |
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
|
251 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)') |
0 | 252 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
253 |
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
|
254 |
|
0 | 255 |
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
|
256 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)') |
0 | 257 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
258 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True) |
|
259 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
260 |
def test_not_exists_1(self): |
0 | 261 |
rqlst = self._prepare('Any U WHERE NOT EXISTS(X owned_by U, X bookmarked_by U)') |
262 |
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
|
263 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, True) |
0 | 264 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
265 |
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
|
266 |
rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 267 |
self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False) |
268 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
269 |
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
|
270 |
rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)') |
0 | 271 |
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
|
272 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
273 |
def test_or_1(self): |
0 | 274 |
rqlst = self._prepare('Any X WHERE X concerne B OR C concerne X, B eid 12, C eid 13') |
275 |
self.assertEquals(rqlst.defined_vars['X']._q_invariant, False) |
|
276 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
277 |
def test_or_2(self): |
0 | 278 |
rqlst = self._prepare('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13') |
279 |
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
|
280 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) |
0 | 281 |
self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'created_by') |
282 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
283 |
def test_or_3(self): |
0 | 284 |
rqlst = self._prepare('Any N WHERE A evaluee N or EXISTS(N todo_by U)') |
285 |
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
|
286 |
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
|
287 |
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
|
288 |
|
0 | 289 |
def test_or_exists_1(self): |
290 |
# query generated by security rewriting |
|
291 |
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
|
292 |
'(EXISTS(A owned_by D)) ' |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
293 |
'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
|
294 |
'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
|
295 |
'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
|
296 |
'OR (EXISTS(K concerne F?, F owned_by D, F is Division, A identity K, K is Affaire)))') |
0 | 297 |
self.assertEquals(rqlst.defined_vars['A']._q_invariant, False) |
298 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, False) |
|
299 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
300 |
def test_or_exists_2(self): |
0 | 301 |
rqlst = self._prepare('Any U WHERE EXISTS(U in_group G, G name "managers") OR EXISTS(X owned_by U, X bookmarked_by U)') |
302 |
self.assertEquals(rqlst.defined_vars['U']._q_invariant, False) |
|
303 |
self.assertEquals(rqlst.defined_vars['G']._q_invariant, False) |
|
304 |
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
|
305 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
306 |
def test_or_exists_3(self): |
0 | 307 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
308 |
'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
|
309 |
'(EXISTS(S owned_by D)) OR (EXISTS(S documented_by N, N title "published"))') |
0 | 310 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
311 |
rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 ' |
|
312 |
'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
|
313 |
'(EXISTS(S owned_by D)) OR (EXISTS(S documented_by N, N title "published"))') |
0 | 314 |
self.assertEquals(rqlst.defined_vars['S']._q_invariant, True) |
315 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
316 |
def test_nonregr_ambiguity(self): |
967 | 317 |
rqlst = self._prepare('Note N WHERE N attachment F') |
318 |
# N may be an image as well, not invariant |
|
319 |
self.assertEquals(rqlst.defined_vars['N']._q_invariant, False) |
|
320 |
self.assertEquals(rqlst.defined_vars['F']._q_invariant, True) |
|
321 |
||
0 | 322 |
if __name__ == '__main__': |
323 |
from logilab.common.testlib import unittest_main |
|
324 |
unittest_main() |