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