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