author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 19 May 2009 16:58:25 +0200 | |
branch | stable |
changeset 1872 | b49fdd5ce8d2 |
parent 1787 | 71c143c0ada3 |
child 1949 | 9064102b4deb |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
2 |
"""unit tests for modules cubicweb.server.querier and cubicweb.server.querier_steps |
|
3 |
""" |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
4 |
from datetime import date, datetime |
0 | 5 |
|
6 |
from logilab.common.testlib import TestCase, unittest_main |
|
7 |
from rql import BadRQLQuery, RQLSyntaxError |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
8 |
|
0 | 9 |
from cubicweb import QueryError, Unauthorized |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
10 |
from cubicweb.server.sqlutils import SQL_PREFIX |
0 | 11 |
from cubicweb.server.utils import crypt_password |
12 |
from cubicweb.server.sources.native import make_schema |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
13 |
from cubicweb.devtools import init_test_database |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
14 |
from cubicweb.devtools.repotest import tuplify, BaseQuerierTC |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
15 |
|
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
16 |
from unittest_session import Variable |
0 | 17 |
|
18 |
||
19 |
# register priority/severity sorting registered procedure |
|
20 |
from rql.utils import register_function, FunctionDescr |
|
21 |
||
22 |
class group_sort_value(FunctionDescr): |
|
23 |
supported_backends = ('sqlite',) |
|
24 |
rtype = 'Int' |
|
25 |
try: |
|
26 |
register_function(group_sort_value) |
|
27 |
except AssertionError: |
|
28 |
pass |
|
29 |
from cubicweb.server.sqlutils import SQL_CONNECT_HOOKS |
|
30 |
def init_sqlite_connexion(cnx): |
|
31 |
def group_sort_value(text): |
|
32 |
return {"managers": "3", "users": "2", "guests": "1", "owners": "0"}[text] |
|
33 |
cnx.create_function("GROUP_SORT_VALUE", 1, group_sort_value) |
|
34 |
SQL_CONNECT_HOOKS['sqlite'].append(init_sqlite_connexion) |
|
35 |
||
36 |
||
37 |
from logilab.common.adbh import _GenericAdvFuncHelper |
|
38 |
TYPEMAP = _GenericAdvFuncHelper.TYPE_MAPPING |
|
39 |
||
40 |
class MakeSchemaTC(TestCase): |
|
41 |
def test_known_values(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
42 |
solution = {'A': 'String', 'B': 'CWUser'} |
1787 | 43 |
self.assertEquals(make_schema((Variable('A'), Variable('B')), solution, |
0 | 44 |
'table0', TYPEMAP), |
45 |
('C0 text,C1 integer', {'A': 'table0.C0', 'B': 'table0.C1'})) |
|
1787 | 46 |
|
0 | 47 |
|
48 |
repo, cnx = init_test_database('sqlite') |
|
49 |
||
50 |
||
51 |
||
52 |
class UtilsTC(BaseQuerierTC): |
|
53 |
repo = repo |
|
1787 | 54 |
|
0 | 55 |
def get_max_eid(self): |
56 |
# no need for cleanup here |
|
57 |
return None |
|
58 |
def cleanup(self): |
|
59 |
# no need for cleanup here |
|
60 |
pass |
|
1787 | 61 |
|
0 | 62 |
def test_preprocess_1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
63 |
reid = self.execute('Any X WHERE X is CWRType, X name "owned_by"')[0][0] |
0 | 64 |
rqlst = self._prepare('Any COUNT(RDEF) WHERE RDEF relation_type X, X eid %(x)s', {'x': reid}) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
65 |
self.assertEquals(rqlst.solutions, [{'RDEF': 'CWAttribute'}, {'RDEF': 'CWRelation'}]) |
1787 | 66 |
|
0 | 67 |
def test_preprocess_2(self): |
68 |
teid = self.execute("INSERT Tag X: X name 'tag'")[0][0] |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
69 |
#geid = self.execute("CWGroup G WHERE G name 'users'")[0][0] |
0 | 70 |
#self.execute("SET X tags Y WHERE X eid %(t)s, Y eid %(g)s", |
71 |
# {'g': geid, 't': teid}, 'g') |
|
72 |
rqlst = self._prepare('Any X WHERE E eid %(x)s, E tags X', {'x': teid}) |
|
73 |
# the query may be optimized, should keep only one solution |
|
74 |
# (any one, etype will be discarded) |
|
75 |
self.assertEquals(len(rqlst.solutions), 1) |
|
1787 | 76 |
|
0 | 77 |
def test_preprocess_security(self): |
78 |
plan = self._prepare_plan('Any ETN,COUNT(X) GROUPBY ETN ' |
|
79 |
'WHERE X is ET, ET name ETN') |
|
80 |
plan.session = self._user_session(('users',))[1] |
|
81 |
union = plan.rqlst |
|
82 |
plan.preprocess(union) |
|
83 |
self.assertEquals(len(union.children), 1) |
|
84 |
self.assertEquals(len(union.children[0].with_), 1) |
|
85 |
subq = union.children[0].with_[0].query |
|
86 |
self.assertEquals(len(subq.children), 3) |
|
87 |
self.assertEquals([t.as_string() for t in union.children[0].selection], |
|
88 |
['ETN','COUNT(X)']) |
|
89 |
self.assertEquals([t.as_string() for t in union.children[0].groupby], |
|
90 |
['ETN']) |
|
91 |
partrqls = sorted(((rqlst.as_string(), rqlst.solutions) for rqlst in subq.children)) |
|
92 |
rql, solutions = partrqls[0] |
|
93 |
self.assertEquals(rql, |
|
94 |
'Any ETN,X WHERE X is ET, ET name ETN, (EXISTS(X owned_by %(B)s))' |
|
95 |
' OR ((((EXISTS(D concerne C?, C owned_by %(B)s, X identity D, C is Division, D is Affaire))' |
|
96 |
' OR (EXISTS(H concerne G?, G owned_by %(B)s, G is SubDivision, X identity H, H is Affaire)))' |
|
97 |
' OR (EXISTS(I concerne F?, F owned_by %(B)s, F is Societe, X identity I, I is Affaire)))' |
|
98 |
' OR (EXISTS(J concerne E?, E owned_by %(B)s, E is Note, X identity J, J is Affaire)))' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
99 |
', ET is CWEType, X is Affaire') |
0 | 100 |
self.assertEquals(solutions, [{'C': 'Division', |
101 |
'D': 'Affaire', |
|
102 |
'E': 'Note', |
|
103 |
'F': 'Societe', |
|
104 |
'G': 'SubDivision', |
|
105 |
'H': 'Affaire', |
|
106 |
'I': 'Affaire', |
|
107 |
'J': 'Affaire', |
|
108 |
'X': 'Affaire', |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
109 |
'ET': 'CWEType', 'ETN': 'String'}]) |
0 | 110 |
rql, solutions = partrqls[1] |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
111 |
self.assertEquals(rql, 'Any ETN,X WHERE X is ET, ET name ETN, ET is CWEType, ' |
1787 | 112 |
'X is IN(Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, CWUser, Card, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Note, Personne, RQLExpression, Societe, State, SubDivision, Tag, TrInfo, Transition)') |
0 | 113 |
self.assertListEquals(sorted(solutions), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
114 |
sorted([{'X': 'Bookmark', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
115 |
{'X': 'Card', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
116 |
{'X': 'Comment', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
117 |
{'X': 'Division', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
118 |
{'X': 'CWCache', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
119 |
{'X': 'CWConstraint', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
120 |
{'X': 'CWConstraintType', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
121 |
{'X': 'CWEType', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
122 |
{'X': 'CWAttribute', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
123 |
{'X': 'CWGroup', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
124 |
{'X': 'Email', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
125 |
{'X': 'EmailAddress', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
126 |
{'X': 'EmailPart', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
127 |
{'X': 'EmailThread', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
128 |
{'X': 'CWRelation', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
129 |
{'X': 'CWPermission', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
130 |
{'X': 'CWProperty', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
131 |
{'X': 'CWRType', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
132 |
{'X': 'CWUser', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
133 |
{'X': 'File', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
134 |
{'X': 'Folder', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
135 |
{'X': 'Image', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
136 |
{'X': 'Note', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
137 |
{'X': 'Personne', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
138 |
{'X': 'RQLExpression', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
139 |
{'X': 'Societe', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
140 |
{'X': 'State', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
141 |
{'X': 'SubDivision', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
142 |
{'X': 'Tag', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
143 |
{'X': 'Transition', 'ETN': 'String', 'ET': 'CWEType'}, |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
144 |
{'X': 'TrInfo', 'ETN': 'String', 'ET': 'CWEType'}])) |
0 | 145 |
rql, solutions = partrqls[2] |
146 |
self.assertEquals(rql, |
|
147 |
'Any ETN,X WHERE X is ET, ET name ETN, EXISTS(X owned_by %(C)s), ' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
148 |
'ET is CWEType, X is Basket') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
149 |
self.assertEquals(solutions, [{'ET': 'CWEType', |
0 | 150 |
'X': 'Basket', |
151 |
'ETN': 'String', |
|
152 |
}]) |
|
153 |
||
154 |
def test_preprocess_security_aggregat(self): |
|
155 |
plan = self._prepare_plan('Any MAX(X)') |
|
156 |
plan.session = self._user_session(('users',))[1] |
|
157 |
union = plan.rqlst |
|
158 |
plan.preprocess(union) |
|
159 |
self.assertEquals(len(union.children), 1) |
|
160 |
self.assertEquals(len(union.children[0].with_), 1) |
|
161 |
subq = union.children[0].with_[0].query |
|
162 |
self.assertEquals(len(subq.children), 3) |
|
163 |
self.assertEquals([t.as_string() for t in union.children[0].selection], |
|
164 |
['MAX(X)']) |
|
1787 | 165 |
|
0 | 166 |
def test_preprocess_nonregr(self): |
167 |
rqlst = self._prepare('Any S ORDERBY SI WHERE NOT S ecrit_par O, S para SI') |
|
168 |
self.assertEquals(len(rqlst.solutions), 1) |
|
1787 | 169 |
|
0 | 170 |
def test_build_description(self): |
171 |
# should return an empty result set |
|
172 |
rset = self.execute('Any X WHERE X eid %(x)s', {'x': self.session.user.eid}) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
173 |
self.assertEquals(rset.description[0][0], 'CWUser') |
0 | 174 |
rset = self.execute('Any 1') |
175 |
self.assertEquals(rset.description[0][0], 'Int') |
|
176 |
rset = self.execute('Any TRUE') |
|
177 |
self.assertEquals(rset.description[0][0], 'Boolean') |
|
178 |
rset = self.execute('Any "hop"') |
|
179 |
self.assertEquals(rset.description[0][0], 'String') |
|
180 |
rset = self.execute('Any TODAY') |
|
181 |
self.assertEquals(rset.description[0][0], 'Date') |
|
182 |
rset = self.execute('Any NOW') |
|
183 |
self.assertEquals(rset.description[0][0], 'Datetime') |
|
184 |
rset = self.execute('Any %(x)s', {'x': 1}) |
|
185 |
self.assertEquals(rset.description[0][0], 'Int') |
|
186 |
rset = self.execute('Any %(x)s', {'x': 1L}) |
|
187 |
self.assertEquals(rset.description[0][0], 'Int') |
|
188 |
rset = self.execute('Any %(x)s', {'x': True}) |
|
189 |
self.assertEquals(rset.description[0][0], 'Boolean') |
|
190 |
rset = self.execute('Any %(x)s', {'x': 1.0}) |
|
191 |
self.assertEquals(rset.description[0][0], 'Float') |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
192 |
rset = self.execute('Any %(x)s', {'x': datetime.now()}) |
0 | 193 |
self.assertEquals(rset.description[0][0], 'Datetime') |
194 |
rset = self.execute('Any %(x)s', {'x': 'str'}) |
|
195 |
self.assertEquals(rset.description[0][0], 'String') |
|
196 |
rset = self.execute('Any %(x)s', {'x': u'str'}) |
|
197 |
self.assertEquals(rset.description[0][0], 'String') |
|
198 |
||
199 |
||
200 |
class QuerierTC(BaseQuerierTC): |
|
201 |
repo = repo |
|
202 |
||
203 |
def test_encoding_pb(self): |
|
204 |
self.assertRaises(RQLSyntaxError, self.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
205 |
'Any X WHERE X is CWRType, X name "�wned_by"') |
0 | 206 |
|
207 |
def test_unknown_eid(self): |
|
208 |
# should return an empty result set |
|
209 |
self.failIf(self.execute('Any X WHERE X eid 99999999')) |
|
1787 | 210 |
|
0 | 211 |
# selection queries tests ################################################# |
1787 | 212 |
|
0 | 213 |
def test_select_1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
214 |
rset = self.execute('Any X ORDERBY X WHERE X is CWGroup') |
0 | 215 |
result, descr = rset.rows, rset.description |
216 |
self.assertEquals(tuplify(result), [(1,), (2,), (3,), (4,)]) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
217 |
self.assertEquals(descr, [('CWGroup',), ('CWGroup',), ('CWGroup',), ('CWGroup',)]) |
1787 | 218 |
|
0 | 219 |
def test_select_2(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
220 |
rset = self.execute('Any X ORDERBY N WHERE X is CWGroup, X name N') |
0 | 221 |
self.assertEquals(tuplify(rset.rows), [(3,), (1,), (4,), (2,)]) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
222 |
self.assertEquals(rset.description, [('CWGroup',), ('CWGroup',), ('CWGroup',), ('CWGroup',)]) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
223 |
rset = self.execute('Any X ORDERBY N DESC WHERE X is CWGroup, X name N') |
0 | 224 |
self.assertEquals(tuplify(rset.rows), [(2,), (4,), (1,), (3,)]) |
1787 | 225 |
|
0 | 226 |
def test_select_3(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
227 |
rset = self.execute('Any N GROUPBY N WHERE X is CWGroup, X name N') |
0 | 228 |
result, descr = rset.rows, rset.description |
229 |
result.sort() |
|
230 |
self.assertEquals(tuplify(result), [('guests',), ('managers',), ('owners',), ('users',)]) |
|
231 |
self.assertEquals(descr, [('String',), ('String',), ('String',), ('String',)]) |
|
1787 | 232 |
|
0 | 233 |
def test_select_is(self): |
234 |
rset = self.execute('Any X, TN ORDERBY TN LIMIT 10 WHERE X is T, T name TN') |
|
235 |
result, descr = rset.rows, rset.description |
|
236 |
self.assertEquals(result[0][1], descr[0][0]) |
|
1787 | 237 |
|
0 | 238 |
def test_select_is_aggr(self): |
239 |
rset = self.execute('Any TN, COUNT(X) GROUPBY TN ORDERBY 2 DESC WHERE X is T, T name TN') |
|
240 |
result, descr = rset.rows, rset.description |
|
241 |
self.assertEquals(descr[0][0], 'String') |
|
242 |
self.assertEquals(descr[0][1], 'Int') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
243 |
self.assertEquals(result[0][0], 'CWRelation') |
1787 | 244 |
|
0 | 245 |
def test_select_groupby_orderby(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
246 |
rset = self.execute('Any N GROUPBY N ORDERBY N WHERE X is CWGroup, X name N') |
0 | 247 |
self.assertEquals(tuplify(rset.rows), [('guests',), ('managers',), ('owners',), ('users',)]) |
248 |
self.assertEquals(rset.description, [('String',), ('String',), ('String',), ('String',)]) |
|
1787 | 249 |
|
0 | 250 |
def test_select_complex_groupby(self): |
251 |
rset = self.execute('Any N GROUPBY N WHERE X name N') |
|
252 |
rset = self.execute('Any N,MAX(D) GROUPBY N LIMIT 5 WHERE X name N, X creation_date D') |
|
1787 | 253 |
|
0 | 254 |
def test_select_inlined_groupby(self): |
255 |
seid = self.execute('State X WHERE X name "deactivated"')[0][0] |
|
256 |
rset = self.execute('Any U,L,S GROUPBY U,L,S WHERE X in_state S, U login L, S eid %s' % seid) |
|
1787 | 257 |
|
0 | 258 |
def test_select_complex_orderby(self): |
259 |
rset1 = self.execute('Any N ORDERBY N WHERE X name N') |
|
260 |
self.assertEquals(sorted(rset1.rows), rset1.rows) |
|
261 |
rset = self.execute('Any N ORDERBY N LIMIT 5 OFFSET 1 WHERE X name N') |
|
1787 | 262 |
self.assertEquals(rset.rows[0][0], rset1.rows[1][0]) |
0 | 263 |
self.assertEquals(len(rset), 5) |
1787 | 264 |
|
0 | 265 |
def test_select_5(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
266 |
rset = self.execute('Any X, TMP ORDERBY TMP WHERE X name TMP, X is CWGroup') |
0 | 267 |
self.assertEquals(tuplify(rset.rows), [(3, 'guests',), (1, 'managers',), (4, 'owners',), (2, 'users',)]) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
268 |
self.assertEquals(rset.description, [('CWGroup', 'String',), ('CWGroup', 'String',), ('CWGroup', 'String',), ('CWGroup', 'String',)]) |
1787 | 269 |
|
0 | 270 |
def test_select_6(self): |
271 |
self.execute("INSERT Personne X: X nom 'bidule'")[0] |
|
272 |
rset = self.execute('Any Y where X name TMP, Y nom in (TMP, "bidule")') |
|
273 |
#self.assertEquals(rset.description, [('Personne',), ('Personne',)]) |
|
274 |
self.assert_(('Personne',) in rset.description) |
|
275 |
rset = self.execute('DISTINCT Any Y where X name TMP, Y nom in (TMP, "bidule")') |
|
276 |
self.assert_(('Personne',) in rset.description) |
|
1787 | 277 |
|
0 | 278 |
def test_select_not_attr(self): |
279 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
280 |
self.execute("INSERT Societe X: X nom 'chouette'") |
|
281 |
rset = self.execute('Personne X WHERE NOT X nom "bidule"') |
|
282 |
self.assertEquals(len(rset.rows), 0, rset.rows) |
|
283 |
rset = self.execute('Personne X WHERE NOT X nom "bid"') |
|
284 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
285 |
self.execute("SET P travaille S WHERE P nom 'bidule', S nom 'chouette'") |
|
286 |
rset = self.execute('Personne X WHERE NOT X travaille S') |
|
287 |
self.assertEquals(len(rset.rows), 0, rset.rows) |
|
1787 | 288 |
|
0 | 289 |
def test_select_is_in(self): |
290 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
291 |
self.execute("INSERT Societe X: X nom 'chouette'") |
|
292 |
self.assertEquals(len(self.execute("Any X WHERE X is IN (Personne, Societe)")), |
|
293 |
2) |
|
1787 | 294 |
|
0 | 295 |
def test_select_not_rel(self): |
296 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
297 |
self.execute("INSERT Societe X: X nom 'chouette'") |
|
298 |
self.execute("INSERT Personne X: X nom 'autre'") |
|
299 |
self.execute("SET P travaille S WHERE P nom 'bidule', S nom 'chouette'") |
|
300 |
rset = self.execute('Personne X WHERE NOT X travaille S') |
|
301 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
302 |
rset = self.execute('Personne X WHERE NOT X travaille S, S nom "chouette"') |
|
303 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
1787 | 304 |
|
0 | 305 |
def test_select_nonregr_inlined(self): |
306 |
self.execute("INSERT Note X: X para 'bidule'") |
|
307 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
308 |
self.execute("INSERT Personne X: X nom 'autre'") |
|
309 |
self.execute("SET X ecrit_par P WHERE X para 'bidule', P nom 'chouette'") |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
310 |
rset = self.execute('Any U,T ORDERBY T DESC WHERE U is CWUser, ' |
0 | 311 |
'N ecrit_par U, N type T')#, {'x': self.ueid}) |
312 |
self.assertEquals(len(rset.rows), 0) |
|
1787 | 313 |
|
0 | 314 |
def test_select_nonregr_edition_not(self): |
315 |
groupeids = set((1, 2, 3)) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
316 |
groupreadperms = set(r[0] for r in self.execute('Any Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), X read_permission Y')) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
317 |
rset = self.execute('DISTINCT Any Y WHERE X is CWEType, X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 318 |
self.assertEquals(sorted(r[0] for r in rset.rows), sorted(groupeids - groupreadperms)) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
319 |
rset = self.execute('DISTINCT Any Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y') |
0 | 320 |
self.assertEquals(sorted(r[0] for r in rset.rows), sorted(groupeids - groupreadperms)) |
1787 | 321 |
|
0 | 322 |
def test_select_outer_join(self): |
323 |
peid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
324 |
peid2 = self.execute("INSERT Personne X: X nom 'autre'")[0][0] |
|
325 |
seid1 = self.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
|
326 |
seid2 = self.execute("INSERT Societe X: X nom 'chouetos'")[0][0] |
|
327 |
rset = self.execute('Any X,S ORDERBY X WHERE X travaille S?') |
|
328 |
self.assertEquals(rset.rows, [[peid1, None], [peid2, None]]) |
|
329 |
self.execute("SET P travaille S WHERE P nom 'bidule', S nom 'chouette'") |
|
330 |
rset = self.execute('Any X,S ORDERBY X WHERE X travaille S?') |
|
331 |
self.assertEquals(rset.rows, [[peid1, seid1], [peid2, None]]) |
|
332 |
rset = self.execute('Any S,X ORDERBY S WHERE X? travaille S') |
|
333 |
self.assertEquals(rset.rows, [[seid1, peid1], [seid2, None]]) |
|
1787 | 334 |
|
0 | 335 |
def test_select_outer_join_optimized(self): |
336 |
peid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
337 |
rset = self.execute('Any X WHERE X eid %(x)s, P? connait X', {'x':peid1}, 'x') |
|
338 |
self.assertEquals(rset.rows, [[peid1]]) |
|
339 |
rset = self.execute('Any X WHERE X eid %(x)s, X require_permission P?', {'x':peid1}, 'x') |
|
340 |
self.assertEquals(rset.rows, [[peid1]]) |
|
341 |
||
342 |
def test_select_left_outer_join(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
343 |
ueid = self.execute("INSERT CWUser X: X login 'bob', X upassword 'toto', X in_group G " |
0 | 344 |
"WHERE G name 'users'")[0][0] |
345 |
self.commit() |
|
346 |
try: |
|
347 |
rset = self.execute('Any FS,TS,C,D,U ORDERBY D DESC ' |
|
348 |
'WHERE WF wf_info_for X,' |
|
349 |
'WF from_state FS?, WF to_state TS, WF comment C,' |
|
350 |
'WF creation_date D, WF owned_by U, X eid %(x)s', |
|
351 |
{'x': ueid}, 'x') |
|
352 |
self.assertEquals(len(rset), 1) |
|
353 |
self.execute('SET X in_state S WHERE X eid %(x)s, S name "deactivated"', |
|
354 |
{'x': ueid}, 'x') |
|
355 |
rset = self.execute('Any FS,TS,C,D,U ORDERBY D DESC ' |
|
356 |
'WHERE WF wf_info_for X,' |
|
357 |
'WF from_state FS?, WF to_state TS, WF comment C,' |
|
358 |
'WF creation_date D, WF owned_by U, X eid %(x)s', |
|
359 |
{'x': ueid}, 'x') |
|
360 |
self.assertEquals(len(rset), 2) |
|
361 |
finally: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
362 |
self.execute('DELETE CWUser X WHERE X eid %s' % ueid) |
0 | 363 |
self.commit() |
364 |
||
365 |
def test_select_ambigous_outer_join(self): |
|
366 |
teid = self.execute("INSERT Tag X: X name 'tag'")[0][0] |
|
367 |
self.execute("INSERT Tag X: X name 'tagbis'")[0][0] |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
368 |
geid = self.execute("CWGroup G WHERE G name 'users'")[0][0] |
0 | 369 |
self.execute("SET X tags Y WHERE X eid %(t)s, Y eid %(g)s", |
370 |
{'g': geid, 't': teid}, 'g') |
|
371 |
rset = self.execute("Any GN,TN ORDERBY GN WHERE T? tags G, T name TN, G name GN") |
|
372 |
self.failUnless(['users', 'tag'] in rset.rows) |
|
373 |
self.failUnless(['activated', None] in rset.rows) |
|
374 |
rset = self.execute("Any GN,TN ORDERBY GN WHERE T tags G?, T name TN, G name GN") |
|
1787 | 375 |
self.assertEquals(rset.rows, [[None, 'tagbis'], ['users', 'tag']]) |
376 |
||
0 | 377 |
def test_select_not_inline_rel(self): |
378 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
379 |
self.execute("INSERT Note X: X type 'a'") |
|
380 |
self.execute("INSERT Note X: X type 'b'") |
|
381 |
self.execute("SET X ecrit_par Y WHERE X type 'a', Y nom 'bidule'") |
|
382 |
rset = self.execute('Note X WHERE NOT X ecrit_par P') |
|
383 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
1787 | 384 |
|
0 | 385 |
def test_select_not_unlinked_multiple_solutions(self): |
386 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
387 |
self.execute("INSERT Note X: X type 'a'") |
|
388 |
self.execute("INSERT Note X: X type 'b'") |
|
389 |
self.execute("SET Y evaluee X WHERE X type 'a', Y nom 'bidule'") |
|
390 |
rset = self.execute('Note X WHERE NOT Y evaluee X') |
|
391 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
392 |
||
393 |
def test_select_aggregat_count(self): |
|
394 |
rset = self.execute('Any COUNT(X)') |
|
395 |
self.assertEquals(len(rset.rows), 1) |
|
396 |
self.assertEquals(len(rset.rows[0]), 1) |
|
397 |
self.assertEquals(rset.description, [('Int',)]) |
|
1787 | 398 |
|
0 | 399 |
def test_select_aggregat_sum(self): |
400 |
rset = self.execute('Any SUM(O) WHERE X ordernum O') |
|
401 |
self.assertEquals(len(rset.rows), 1) |
|
402 |
self.assertEquals(len(rset.rows[0]), 1) |
|
403 |
self.assertEquals(rset.description, [('Int',)]) |
|
1787 | 404 |
|
0 | 405 |
def test_select_aggregat_min(self): |
406 |
rset = self.execute('Any MIN(X) WHERE X is Personne') |
|
407 |
self.assertEquals(len(rset.rows), 1) |
|
408 |
self.assertEquals(len(rset.rows[0]), 1) |
|
409 |
self.assertEquals(rset.description, [('Personne',)]) |
|
410 |
rset = self.execute('Any MIN(O) WHERE X ordernum O') |
|
411 |
self.assertEquals(len(rset.rows), 1) |
|
412 |
self.assertEquals(len(rset.rows[0]), 1) |
|
413 |
self.assertEquals(rset.description, [('Int',)]) |
|
1787 | 414 |
|
0 | 415 |
def test_select_aggregat_max(self): |
416 |
rset = self.execute('Any MAX(X) WHERE X is Personne') |
|
417 |
self.assertEquals(len(rset.rows), 1) |
|
418 |
self.assertEquals(len(rset.rows[0]), 1) |
|
419 |
self.assertEquals(rset.description, [('Personne',)]) |
|
420 |
rset = self.execute('Any MAX(O) WHERE X ordernum O') |
|
421 |
self.assertEquals(len(rset.rows), 1) |
|
422 |
self.assertEquals(len(rset.rows[0]), 1) |
|
423 |
self.assertEquals(rset.description, [('Int',)]) |
|
424 |
||
425 |
def test_select_custom_aggregat_concat_string(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
426 |
rset = self.execute('Any CONCAT_STRINGS(N) WHERE X is CWGroup, X name N') |
0 | 427 |
self.failUnless(rset) |
428 |
self.failUnlessEqual(sorted(rset[0][0].split(', ')), ['guests', 'managers', |
|
429 |
'owners', 'users']) |
|
430 |
||
431 |
def test_select_custom_regproc_limit_size(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
432 |
rset = self.execute('Any TEXT_LIMIT_SIZE(N, 3) WHERE X is CWGroup, X name N, X name "managers"') |
0 | 433 |
self.failUnless(rset) |
434 |
self.failUnlessEqual(rset[0][0], 'man...') |
|
435 |
self.execute("INSERT Basket X: X name 'bidule', X description '<b>hop hop</b>', X description_format 'text/html'") |
|
436 |
rset = self.execute('Any LIMIT_SIZE(D, DF, 3) WHERE X is Basket, X description D, X description_format DF') |
|
437 |
self.failUnless(rset) |
|
438 |
self.failUnlessEqual(rset[0][0], 'hop...') |
|
439 |
||
440 |
def test_select_regproc_orderby(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
441 |
rset = self.execute('DISTINCT Any X,N ORDERBY GROUP_SORT_VALUE(N) WHERE X is CWGroup, X name N, X name "managers"') |
0 | 442 |
self.failUnlessEqual(len(rset), 1) |
443 |
self.failUnlessEqual(rset[0][1], 'managers') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
444 |
rset = self.execute('Any X,N ORDERBY GROUP_SORT_VALUE(N) WHERE X is CWGroup, X name N, NOT U in_group X, U login "admin"') |
0 | 445 |
self.failUnlessEqual(len(rset), 3) |
446 |
self.failUnlessEqual(rset[0][1], 'owners') |
|
1787 | 447 |
|
0 | 448 |
def test_select_aggregat_sort(self): |
449 |
rset = self.execute('Any G, COUNT(U) GROUPBY G ORDERBY 2 WHERE U in_group G') |
|
450 |
self.assertEquals(len(rset.rows), 2) |
|
451 |
self.assertEquals(len(rset.rows[0]), 2) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
452 |
self.assertEquals(rset.description[0], ('CWGroup', 'Int',)) |
0 | 453 |
|
454 |
def test_select_aggregat_having(self): |
|
455 |
rset = self.execute('Any N,COUNT(RDEF) GROUPBY N ORDERBY 2,N ' |
|
456 |
'WHERE RT name N, RDEF relation_type RT ' |
|
457 |
'HAVING COUNT(RDEF) > 10') |
|
458 |
self.assertListEquals(rset.rows, |
|
439 | 459 |
[[u'description', 11], ['in_basket', 11], |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
460 |
[u'name', 13], [u'created_by', 33], |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
461 |
[u'creation_date', 33], [u'is', 33], [u'is_instance_of', 33], |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
462 |
[u'modification_date', 33], [u'owned_by', 33]]) |
0 | 463 |
|
464 |
def test_select_aggregat_having_dumb(self): |
|
465 |
# dumb but should not raise an error |
|
466 |
rset = self.execute('Any U,COUNT(X) GROUPBY U ' |
|
467 |
'WHERE U eid %(x)s, X owned_by U ' |
|
468 |
'HAVING COUNT(X) > 10', {'x': self.ueid}) |
|
469 |
self.assertEquals(len(rset.rows), 1) |
|
470 |
self.assertEquals(rset.rows[0][0], self.ueid) |
|
471 |
||
472 |
def test_select_complex_sort(self): |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
473 |
self.skip('retry me once http://www.sqlite.org/cvstrac/tktview?tn=3773 is fixed') |
0 | 474 |
rset = self.execute('Any X ORDERBY X,D LIMIT 5 WHERE X creation_date D') |
475 |
result = rset.rows |
|
476 |
result.sort() |
|
477 |
self.assertEquals(tuplify(result), [(1,), (2,), (3,), (4,), (5,)]) |
|
1787 | 478 |
|
0 | 479 |
def test_select_upper(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
480 |
rset = self.execute('Any X, UPPER(L) ORDERBY L WHERE X is CWUser, X login L') |
0 | 481 |
self.assertEquals(len(rset.rows), 2) |
482 |
self.assertEquals(rset.rows[0][1], 'ADMIN') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
483 |
self.assertEquals(rset.description[0], ('CWUser', 'String',)) |
0 | 484 |
self.assertEquals(rset.rows[1][1], 'ANON') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
485 |
self.assertEquals(rset.description[1], ('CWUser', 'String',)) |
0 | 486 |
eid = rset.rows[0][0] |
487 |
rset = self.execute('Any UPPER(L) WHERE X eid %s, X login L'%eid) |
|
488 |
self.assertEquals(rset.rows[0][0], 'ADMIN') |
|
489 |
self.assertEquals(rset.description, [('String',)]) |
|
490 |
||
491 |
## def test_select_simplified(self): |
|
492 |
## ueid = self.session.user.eid |
|
493 |
## rset = self.execute('Any L WHERE %s login L'%ueid) |
|
494 |
## self.assertEquals(rset.rows[0][0], 'admin') |
|
495 |
## rset = self.execute('Any L WHERE %(x)s login L', {'x':ueid}) |
|
496 |
## self.assertEquals(rset.rows[0][0], 'admin') |
|
1787 | 497 |
|
0 | 498 |
def test_select_searchable_text_1(self): |
499 |
rset = self.execute(u"INSERT Personne X: X nom 'bid�le'") |
|
500 |
rset = self.execute(u"INSERT Societe X: X nom 'bid�le'") |
|
501 |
rset = self.execute("INSERT Societe X: X nom 'chouette'") |
|
502 |
self.commit() |
|
503 |
rset = self.execute('Any X where X has_text %(text)s', {'text': u'bid�le'}) |
|
504 |
self.assertEquals(len(rset.rows), 2, rset.rows) |
|
505 |
rset = self.execute(u'Any N where N has_text "bid�le"') |
|
506 |
self.assertEquals(len(rset.rows), 2, rset.rows) |
|
507 |
biduleeids = [r[0] for r in rset.rows] |
|
508 |
rset = self.execute(u'Any N where NOT N has_text "bid�le"') |
|
509 |
self.failIf([r[0] for r in rset.rows if r[0] in biduleeids]) |
|
510 |
# duh? |
|
511 |
rset = self.execute('Any X WHERE X has_text %(text)s', {'text': u'�a'}) |
|
1787 | 512 |
|
0 | 513 |
def test_select_searchable_text_2(self): |
514 |
rset = self.execute("INSERT Personne X: X nom 'bidule'") |
|
515 |
rset = self.execute("INSERT Personne X: X nom 'chouette'") |
|
516 |
rset = self.execute("INSERT Societe X: X nom 'bidule'") |
|
517 |
self.commit() |
|
518 |
rset = self.execute('Personne N where N has_text "bidule"') |
|
519 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
1787 | 520 |
|
0 | 521 |
def test_select_searchable_text_3(self): |
522 |
rset = self.execute("INSERT Personne X: X nom 'bidule', X sexe 'M'") |
|
523 |
rset = self.execute("INSERT Personne X: X nom 'bidule', X sexe 'F'") |
|
524 |
rset = self.execute("INSERT Societe X: X nom 'bidule'") |
|
525 |
self.commit() |
|
526 |
rset = self.execute('Any X where X has_text "bidule" and X sexe "M"') |
|
527 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
1787 | 528 |
|
0 | 529 |
def test_select_multiple_searchable_text(self): |
530 |
self.execute(u"INSERT Personne X: X nom 'bid�le'") |
|
531 |
self.execute("INSERT Societe X: X nom 'chouette', S travaille X") |
|
532 |
self.execute(u"INSERT Personne X: X nom 'bid�le'") |
|
533 |
self.commit() |
|
534 |
rset = self.execute('Personne X WHERE X has_text %(text)s, X travaille S, S has_text %(text2)s', |
|
535 |
{'text': u'bid�le', |
|
536 |
'text2': u'chouette',} |
|
537 |
) |
|
538 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
1787 | 539 |
|
0 | 540 |
def test_select_no_descr(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
541 |
rset = self.execute('Any X WHERE X is CWGroup', build_descr=0) |
0 | 542 |
rset.rows.sort() |
543 |
self.assertEquals(tuplify(rset.rows), [(1,), (2,), (3,), (4,)]) |
|
544 |
self.assertEquals(rset.description, ()) |
|
545 |
||
546 |
def test_select_limit_offset(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
547 |
rset = self.execute('CWGroup X ORDERBY N LIMIT 2 WHERE X name N') |
0 | 548 |
self.assertEquals(tuplify(rset.rows), [(3,), (1,)]) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
549 |
self.assertEquals(rset.description, [('CWGroup',), ('CWGroup',)]) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
550 |
rset = self.execute('CWGroup X ORDERBY N LIMIT 2 OFFSET 2 WHERE X name N') |
0 | 551 |
self.assertEquals(tuplify(rset.rows), [(4,), (2,)]) |
1787 | 552 |
|
0 | 553 |
def test_select_symetric(self): |
554 |
self.execute("INSERT Personne X: X nom 'machin'") |
|
555 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
556 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
557 |
self.execute("INSERT Personne X: X nom 'trucmuche'") |
|
558 |
self.execute("SET X connait Y WHERE X nom 'chouette', Y nom 'bidule'") |
|
559 |
self.execute("SET X connait Y WHERE X nom 'machin', Y nom 'chouette'") |
|
560 |
rset = self.execute('Any P where P connait P2') |
|
561 |
self.assertEquals(len(rset.rows), 3, rset.rows) |
|
562 |
rset = self.execute('Any P where NOT P connait P2') |
|
563 |
self.assertEquals(len(rset.rows), 1, rset.rows) # trucmuche |
|
564 |
rset = self.execute('Any P where P connait P2, P2 nom "bidule"') |
|
565 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
566 |
rset = self.execute('Any P where P2 connait P, P2 nom "bidule"') |
|
567 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
568 |
rset = self.execute('Any P where P connait P2, P2 nom "chouette"') |
|
569 |
self.assertEquals(len(rset.rows), 2, rset.rows) |
|
570 |
rset = self.execute('Any P where P2 connait P, P2 nom "chouette"') |
|
571 |
self.assertEquals(len(rset.rows), 2, rset.rows) |
|
1787 | 572 |
|
0 | 573 |
def test_select_inline(self): |
574 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
575 |
self.execute("INSERT Note X: X type 'a'") |
|
576 |
self.execute("SET X ecrit_par Y WHERE X type 'a', Y nom 'bidule'") |
|
577 |
rset = self.execute('Any N where N ecrit_par X, X nom "bidule"') |
|
578 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
1787 | 579 |
|
0 | 580 |
def test_select_creation_date(self): |
581 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
582 |
rset = self.execute('Any D WHERE X nom "bidule", X creation_date D') |
|
583 |
self.assertEqual(len(rset.rows), 1) |
|
584 |
||
585 |
def test_select_or_relation(self): |
|
586 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
587 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
588 |
self.execute("INSERT Societe X: X nom 'logilab'") |
|
589 |
self.execute("INSERT Societe X: X nom 'caesium'") |
|
590 |
self.execute("SET P travaille S WHERE P nom 'bidule', S nom 'logilab'") |
|
591 |
rset = self.execute('DISTINCT Any P WHERE P travaille S1 OR P travaille S2, S1 nom "logilab", S2 nom "caesium"') |
|
592 |
self.assertEqual(len(rset.rows), 1) |
|
593 |
self.execute("SET P travaille S WHERE P nom 'chouette', S nom 'caesium'") |
|
594 |
rset = self.execute('DISTINCT Any P WHERE P travaille S1 OR P travaille S2, S1 nom "logilab", S2 nom "caesium"') |
|
595 |
self.assertEqual(len(rset.rows), 2) |
|
1787 | 596 |
|
0 | 597 |
def test_select_or_sym_relation(self): |
598 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
599 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
600 |
self.execute("INSERT Personne X: X nom 'truc'") |
|
601 |
self.execute("SET P connait S WHERE P nom 'bidule', S nom 'chouette'") |
|
602 |
rset = self.execute('DISTINCT Any P WHERE S connait P, S nom "chouette"') |
|
603 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
|
604 |
rset = self.execute('DISTINCT Any P WHERE P connait S or S connait P, S nom "chouette"') |
|
605 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
|
606 |
self.execute("SET P connait S WHERE P nom 'chouette', S nom 'truc'") |
|
607 |
rset = self.execute('DISTINCT Any P WHERE S connait P, S nom "chouette"') |
|
608 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
|
609 |
rset = self.execute('DISTINCT Any P WHERE P connait S OR S connait P, S nom "chouette"') |
|
610 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
|
1787 | 611 |
|
0 | 612 |
def test_select_follow_relation(self): |
613 |
self.execute("INSERT Affaire X: X sujet 'cool'") |
|
614 |
self.execute("INSERT Societe X: X nom 'chouette'") |
|
615 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
616 |
self.execute("INSERT Note X: X para 'truc'") |
|
617 |
self.execute("SET S evaluee N WHERE S is Societe, N is Note") |
|
618 |
self.execute("INSERT Societe X: X nom 'bidule'") |
|
619 |
self.execute("INSERT Note X: X para 'troc'") |
|
620 |
self.execute("SET S evaluee N WHERE S nom 'bidule', N para 'troc'") |
|
621 |
rset = self.execute('DISTINCT Any A,N WHERE A concerne S, S evaluee N') |
|
622 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
|
623 |
||
624 |
def test_select_ordered_distinct_1(self): |
|
625 |
self.execute("INSERT Affaire X: X sujet 'cool', X ref '1'") |
|
626 |
self.execute("INSERT Affaire X: X sujet 'cool', X ref '2'") |
|
627 |
rset = self.execute('DISTINCT Any S ORDERBY R WHERE A is Affaire, A sujet S, A ref R') |
|
628 |
self.assertEqual(rset.rows, [['cool']]) |
|
629 |
||
630 |
def test_select_ordered_distinct_2(self): |
|
631 |
self.execute("INSERT Affaire X: X sujet 'minor'") |
|
632 |
self.execute("INSERT Affaire X: X sujet 'important'") |
|
633 |
self.execute("INSERT Affaire X: X sujet 'normal'") |
|
634 |
self.execute("INSERT Affaire X: X sujet 'zou'") |
|
635 |
self.execute("INSERT Affaire X: X sujet 'abcd'") |
|
636 |
rset = self.execute('DISTINCT Any S ORDERBY S WHERE A is Affaire, A sujet S') |
|
637 |
self.assertEqual(rset.rows, [['abcd'], ['important'], ['minor'], ['normal'], ['zou']]) |
|
1787 | 638 |
|
0 | 639 |
def test_select_ordered_distinct_3(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
640 |
rset = self.execute('DISTINCT Any N ORDERBY GROUP_SORT_VALUE(N) WHERE X is CWGroup, X name N') |
0 | 641 |
self.assertEqual(rset.rows, [['owners'], ['guests'], ['users'], ['managers']]) |
642 |
||
643 |
def test_select_or_value(self): |
|
644 |
rset = self.execute('Any U WHERE U in_group G, G name "owners" OR G name "users"') |
|
645 |
self.assertEqual(len(rset.rows), 0) |
|
646 |
rset = self.execute('Any U WHERE U in_group G, G name "guests" OR G name "managers"') |
|
647 |
self.assertEqual(len(rset.rows), 2) |
|
648 |
||
649 |
def test_select_explicit_eid(self): |
|
650 |
rset = self.execute('Any X,E WHERE X owned_by U, X eid E, U eid %(u)s', {'u': self.session.user.eid}) |
|
651 |
self.failUnless(rset) |
|
652 |
self.assertEquals(rset.description[0][1], 'Int') |
|
1787 | 653 |
|
0 | 654 |
# def test_select_rewritten_optional(self): |
655 |
# eid = self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
656 |
# rset = self.execute('Any X WHERE X eid %(x)s, EXISTS(X owned_by U) OR EXISTS(X concerne S?, S owned_by U)', |
|
657 |
# {'x': eid}, 'x') |
|
658 |
# self.assertEquals(rset.rows, [[eid]]) |
|
1787 | 659 |
|
0 | 660 |
def test_today_bug(self): |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
661 |
self.execute("INSERT Tag X: X name 'bidule', X creation_date NOW") |
0 | 662 |
self.execute("INSERT Tag Y: Y name 'toto'") |
663 |
rset = self.execute("Any D WHERE X name in ('bidule', 'toto') , X creation_date D") |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
664 |
self.assert_(isinstance(rset.rows[0][0], datetime), rset.rows) |
0 | 665 |
rset = self.execute('Tag X WHERE X creation_date TODAY') |
666 |
self.assertEqual(len(rset.rows), 2) |
|
667 |
rset = self.execute('Any MAX(D) WHERE X is Tag, X creation_date D') |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
668 |
self.failUnless(isinstance(rset[0][0], datetime), type(rset[0][0])) |
0 | 669 |
|
670 |
def test_today(self): |
|
671 |
self.execute("INSERT Tag X: X name 'bidule', X creation_date TODAY") |
|
672 |
self.execute("INSERT Tag Y: Y name 'toto'") |
|
673 |
rset = self.execute('Tag X WHERE X creation_date TODAY') |
|
674 |
self.assertEqual(len(rset.rows), 2) |
|
675 |
||
676 |
def test_select_boolean(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
677 |
rset = self.execute('Any N WHERE X is CWEType, X name N, X final %(val)s', |
0 | 678 |
{'val': True}) |
679 |
self.assertEquals(sorted(r[0] for r in rset.rows), ['Boolean', 'Bytes', |
|
680 |
'Date', 'Datetime', |
|
681 |
'Decimal', 'Float', |
|
682 |
'Int', 'Interval', |
|
683 |
'Password', 'String', |
|
684 |
'Time']) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
685 |
rset = self.execute('Any N WHERE X is CWEType, X name N, X final TRUE') |
0 | 686 |
self.assertEquals(sorted(r[0] for r in rset.rows), ['Boolean', 'Bytes', |
687 |
'Date', 'Datetime', |
|
688 |
'Decimal', 'Float', |
|
689 |
'Int', 'Interval', |
|
690 |
'Password', 'String', |
|
691 |
'Time']) |
|
1787 | 692 |
|
0 | 693 |
def test_select_constant(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
694 |
rset = self.execute('Any X, "toto" ORDERBY X WHERE X is CWGroup') |
0 | 695 |
self.assertEquals(rset.rows, |
696 |
map(list, zip((1,2,3,4), ('toto','toto','toto','toto',)))) |
|
697 |
self.assertIsInstance(rset[0][1], unicode) |
|
698 |
self.assertEquals(rset.description, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
699 |
zip(('CWGroup', 'CWGroup', 'CWGroup', 'CWGroup'), |
0 | 700 |
('String', 'String', 'String', 'String',))) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
701 |
rset = self.execute('Any X, %(value)s ORDERBY X WHERE X is CWGroup', {'value': 'toto'}) |
0 | 702 |
self.assertEquals(rset.rows, |
703 |
map(list, zip((1,2,3,4), ('toto','toto','toto','toto',)))) |
|
704 |
self.assertIsInstance(rset[0][1], unicode) |
|
705 |
self.assertEquals(rset.description, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
706 |
zip(('CWGroup', 'CWGroup', 'CWGroup', 'CWGroup'), |
0 | 707 |
('String', 'String', 'String', 'String',))) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
708 |
rset = self.execute('Any X,GN WHERE X is CWUser, G is CWGroup, X login "syt", X in_group G, G name GN') |
0 | 709 |
|
710 |
def test_select_union(self): |
|
711 |
rset = self.execute('Any X,N ORDERBY N WITH X,N BEING ' |
|
712 |
'((Any X,N WHERE X name N, X transition_of E, E name %(name)s)' |
|
713 |
' UNION ' |
|
714 |
'(Any X,N WHERE X name N, X state_of E, E name %(name)s))', |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
715 |
{'name': 'CWUser'}) |
0 | 716 |
self.assertEquals([x[1] for x in rset.rows], |
717 |
['activate', 'activated', 'deactivate', 'deactivated']) |
|
718 |
self.assertEquals(rset.description, |
|
719 |
[('Transition', 'String'), ('State', 'String'), |
|
720 |
('Transition', 'String'), ('State', 'String')]) |
|
1787 | 721 |
|
0 | 722 |
def test_select_union_aggregat(self): |
723 |
# meaningless, the goal in to have group by done on different attribute |
|
724 |
# for each sub-query |
|
725 |
self.execute('(Any N,COUNT(X) GROUPBY N WHERE X name N, X is State)' |
|
726 |
' UNION ' |
|
727 |
'(Any N,COUNT(X) GROUPBY N ORDERBY 2 WHERE X login N)') |
|
1787 | 728 |
|
0 | 729 |
def test_select_union_aggregat_independant_group(self): |
730 |
self.execute('INSERT State X: X name "hop"') |
|
731 |
self.execute('INSERT State X: X name "hop"') |
|
732 |
self.execute('INSERT Transition X: X name "hop"') |
|
733 |
self.execute('INSERT Transition X: X name "hop"') |
|
734 |
rset = self.execute('Any N,NX ORDERBY 2 WITH N,NX BEING ' |
|
735 |
'((Any N,COUNT(X) GROUPBY N WHERE X name N, X is State HAVING COUNT(X)>1)' |
|
736 |
' UNION ' |
|
737 |
'(Any N,COUNT(X) GROUPBY N WHERE X name N, X is Transition HAVING COUNT(X)>1))') |
|
738 |
self.assertEquals(rset.rows, [[u'hop', 2], [u'hop', 2]]) |
|
1787 | 739 |
|
0 | 740 |
def test_select_union_selection_with_diff_variables(self): |
741 |
rset = self.execute('(Any N WHERE X name N, X is State)' |
|
742 |
' UNION ' |
|
743 |
'(Any NN WHERE XX name NN, XX is Transition)') |
|
744 |
self.assertEquals(sorted(r[0] for r in rset.rows), |
|
745 |
['abort', 'activate', 'activated', 'ben non', |
|
746 |
'deactivate', 'deactivated', 'done', 'en cours', |
|
747 |
'end', 'finie', 'markasdone', 'pitetre', 'redoit', |
|
748 |
'start', 'todo']) |
|
1787 | 749 |
|
0 | 750 |
def test_exists(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
751 |
geid = self.execute("INSERT CWGroup X: X name 'lulufanclub'")[0][0] |
0 | 752 |
self.execute("SET U in_group G WHERE G name 'lulufanclub'") |
753 |
peid = self.execute("INSERT Personne X: X prenom 'lulu', X nom 'petit'")[0][0] |
|
754 |
rset = self.execute("Any X WHERE X prenom 'lulu'," |
|
755 |
"EXISTS (U in_group G, G name 'lulufanclub' OR G name 'managers');") |
|
756 |
self.assertEquals(rset.rows, [[peid]]) |
|
757 |
||
758 |
def test_identity(self): |
|
759 |
eid = self.execute('Any X WHERE X identity Y, Y eid 1')[0][0] |
|
760 |
self.assertEquals(eid, 1) |
|
761 |
eid = self.execute('Any X WHERE Y identity X, Y eid 1')[0][0] |
|
762 |
self.assertEquals(eid, 1) |
|
763 |
login = self.execute('Any L WHERE X login "admin", X identity Y, Y login L')[0][0] |
|
764 |
self.assertEquals(login, 'admin') |
|
765 |
||
766 |
def test_select_date_mathexp(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
767 |
rset = self.execute('Any X, TODAY - CD WHERE X is CWUser, X creation_date CD') |
0 | 768 |
self.failUnless(rset) |
769 |
self.failUnlessEqual(rset.description[0][1], 'Interval') |
|
770 |
eid, = self.execute("INSERT Personne X: X nom 'bidule'")[0] |
|
771 |
rset = self.execute('Any X, NOW - CD WHERE X is Personne, X creation_date CD') |
|
772 |
self.failUnlessEqual(rset.description[0][1], 'Interval') |
|
773 |
||
774 |
def test_select_subquery_aggregat(self): |
|
775 |
# percent users by groups |
|
776 |
self.execute('SET X in_group G WHERE G name "users"') |
|
777 |
rset = self.execute('Any GN, COUNT(X)*100/T GROUPBY GN ORDERBY 2,1' |
|
778 |
' WHERE G name GN, X in_group G' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
779 |
' WITH T BEING (Any COUNT(U) WHERE U is CWUser)') |
0 | 780 |
self.assertEquals(rset.rows, [[u'guests', 50], [u'managers', 50], [u'users', 100]]) |
781 |
self.assertEquals(rset.description, [('String', 'Int'), ('String', 'Int'), ('String', 'Int')]) |
|
782 |
||
783 |
def test_select_subquery_const(self): |
|
784 |
rset = self.execute('Any X WITH X BEING ((Any NULL) UNION (Any "toto"))') |
|
785 |
self.assertEquals(rset.rows, [[None], ['toto']]) |
|
786 |
self.assertEquals(rset.description, [(None,), ('String',)]) |
|
1787 | 787 |
|
0 | 788 |
# insertion queries tests ################################################# |
1787 | 789 |
|
0 | 790 |
def test_insert_is(self): |
791 |
eid, = self.execute("INSERT Personne X: X nom 'bidule'")[0] |
|
792 |
etype, = self.execute("Any TN WHERE X is T, X eid %s, T name TN" % eid)[0] |
|
793 |
self.assertEquals(etype, 'Personne') |
|
794 |
self.execute("INSERT Personne X: X nom 'managers'") |
|
1787 | 795 |
|
0 | 796 |
def test_insert_1(self): |
797 |
rset = self.execute("INSERT Personne X: X nom 'bidule'") |
|
798 |
self.assertEquals(len(rset.rows), 1) |
|
799 |
self.assertEquals(rset.description, [('Personne',)]) |
|
800 |
rset = self.execute('Personne X WHERE X nom "bidule"') |
|
801 |
self.assert_(rset.rows) |
|
802 |
self.assertEquals(rset.description, [('Personne',)]) |
|
803 |
||
804 |
def test_insert_1_multiple(self): |
|
805 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
806 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
807 |
rset = self.execute("INSERT Societe Y: Y nom N, P travaille Y WHERE P nom N") |
|
808 |
self.assertEquals(len(rset.rows), 2) |
|
809 |
self.assertEquals(rset.description, [('Societe',), ('Societe',)]) |
|
810 |
||
811 |
def test_insert_2(self): |
|
812 |
rset = self.execute("INSERT Personne X, Personne Y: X nom 'bidule', Y nom 'tutu'") |
|
813 |
self.assertEquals(rset.description, [('Personne', 'Personne')]) |
|
814 |
rset = self.execute('Personne X WHERE X nom "bidule" or X nom "tutu"') |
|
815 |
self.assert_(rset.rows) |
|
816 |
self.assertEquals(rset.description, [('Personne',), ('Personne',)]) |
|
817 |
||
818 |
def test_insert_3(self): |
|
819 |
self.execute("INSERT Personne X: X nom Y WHERE U login 'admin', U login Y") |
|
820 |
rset = self.execute('Personne X WHERE X nom "admin"') |
|
821 |
self.assert_(rset.rows) |
|
1787 | 822 |
self.assertEquals(rset.description, [('Personne',)]) |
0 | 823 |
|
824 |
def test_insert_4(self): |
|
825 |
self.execute("INSERT Societe Y: Y nom 'toto'") |
|
826 |
self.execute("INSERT Personne X: X nom 'bidule', X travaille Y WHERE Y nom 'toto'") |
|
827 |
rset = self.execute('Any X, Y WHERE X nom "bidule", Y nom "toto", X travaille Y') |
|
828 |
self.assert_(rset.rows) |
|
829 |
self.assertEquals(rset.description, [('Personne', 'Societe',)]) |
|
1787 | 830 |
|
0 | 831 |
def test_insert_4bis(self): |
832 |
peid = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
833 |
seid = self.execute("INSERT Societe Y: Y nom 'toto', X travaille Y WHERE X eid %(x)s", |
|
834 |
{'x': str(peid)})[0][0] |
|
835 |
self.assertEqual(len(self.execute('Any X, Y WHERE X travaille Y')), 1) |
|
836 |
self.execute("INSERT Personne X: X nom 'chouette', X travaille Y WHERE Y eid %(x)s", |
|
837 |
{'x': str(seid)}) |
|
838 |
self.assertEqual(len(self.execute('Any X, Y WHERE X travaille Y')), 2) |
|
1787 | 839 |
|
0 | 840 |
def test_insert_4ter(self): |
841 |
peid = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
842 |
seid = self.execute("INSERT Societe Y: Y nom 'toto', X travaille Y WHERE X eid %(x)s", |
|
843 |
{'x': unicode(peid)})[0][0] |
|
844 |
self.assertEqual(len(self.execute('Any X, Y WHERE X travaille Y')), 1) |
|
845 |
self.execute("INSERT Personne X: X nom 'chouette', X travaille Y WHERE Y eid %(x)s", |
|
846 |
{'x': unicode(seid)}) |
|
847 |
self.assertEqual(len(self.execute('Any X, Y WHERE X travaille Y')), 2) |
|
848 |
||
849 |
def test_insert_5(self): |
|
850 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
851 |
self.execute("INSERT Societe Y: Y nom 'toto', X travaille Y WHERE X nom 'bidule'") |
|
852 |
rset = self.execute('Any X, Y WHERE X nom "bidule", Y nom "toto", X travaille Y') |
|
853 |
self.assert_(rset.rows) |
|
854 |
self.assertEquals(rset.description, [('Personne', 'Societe',)]) |
|
855 |
||
856 |
def test_insert_6(self): |
|
857 |
self.execute("INSERT Personne X, Societe Y: X nom 'bidule', Y nom 'toto', X travaille Y") |
|
858 |
rset = self.execute('Any X, Y WHERE X nom "bidule", Y nom "toto", X travaille Y') |
|
859 |
self.assert_(rset.rows) |
|
860 |
self.assertEquals(rset.description, [('Personne', 'Societe',)]) |
|
861 |
||
862 |
def test_insert_7(self): |
|
863 |
self.execute("INSERT Personne X, Societe Y: X nom N, Y nom 'toto', X travaille Y WHERE U login 'admin', U login N") |
|
864 |
rset = self.execute('Any X, Y WHERE X nom "admin", Y nom "toto", X travaille Y') |
|
865 |
self.assert_(rset.rows) |
|
866 |
self.assertEquals(rset.description, [('Personne', 'Societe',)]) |
|
867 |
||
868 |
def test_insert_8(self): |
|
869 |
self.execute("INSERT Societe Y, Personne X: Y nom N, X nom 'toto', X travaille Y WHERE U login 'admin', U login N") |
|
870 |
rset = self.execute('Any X, Y WHERE X nom "toto", Y nom "admin", X travaille Y') |
|
871 |
self.assert_(rset.rows) |
|
872 |
self.assertEquals(rset.description, [('Personne', 'Societe',)]) |
|
873 |
||
874 |
def test_insert_query_error(self): |
|
875 |
self.assertRaises(Exception, |
|
876 |
self.execute, |
|
877 |
"INSERT Personne X: X nom 'toto', X is Personne") |
|
878 |
self.assertRaises(Exception, |
|
879 |
self.execute, |
|
880 |
"INSERT Personne X: X nom 'toto', X is_instance_of Personne") |
|
881 |
self.assertRaises(QueryError, |
|
882 |
self.execute, |
|
883 |
"INSERT Personne X: X nom 'toto', X has_text 'tutu'") |
|
884 |
||
885 |
self.assertRaises(QueryError, |
|
886 |
self.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
887 |
"INSERT CWUser X: X login 'toto', X eid %s" % cnx.user(self.session).eid) |
0 | 888 |
|
889 |
def test_insertion_description_with_where(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
890 |
rset = self.execute('INSERT CWUser E, EmailAddress EM: E login "X", E upassword "X", ' |
0 | 891 |
'E primary_email EM, EM address "X", E in_group G ' |
892 |
'WHERE G name "managers"') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
893 |
self.assertEquals(list(rset.description[0]), ['CWUser', 'EmailAddress']) |
1787 | 894 |
|
0 | 895 |
# deletion queries tests ################################################## |
896 |
||
897 |
def test_delete_1(self): |
|
898 |
self.execute("INSERT Personne Y: Y nom 'toto'") |
|
899 |
rset = self.execute('Personne X WHERE X nom "toto"') |
|
900 |
self.assertEqual(len(rset.rows), 1) |
|
901 |
self.execute("DELETE Personne Y WHERE Y nom 'toto'") |
|
902 |
rset = self.execute('Personne X WHERE X nom "toto"') |
|
903 |
self.assertEqual(len(rset.rows), 0) |
|
1787 | 904 |
|
0 | 905 |
def test_delete_2(self): |
906 |
rset = self.execute("INSERT Personne X, Personne Y, Societe Z : X nom 'syt', Y nom 'adim', Z nom 'Logilab', X travaille Z, Y travaille Z") |
|
907 |
self.assertEquals(len(rset), 1) |
|
908 |
self.assertEquals(len(rset[0]), 3) |
|
909 |
self.assertEquals(rset.description[0], ('Personne', 'Personne', 'Societe')) |
|
910 |
self.assertEquals(self.execute('Any N WHERE X nom N, X eid %s'% rset[0][0])[0][0], 'syt') |
|
911 |
rset = self.execute('Personne X WHERE X travaille Y, Y nom "Logilab"') |
|
912 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
|
913 |
self.execute("DELETE X travaille Y WHERE X is Personne, Y nom 'Logilabo'") |
|
914 |
rset = self.execute('Personne X WHERE X travaille Y, Y nom "Logilab"') |
|
915 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
|
916 |
self.execute("DELETE X travaille Y WHERE X is Personne, Y nom 'Logilab'") |
|
917 |
rset = self.execute('Personne X WHERE X travaille Y, Y nom "Logilab"') |
|
918 |
self.assertEqual(len(rset.rows), 0, rset.rows) |
|
919 |
||
920 |
def test_delete_3(self): |
|
921 |
u, s = self._user_session(('users',)) |
|
922 |
peid, = self.o.execute(s, "INSERT Personne P: P nom 'toto'")[0] |
|
923 |
seid, = self.o.execute(s, "INSERT Societe S: S nom 'logilab'")[0] |
|
924 |
self.o.execute(s, "SET P travaille S") |
|
925 |
rset = self.execute('Personne P WHERE P travaille S') |
|
926 |
self.assertEqual(len(rset.rows), 1) |
|
927 |
self.execute("DELETE X travaille Y WHERE X eid %s, Y eid %s" % (peid, seid)) |
|
928 |
rset = self.execute('Personne P WHERE P travaille S') |
|
929 |
self.assertEqual(len(rset.rows), 0) |
|
930 |
||
931 |
def test_delete_symetric(self): |
|
932 |
teid1 = self.execute("INSERT Folder T: T name 'toto'")[0][0] |
|
933 |
teid2 = self.execute("INSERT Folder T: T name 'tutu'")[0][0] |
|
934 |
self.execute('SET X see_also Y WHERE X eid %s, Y eid %s' % (teid1, teid2)) |
|
935 |
rset = self.execute('Any X,Y WHERE X see_also Y') |
|
936 |
self.assertEquals(len(rset) , 2, rset.rows) |
|
937 |
self.execute('DELETE X see_also Y WHERE X eid %s, Y eid %s' % (teid1, teid2)) |
|
938 |
rset = self.execute('Any X,Y WHERE X see_also Y') |
|
939 |
self.assertEquals(len(rset) , 0) |
|
940 |
self.execute('SET X see_also Y WHERE X eid %s, Y eid %s' % (teid1, teid2)) |
|
941 |
rset = self.execute('Any X,Y WHERE X see_also Y') |
|
942 |
self.assertEquals(len(rset) , 2) |
|
943 |
self.execute('DELETE X see_also Y WHERE X eid %s, Y eid %s' % (teid2, teid1)) |
|
944 |
rset = self.execute('Any X,Y WHERE X see_also Y') |
|
945 |
self.assertEquals(len(rset) , 0) |
|
946 |
||
947 |
def test_nonregr_delete_cache(self): |
|
948 |
"""test that relations are properly cleaned when an entity is deleted |
|
949 |
(using cachekey on sql generation returned always the same query for an eid, |
|
950 |
whatever the relation) |
|
951 |
""" |
|
952 |
u, s = self._user_session(('users',)) |
|
953 |
aeid, = self.o.execute(s, 'INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')[0] |
|
954 |
# XXX would be nice if the rql below was enough... |
|
955 |
#'INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y' |
|
956 |
eeid, = self.o.execute(s, 'INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y WHERE Y is EmailAddress')[0] |
|
957 |
self.o.execute(s, "DELETE Email X") |
|
958 |
sqlc = s.pool['system'] |
|
959 |
sqlc.execute('SELECT * FROM recipients_relation') |
|
960 |
self.assertEquals(len(sqlc.fetchall()), 0) |
|
961 |
sqlc.execute('SELECT * FROM owned_by_relation WHERE eid_from=%s'%eeid) |
|
962 |
self.assertEquals(len(sqlc.fetchall()), 0) |
|
1787 | 963 |
|
0 | 964 |
def test_nonregr_delete_cache2(self): |
965 |
eid = self.execute("INSERT Folder T: T name 'toto'")[0][0] |
|
966 |
self.commit() |
|
967 |
# fill the cache |
|
968 |
self.execute("Any X WHERE X eid %(x)s", {'x': eid}, 'x') |
|
969 |
self.execute("Any X WHERE X eid %s" %eid) |
|
970 |
self.execute("Folder X WHERE X eid %(x)s", {'x': eid}, 'x') |
|
971 |
self.execute("Folder X WHERE X eid %s" %eid) |
|
972 |
self.execute("DELETE Folder T WHERE T eid %s"%eid) |
|
973 |
self.commit() |
|
974 |
rset = self.execute("Any X WHERE X eid %(x)s", {'x': eid}, 'x') |
|
975 |
self.assertEquals(rset.rows, []) |
|
976 |
rset = self.execute("Any X WHERE X eid %s" %eid) |
|
977 |
self.assertEquals(rset.rows, []) |
|
978 |
rset = self.execute("Folder X WHERE X eid %(x)s", {'x': eid}, 'x') |
|
979 |
self.assertEquals(rset.rows, []) |
|
980 |
rset = self.execute("Folder X WHERE X eid %s" %eid) |
|
981 |
self.assertEquals(rset.rows, []) |
|
1787 | 982 |
|
0 | 983 |
# update queries tests #################################################### |
984 |
||
985 |
def test_update_1(self): |
|
986 |
self.execute("INSERT Personne Y: Y nom 'toto'") |
|
987 |
rset = self.execute('Personne X WHERE X nom "toto"') |
|
988 |
self.assertEqual(len(rset.rows), 1) |
|
989 |
self.execute("SET X nom 'tutu', X prenom 'original' WHERE X is Personne, X nom 'toto'") |
|
990 |
rset = self.execute('Any Y, Z WHERE X is Personne, X nom Y, X prenom Z') |
|
991 |
self.assertEqual(tuplify(rset.rows), [('tutu', 'original')]) |
|
1787 | 992 |
|
0 | 993 |
def test_update_2(self): |
994 |
self.execute("INSERT Personne X, Societe Y: X nom 'bidule', Y nom 'toto'") |
|
995 |
#rset = self.execute('Any X, Y WHERE X nom "bidule", Y nom "toto"') |
|
996 |
#self.assertEqual(len(rset.rows), 1) |
|
997 |
#rset = self.execute('Any X, Y WHERE X travaille Y') |
|
998 |
#self.assertEqual(len(rset.rows), 0) |
|
999 |
self.execute("SET X travaille Y WHERE X nom 'bidule', Y nom 'toto'") |
|
1000 |
rset = self.execute('Any X, Y WHERE X travaille Y') |
|
1001 |
self.assertEqual(len(rset.rows), 1) |
|
1787 | 1002 |
|
0 | 1003 |
def test_update_2bis(self): |
1004 |
rset = self.execute("INSERT Personne X, Societe Y: X nom 'bidule', Y nom 'toto'") |
|
1005 |
eid1, eid2 = rset[0][0], rset[0][1] |
|
1006 |
self.execute("SET X travaille Y WHERE X eid %(x)s, Y eid %(y)s", |
|
1007 |
{'x': str(eid1), 'y': str(eid2)}) |
|
1008 |
rset = self.execute('Any X, Y WHERE X travaille Y') |
|
1009 |
self.assertEqual(len(rset.rows), 1) |
|
1787 | 1010 |
|
0 | 1011 |
def test_update_2ter(self): |
1012 |
rset = self.execute("INSERT Personne X, Societe Y: X nom 'bidule', Y nom 'toto'") |
|
1013 |
eid1, eid2 = rset[0][0], rset[0][1] |
|
1014 |
self.execute("SET X travaille Y WHERE X eid %(x)s, Y eid %(y)s", |
|
1015 |
{'x': unicode(eid1), 'y': unicode(eid2)}) |
|
1016 |
rset = self.execute('Any X, Y WHERE X travaille Y') |
|
1017 |
self.assertEqual(len(rset.rows), 1) |
|
1787 | 1018 |
|
0 | 1019 |
## def test_update_4(self): |
1020 |
## self.execute("SET X know Y WHERE X ami Y") |
|
1787 | 1021 |
|
0 | 1022 |
def test_update_multiple1(self): |
1023 |
peid1 = self.execute("INSERT Personne Y: Y nom 'tutu'")[0][0] |
|
1024 |
peid2 = self.execute("INSERT Personne Y: Y nom 'toto'")[0][0] |
|
1025 |
self.execute("SET X nom 'tutu', Y nom 'toto' WHERE X nom 'toto', Y nom 'tutu'") |
|
1026 |
self.assertEquals(self.execute('Any X WHERE X nom "toto"').rows, [[peid1]]) |
|
1027 |
self.assertEquals(self.execute('Any X WHERE X nom "tutu"').rows, [[peid2]]) |
|
1028 |
||
1029 |
def test_update_multiple2(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1030 |
ueid = self.execute("INSERT CWUser X: X login 'bob', X upassword 'toto'")[0][0] |
0 | 1031 |
peid1 = self.execute("INSERT Personne Y: Y nom 'turlu'")[0][0] |
1032 |
peid2 = self.execute("INSERT Personne Y: Y nom 'tutu'")[0][0] |
|
1033 |
self.execute('SET P1 owned_by U, P2 owned_by U ' |
|
1034 |
'WHERE P1 eid %s, P2 eid %s, U eid %s' % (peid1, peid2, ueid)) |
|
1035 |
self.failUnless(self.execute('Any X WHERE X eid %s, X owned_by U, U eid %s' |
|
1036 |
% (peid1, ueid))) |
|
1037 |
self.failUnless(self.execute('Any X WHERE X eid %s, X owned_by U, U eid %s' |
|
1038 |
% (peid2, ueid))) |
|
1039 |
||
1040 |
def test_update_math_expr(self): |
|
1041 |
orders = [r[0] for r in self.execute('Any O ORDERBY O WHERE ST name "Personne", X from_entity ST, X ordernum O')] |
|
1042 |
for i,v in enumerate(orders): |
|
1043 |
if v != orders[0]: |
|
1044 |
splitidx = i |
|
1045 |
break |
|
1046 |
self.execute('SET X ordernum Y+1 WHERE X from_entity SE, SE name "Personne", X ordernum Y, X ordernum >= %(order)s', |
|
1047 |
{'order': orders[splitidx]}) |
|
1048 |
orders2 = [r[0] for r in self.execute('Any O ORDERBY O WHERE ST name "Personne", X from_entity ST, X ordernum O')] |
|
1049 |
orders = orders[:splitidx] + [o+1 for o in orders[splitidx:]] |
|
1050 |
self.assertEquals(orders2, orders) |
|
1051 |
||
1052 |
def test_update_string_concat(self): |
|
1053 |
beid = self.execute("INSERT Bookmark Y: Y title 'toto', Y path '/view'")[0][0] |
|
1054 |
self.execute('SET X title XN + %(suffix)s WHERE X is Bookmark, X title XN', {'suffix': u'-moved'}) |
|
1055 |
newname = self.execute('Any XN WHERE X eid %(x)s, X title XN', {'x': beid}, 'x')[0][0] |
|
1056 |
self.assertEquals(newname, 'toto-moved') |
|
1787 | 1057 |
|
0 | 1058 |
def test_update_query_error(self): |
1059 |
self.execute("INSERT Personne Y: Y nom 'toto'") |
|
1060 |
self.assertRaises(Exception, self.execute, "SET X nom 'toto', X is Personne") |
|
1061 |
self.assertRaises(QueryError, self.execute, "SET X nom 'toto', X has_text 'tutu' WHERE X is Personne") |
|
1062 |
self.assertRaises(QueryError, self.execute, "SET X login 'tutu', X eid %s" % cnx.user(self.session).eid) |
|
1063 |
||
1787 | 1064 |
|
0 | 1065 |
# upassword encryption tests ################################################# |
1787 | 1066 |
|
0 | 1067 |
def test_insert_upassword(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1068 |
rset = self.execute("INSERT CWUser X: X login 'bob', X upassword 'toto'") |
0 | 1069 |
self.assertEquals(len(rset.rows), 1) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1070 |
self.assertEquals(rset.description, [('CWUser',)]) |
0 | 1071 |
self.assertRaises(Unauthorized, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1072 |
self.execute, "Any P WHERE X is CWUser, X login 'bob', X upassword P") |
0 | 1073 |
cursor = self.pool['system'] |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1074 |
cursor.execute("SELECT %supassword from %sCWUser WHERE %slogin='bob'" |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
1075 |
% (SQL_PREFIX, SQL_PREFIX, SQL_PREFIX)) |
0 | 1076 |
passwd = cursor.fetchone()[0].getvalue() |
1787 | 1077 |
self.assertEquals(passwd, crypt_password('toto', passwd[:2])) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1078 |
rset = self.execute("Any X WHERE X is CWUser, X login 'bob', X upassword '%s'" % passwd) |
0 | 1079 |
self.assertEquals(len(rset.rows), 1) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1080 |
self.assertEquals(rset.description, [('CWUser',)]) |
1787 | 1081 |
|
0 | 1082 |
def test_update_upassword(self): |
1083 |
cursor = self.pool['system'] |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1084 |
rset = self.execute("INSERT CWUser X: X login 'bob', X upassword %(pwd)s", {'pwd': 'toto'}) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1085 |
self.assertEquals(rset.description[0][0], 'CWUser') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1086 |
rset = self.execute("SET X upassword %(pwd)s WHERE X is CWUser, X login 'bob'", |
0 | 1087 |
{'pwd': 'tutu'}) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1088 |
cursor.execute("SELECT %supassword from %sCWUser WHERE %slogin='bob'" |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
1089 |
% (SQL_PREFIX, SQL_PREFIX, SQL_PREFIX)) |
0 | 1090 |
passwd = cursor.fetchone()[0].getvalue() |
1787 | 1091 |
self.assertEquals(passwd, crypt_password('tutu', passwd[:2])) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1092 |
rset = self.execute("Any X WHERE X is CWUser, X login 'bob', X upassword '%s'" % passwd) |
0 | 1093 |
self.assertEquals(len(rset.rows), 1) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1094 |
self.assertEquals(rset.description, [('CWUser',)]) |
0 | 1095 |
|
1096 |
# non regression tests #################################################### |
|
1787 | 1097 |
|
0 | 1098 |
def test_nonregr_1(self): |
1099 |
teid = self.execute("INSERT Tag X: X name 'tag'")[0][0] |
|
1100 |
self.execute("SET X tags Y WHERE X name 'tag', Y is State, Y name 'activated'") |
|
1101 |
rset = self.execute('Any X WHERE T tags X') |
|
1102 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
1103 |
rset = self.execute('Any T WHERE T tags X, X is State') |
|
1104 |
self.assertEquals(rset.rows, [[teid]]) |
|
1105 |
rset = self.execute('Any T WHERE T tags X') |
|
1106 |
self.assertEquals(rset.rows, [[teid]]) |
|
1107 |
||
1108 |
def test_nonregr_2(self): |
|
1109 |
teid = self.execute("INSERT Tag X: X name 'tag'")[0][0] |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1110 |
geid = self.execute("CWGroup G WHERE G name 'users'")[0][0] |
0 | 1111 |
self.execute("SET X tags Y WHERE X eid %(t)s, Y eid %(g)s", |
1112 |
{'g': geid, 't': teid}) |
|
1113 |
rset = self.execute('Any X WHERE E eid %(x)s, E tags X', |
|
1114 |
{'x': teid}) |
|
1115 |
self.assertEquals(rset.rows, [[geid]]) |
|
1787 | 1116 |
|
0 | 1117 |
def test_nonregr_3(self): |
1118 |
"""bad sql generated on the second query (destination_state is not |
|
1119 |
detected as an inlined relation) |
|
1120 |
""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1121 |
rset = self.execute('Any S,ES,T WHERE S state_of ET, ET name "CWUser",' |
0 | 1122 |
'ES allowed_transition T, T destination_state S') |
1123 |
self.assertEquals(len(rset.rows), 2) |
|
1124 |
||
1125 |
def test_nonregr_4(self): |
|
1126 |
# fix variables'type, else we get (nb of entity types with a 'name' attribute)**3 |
|
1127 |
# union queries and that make for instance a 266Ko sql query which is refused |
|
1128 |
# by the server (or client lib) |
|
1129 |
rset = self.execute('Any ER,SE,OE WHERE SE name "Comment", ER name "comments", OE name "Comment",' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1130 |
'ER is CWRType, SE is CWEType, OE is CWEType') |
0 | 1131 |
self.assertEquals(len(rset), 1) |
1132 |
||
1133 |
def test_nonregr_5(self): |
|
1134 |
# jpl #15505: equivalent queries returning different result sets |
|
1135 |
teid1 = self.execute("INSERT Folder X: X name 'hop'")[0][0] |
|
1136 |
teid2 = self.execute("INSERT Folder X: X name 'hip'")[0][0] |
|
1137 |
neid = self.execute("INSERT Note X: X todo_by U, X filed_under T WHERE U login 'admin', T name 'hop'")[0][0] |
|
1138 |
weid = self.execute("INSERT Affaire X: X concerne N, X filed_under T WHERE N is Note, T name 'hip'")[0][0] |
|
1139 |
rset1 = self.execute('Any N,U WHERE N filed_under T, T eid %s,' |
|
1140 |
'N todo_by U, W concerne N,' |
|
1141 |
'W is Affaire, W filed_under A, A eid %s' % (teid1, teid2)) |
|
1142 |
rset2 = self.execute('Any N,U WHERE N filed_under T, T eid %s,' |
|
1143 |
'N todo_by U, W concerne N,' |
|
1144 |
'W filed_under A, A eid %s' % (teid1, teid2)) |
|
1145 |
rset3 = self.execute('Any N,U WHERE N todo_by U, T eid %s,' |
|
1146 |
'N filed_under T, W concerne N,' |
|
1147 |
'W is Affaire, W filed_under A, A eid %s' % (teid1, teid2)) |
|
1148 |
rset4 = self.execute('Any N,U WHERE N todo_by U, T eid %s,' |
|
1149 |
'N filed_under T, W concerne N,' |
|
1150 |
'W filed_under A, A eid %s' % (teid1, teid2)) |
|
1151 |
self.assertEquals(rset1.rows, rset2.rows) |
|
1152 |
self.assertEquals(rset1.rows, rset3.rows) |
|
1153 |
self.assertEquals(rset1.rows, rset4.rows) |
|
1787 | 1154 |
|
0 | 1155 |
def test_nonregr_6(self): |
1156 |
self.execute('Any N,COUNT(S) GROUPBY N ORDERBY COUNT(N) WHERE S name N, S is State') |
|
1787 | 1157 |
|
0 | 1158 |
def test_sqlite_encoding(self): |
1159 |
"""XXX this test was trying to show a bug on use of lower which only |
|
1160 |
occurs with non ascii string and misconfigured locale |
|
1161 |
""" |
|
1162 |
self.execute("INSERT Tag X: X name %(name)s," |
|
1163 |
"X modification_date %(modification_date)s," |
|
1164 |
"X creation_date %(creation_date)s", |
|
1165 |
{'name': u'�name0', |
|
1166 |
'modification_date': '2003/03/12 11:00', |
|
1167 |
'creation_date': '2000/07/03 11:00'}) |
|
1168 |
rset = self.execute('Any lower(N) ORDERBY LOWER(N) WHERE X is Tag, X name N,' |
|
1169 |
'X owned_by U, U eid %(x)s', |
|
1170 |
{'x':self.session.user.eid}, 'x') |
|
1171 |
self.assertEquals(rset.rows, [[u'\xe9name0']]) |
|
1172 |
||
1173 |
||
1174 |
def test_nonregr_description(self): |
|
1175 |
"""check that a correct description is built in case where infered |
|
1176 |
solutions may be "fusionned" into one by the querier while all solutions |
|
1177 |
are needed to build the result's description |
|
1178 |
""" |
|
1179 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
1180 |
self.execute("INSERT Societe Y: Y nom 'toto'") |
|
1181 |
beid = self.execute("INSERT Basket B: B name 'mybasket'")[0][0] |
|
1182 |
self.execute("SET X in_basket B WHERE X is Personne") |
|
1183 |
self.execute("SET X in_basket B WHERE X is Societe") |
|
1184 |
rset = self.execute('Any X WHERE X in_basket B, B eid %s' % beid) |
|
1185 |
self.assertEquals(len(rset), 2) |
|
1186 |
self.assertEquals(rset.description, [('Personne',), ('Societe',)]) |
|
1187 |
||
1188 |
||
1189 |
def test_nonregr_cache_1(self): |
|
1190 |
peid = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
1191 |
beid = self.execute("INSERT Basket X: X name 'tag'")[0][0] |
|
1192 |
self.execute("SET X in_basket Y WHERE X is Personne, Y eid %(y)s", |
|
1193 |
{'y': beid}) |
|
1194 |
rset = self.execute("Any X WHERE X in_basket B, B eid %(x)s", |
|
1195 |
{'x': beid}) |
|
1196 |
self.assertEquals(rset.rows, [[peid]]) |
|
1197 |
rset = self.execute("Any X WHERE X in_basket B, B eid %(x)s", |
|
1198 |
{'x': beid}) |
|
1199 |
self.assertEquals(rset.rows, [[peid]]) |
|
1200 |
||
1201 |
def test_nonregr_has_text_cache(self): |
|
1202 |
eid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
1203 |
eid2 = self.execute("INSERT Personne X: X nom 'tag'")[0][0] |
|
1204 |
self.commit() |
|
1205 |
rset = self.execute("Any X WHERE X has_text %(text)s", {'text': 'bidule'}) |
|
1206 |
self.assertEquals(rset.rows, [[eid1]]) |
|
1207 |
rset = self.execute("Any X WHERE X has_text %(text)s", {'text': 'tag'}) |
|
1208 |
self.assertEquals(rset.rows, [[eid2]]) |
|
1209 |
||
1210 |
def test_nonregr_sortterm_management(self): |
|
1211 |
"""Error: Variable has no attribute 'sql' in rql2sql.py (visit_variable) |
|
1212 |
||
1213 |
cause: old variable ref inserted into a fresh rqlst copy |
|
1214 |
(in RQLSpliter._complex_select_plan) |
|
1215 |
""" |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
1216 |
self.skip('retry me once http://www.sqlite.org/cvstrac/tktview?tn=3773 is fixed') |
0 | 1217 |
self.execute('Any X ORDERBY D DESC WHERE X creation_date D') |
1787 | 1218 |
|
0 | 1219 |
def test_nonregr_extra_joins(self): |
1220 |
ueid = self.session.user.eid |
|
1221 |
teid1 = self.execute("INSERT Folder X: X name 'folder1'")[0][0] |
|
1222 |
teid2 = self.execute("INSERT Folder X: X name 'folder2'")[0][0] |
|
1223 |
neid1 = self.execute("INSERT Note X: X para 'note1'")[0][0] |
|
1224 |
neid2 = self.execute("INSERT Note X: X para 'note2'")[0][0] |
|
1225 |
self.execute("SET X filed_under Y WHERE X eid %s, Y eid %s" |
|
1226 |
% (neid1, teid1)) |
|
1227 |
self.execute("SET X filed_under Y WHERE X eid %s, Y eid %s" |
|
1228 |
% (neid2, teid2)) |
|
1229 |
self.execute("SET X todo_by Y WHERE X is Note, Y eid %s" % ueid) |
|
1230 |
rset = self.execute('Any N WHERE N todo_by U, N is Note, U eid %s, N filed_under T, T eid %s' |
|
1231 |
% (ueid, teid1)) |
|
1232 |
self.assertEquals(len(rset), 1) |
|
1233 |
||
1234 |
def test_nonregr_XXX(self): |
|
1235 |
teid = self.execute('Transition S WHERE S name "deactivate"')[0][0] |
|
1236 |
rset = self.execute('Any O WHERE O is State, ' |
|
1237 |
'S eid %(x)s, S transition_of ET, O state_of ET', {'x': teid}) |
|
1238 |
self.assertEquals(len(rset), 2) |
|
1239 |
rset = self.execute('Any O WHERE O is State, NOT S destination_state O, ' |
|
1240 |
'S eid %(x)s, S transition_of ET, O state_of ET', {'x': teid}) |
|
1241 |
self.assertEquals(len(rset), 1) |
|
1242 |
||
1243 |
||
1244 |
def test_nonregr_set_datetime(self): |
|
1245 |
# huum, psycopg specific |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
1246 |
self.execute('SET X creation_date %(date)s WHERE X eid 1', {'date': date.today()}) |
0 | 1247 |
|
1248 |
def test_nonregr_set_query(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1249 |
ueid = self.execute("INSERT CWUser X: X login 'bob', X upassword 'toto'")[0][0] |
0 | 1250 |
self.execute("SET E in_group G, E in_state S, " |
1251 |
"E firstname %(firstname)s, E surname %(surname)s " |
|
1252 |
"WHERE E eid %(x)s, G name 'users', S name 'activated'", |
|
1253 |
{'x':ueid, 'firstname': u'jean', 'surname': u'paul'}, 'x') |
|
1787 | 1254 |
|
0 | 1255 |
def test_nonregr_u_owned_by_u(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1256 |
ueid = self.execute("INSERT CWUser X: X login 'bob', X upassword 'toto', X in_group G " |
0 | 1257 |
"WHERE G name 'users'")[0][0] |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1258 |
rset = self.execute("CWUser U") |
0 | 1259 |
self.assertEquals(len(rset), 3) # bob + admin + anon |
1260 |
rset = self.execute("Any U WHERE NOT U owned_by U") |
|
1261 |
self.assertEquals(len(rset), 0) # even admin created at repo initialization time should belong to itself |
|
1262 |
||
1263 |
def test_nonreg_update_index(self): |
|
1264 |
# this is the kind of queries generated by "cubicweb-ctl db-check -ry" |
|
1265 |
self.execute("SET X description D WHERE X is State, X description D") |
|
1266 |
||
1267 |
def test_nonregr_is(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1268 |
uteid = self.execute('Any ET WHERE ET name "CWUser"')[0][0] |
0 | 1269 |
self.execute('Any X, ET WHERE X is ET, ET eid %s' % uteid) |
1270 |
||
1271 |
def test_nonregr_orderby(self): |
|
1272 |
seid = self.execute('Any X WHERE X name "activated"')[0][0] |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1273 |
self.execute('Any X,S, MAX(T) GROUPBY X,S ORDERBY S WHERE X is CWUser, T tags X, S eid IN(%s), X in_state S' % seid) |
0 | 1274 |
|
1275 |
def test_nonregr_solution_cache(self): |
|
1276 |
self.skip('XXX should be fixed or documented') # (doesn't occur if cache key is provided.) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1277 |
rset = self.execute('Any X WHERE X is CWUser, X eid %(x)s', {'x':self.ueid}) |
0 | 1278 |
self.assertEquals(len(rset), 1) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1279 |
rset = self.execute('Any X WHERE X is CWUser, X eid %(x)s', {'x':12345}) |
0 | 1280 |
self.assertEquals(len(rset), 0) |
1281 |
||
1282 |
def test_nonregr_final_norestr(self): |
|
1283 |
self.assertRaises(BadRQLQuery, self.execute, 'Date X') |
|
1284 |
||
1285 |
||
1286 |
if __name__ == '__main__': |
|
1287 |
unittest_main() |