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