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