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