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