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