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