author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Mon, 27 Feb 2012 17:02:31 +0100 | |
changeset 8298 | 2a4bc6f75e9c |
parent 8222 | 2a92f0ec881d |
child 8349 | fdb796435d7b |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
7043
686010f3a83e
some copyrigh updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
2 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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/>. |
6196 | 19 |
"""unit tests for modules cubicweb.server.querier and cubicweb.server.ssplanner |
0 | 20 |
""" |
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
21 |
from datetime import date, datetime, timedelta, tzinfo |
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 |
|
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7043
diff
changeset
|
30 |
from cubicweb.devtools import get_test_db_handler, TestServerConfiguration |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7043
diff
changeset
|
31 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
32 |
from cubicweb.devtools.repotest import tuplify, BaseQuerierTC |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
33 |
from unittest_session import Variable |
0 | 34 |
|
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
35 |
class FixedOffset(tzinfo): |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
36 |
def __init__(self, hours=0): |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
37 |
self.hours = hours |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
38 |
def utcoffset(self, dt): |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
39 |
return timedelta(hours=self.hours) |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
40 |
def dst(self, dt): |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
41 |
return timedelta(0) |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
42 |
|
0 | 43 |
|
44 |
# register priority/severity sorting registered procedure |
|
45 |
from rql.utils import register_function, FunctionDescr |
|
46 |
||
47 |
class group_sort_value(FunctionDescr): |
|
48 |
supported_backends = ('sqlite',) |
|
49 |
rtype = 'Int' |
|
50 |
try: |
|
51 |
register_function(group_sort_value) |
|
52 |
except AssertionError: |
|
53 |
pass |
|
54 |
from cubicweb.server.sqlutils import SQL_CONNECT_HOOKS |
|
55 |
def init_sqlite_connexion(cnx): |
|
56 |
def group_sort_value(text): |
|
57 |
return {"managers": "3", "users": "2", "guests": "1", "owners": "0"}[text] |
|
58 |
cnx.create_function("GROUP_SORT_VALUE", 1, group_sort_value) |
|
59 |
SQL_CONNECT_HOOKS['sqlite'].append(init_sqlite_connexion) |
|
60 |
||
61 |
||
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
diff
changeset
|
62 |
from logilab.database import _GenericAdvFuncHelper |
0 | 63 |
TYPEMAP = _GenericAdvFuncHelper.TYPE_MAPPING |
64 |
||
65 |
class MakeSchemaTC(TestCase): |
|
66 |
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
|
67 |
solution = {'A': 'String', 'B': 'CWUser'} |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
68 |
self.assertEqual(make_schema((Variable('A'), Variable('B')), solution, |
0 | 69 |
'table0', TYPEMAP), |
70 |
('C0 text,C1 integer', {'A': 'table0.C0', 'B': 'table0.C1'})) |
|
1787 | 71 |
|
0 | 72 |
|
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6631
diff
changeset
|
73 |
def setUpModule(*args): |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
74 |
global repo, cnx |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7043
diff
changeset
|
75 |
config = TestServerConfiguration(apphome=UtilsTC.datadir) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7043
diff
changeset
|
76 |
handler = get_test_db_handler(config) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7043
diff
changeset
|
77 |
handler.build_db_cache() |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7043
diff
changeset
|
78 |
repo, cnx = handler.get_repo_and_cnx() |
0 | 79 |
|
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6631
diff
changeset
|
80 |
def tearDownModule(*args): |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
del repo, cnx |
0 | 85 |
|
86 |
||
87 |
class UtilsTC(BaseQuerierTC): |
|
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
88 |
def setUp(self): |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
89 |
self.__class__.repo = repo |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
90 |
super(UtilsTC, self).setUp() |
1787 | 91 |
|
0 | 92 |
def get_max_eid(self): |
93 |
# no need for cleanup here |
|
94 |
return None |
|
95 |
def cleanup(self): |
|
96 |
# no need for cleanup here |
|
97 |
pass |
|
1787 | 98 |
|
0 | 99 |
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
|
100 |
reid = self.execute('Any X WHERE X is CWRType, X name "owned_by"')[0][0] |
0 | 101 |
rqlst = self._prepare('Any COUNT(RDEF) WHERE RDEF relation_type X, X eid %(x)s', {'x': reid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
102 |
self.assertEqual(rqlst.solutions, [{'RDEF': 'CWAttribute'}, {'RDEF': 'CWRelation'}]) |
1787 | 103 |
|
0 | 104 |
def test_preprocess_2(self): |
105 |
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
|
106 |
#geid = self.execute("CWGroup G WHERE G name 'users'")[0][0] |
0 | 107 |
#self.execute("SET X tags Y WHERE X eid %(t)s, Y eid %(g)s", |
108 |
# {'g': geid, 't': teid}, 'g') |
|
109 |
rqlst = self._prepare('Any X WHERE E eid %(x)s, E tags X', {'x': teid}) |
|
110 |
# the query may be optimized, should keep only one solution |
|
111 |
# (any one, etype will be discarded) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
112 |
self.assertEqual(len(rqlst.solutions), 1) |
1787 | 113 |
|
0 | 114 |
def test_preprocess_security(self): |
115 |
plan = self._prepare_plan('Any ETN,COUNT(X) GROUPBY ETN ' |
|
116 |
'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
|
117 |
plan.session = self.user_groups_session('users') |
0 | 118 |
union = plan.rqlst |
119 |
plan.preprocess(union) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
120 |
self.assertEqual(len(union.children), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
121 |
self.assertEqual(len(union.children[0].with_), 1) |
0 | 122 |
subq = union.children[0].with_[0].query |
8222
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
123 |
self.assertEqual(len(subq.children), 4) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
124 |
self.assertEqual([t.as_string() for t in union.children[0].selection], |
0 | 125 |
['ETN','COUNT(X)']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
126 |
self.assertEqual([t.as_string() for t in union.children[0].groupby], |
0 | 127 |
['ETN']) |
128 |
partrqls = sorted(((rqlst.as_string(), rqlst.solutions) for rqlst in subq.children)) |
|
129 |
rql, solutions = partrqls[0] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
130 |
self.assertEqual(rql, |
0 | 131 |
'Any ETN,X WHERE X is ET, ET name ETN, (EXISTS(X owned_by %(B)s))' |
132 |
' OR ((((EXISTS(D concerne C?, C owned_by %(B)s, X identity D, C is Division, D is Affaire))' |
|
133 |
' OR (EXISTS(H concerne G?, G owned_by %(B)s, G is SubDivision, X identity H, H is Affaire)))' |
|
134 |
' OR (EXISTS(I concerne F?, F owned_by %(B)s, F is Societe, X identity I, I is Affaire)))' |
|
135 |
' 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
|
136 |
', ET is CWEType, X is Affaire') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
137 |
self.assertEqual(solutions, [{'C': 'Division', |
0 | 138 |
'D': 'Affaire', |
139 |
'E': 'Note', |
|
140 |
'F': 'Societe', |
|
141 |
'G': 'SubDivision', |
|
142 |
'H': 'Affaire', |
|
143 |
'I': 'Affaire', |
|
144 |
'J': 'Affaire', |
|
145 |
'X': 'Affaire', |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
146 |
'ET': 'CWEType', 'ETN': 'String'}]) |
0 | 147 |
rql, solutions = partrqls[1] |
8222
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
148 |
self.assertEqual(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, CWSource, CWUniqueTogetherConstraint, CWUser, Card, Comment, Division, Email, EmailPart, EmailThread, ExternalUri, File, Folder, Note, Old, Personne, RQLExpression, Societe, State, SubDivision, SubWorkflowExitPoint, Tag, TrInfo, Transition, Workflow, WorkflowTransition)') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
149 |
self.assertListEqual(sorted(solutions), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
150 |
sorted([{'X': 'BaseTransition', 'ETN': 'String', 'ET': 'CWEType'}, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
151 |
{'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
|
152 |
{'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
|
153 |
{'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
|
154 |
{'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
|
155 |
{'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
|
156 |
{'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
|
157 |
{'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
|
158 |
{'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
|
159 |
{'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
|
160 |
{'X': 'CWGroup', 'ETN': 'String', 'ET': 'CWEType'}, |
6209 | 161 |
{'X': 'CWRelation', 'ETN': 'String', 'ET': 'CWEType'}, |
162 |
{'X': 'CWPermission', 'ETN': 'String', 'ET': 'CWEType'}, |
|
163 |
{'X': 'CWProperty', 'ETN': 'String', 'ET': 'CWEType'}, |
|
164 |
{'X': 'CWRType', 'ETN': 'String', 'ET': 'CWEType'}, |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
165 |
{'X': 'CWSource', 'ETN': 'String', 'ET': 'CWEType'}, |
6209 | 166 |
{'X': 'CWUniqueTogetherConstraint', 'ETN': 'String', 'ET': 'CWEType'}, |
167 |
{'X': 'CWUser', '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
|
168 |
{'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
|
169 |
{'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
|
170 |
{'X': 'EmailThread', '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
|
171 |
{'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
|
172 |
{'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
|
173 |
{'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
|
174 |
{'X': 'Note', 'ETN': 'String', 'ET': 'CWEType'}, |
8111
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
175 |
{'X': 'Old', '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
|
176 |
{'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
|
177 |
{'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
|
178 |
{'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
|
179 |
{'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
|
180 |
{'X': 'SubDivision', 'ETN': 'String', 'ET': 'CWEType'}, |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
181 |
{'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
|
182 |
{'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
|
183 |
{'X': 'Transition', 'ETN': 'String', 'ET': 'CWEType'}, |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
184 |
{'X': 'TrInfo', 'ETN': 'String', 'ET': 'CWEType'}, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
185 |
{'X': 'Workflow', 'ETN': 'String', 'ET': 'CWEType'}, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
186 |
{'X': 'WorkflowTransition', 'ETN': 'String', 'ET': 'CWEType'}])) |
0 | 187 |
rql, solutions = partrqls[2] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
188 |
self.assertEqual(rql, |
8222
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
189 |
'Any ETN,X WHERE X is ET, ET name ETN, EXISTS(%(D)s use_email X), ' |
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
190 |
'ET is CWEType, X is EmailAddress') |
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
191 |
self.assertEqual(solutions, [{'X': 'EmailAddress', 'ET': 'CWEType', 'ETN': 'String'}]) |
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
192 |
rql, solutions = partrqls[3] |
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
193 |
self.assertEqual(rql, |
0 | 194 |
'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
|
195 |
'ET is CWEType, X is Basket') |
8222
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
196 |
self.assertEqual(solutions, [{'X': 'Basket', 'ET': 'CWEType', 'ETN': 'String'}]) |
0 | 197 |
|
198 |
def test_preprocess_security_aggregat(self): |
|
199 |
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
|
200 |
plan.session = self.user_groups_session('users') |
0 | 201 |
union = plan.rqlst |
202 |
plan.preprocess(union) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
203 |
self.assertEqual(len(union.children), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
204 |
self.assertEqual(len(union.children[0].with_), 1) |
0 | 205 |
subq = union.children[0].with_[0].query |
8222
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
206 |
self.assertEqual(len(subq.children), 4) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
207 |
self.assertEqual([t.as_string() for t in union.children[0].selection], |
0 | 208 |
['MAX(X)']) |
1787 | 209 |
|
0 | 210 |
def test_preprocess_nonregr(self): |
211 |
rqlst = self._prepare('Any S ORDERBY SI WHERE NOT S ecrit_par O, S para SI') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
212 |
self.assertEqual(len(rqlst.solutions), 1) |
1787 | 213 |
|
0 | 214 |
def test_build_description(self): |
215 |
# should return an empty result set |
|
216 |
rset = self.execute('Any X WHERE X eid %(x)s', {'x': self.session.user.eid}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
217 |
self.assertEqual(rset.description[0][0], 'CWUser') |
0 | 218 |
rset = self.execute('Any 1') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
219 |
self.assertEqual(rset.description[0][0], 'Int') |
0 | 220 |
rset = self.execute('Any TRUE') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
221 |
self.assertEqual(rset.description[0][0], 'Boolean') |
0 | 222 |
rset = self.execute('Any "hop"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
223 |
self.assertEqual(rset.description[0][0], 'String') |
0 | 224 |
rset = self.execute('Any TODAY') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
225 |
self.assertEqual(rset.description[0][0], 'Date') |
0 | 226 |
rset = self.execute('Any NOW') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
227 |
self.assertEqual(rset.description[0][0], 'Datetime') |
0 | 228 |
rset = self.execute('Any %(x)s', {'x': 1}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
229 |
self.assertEqual(rset.description[0][0], 'Int') |
0 | 230 |
rset = self.execute('Any %(x)s', {'x': 1L}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
231 |
self.assertEqual(rset.description[0][0], 'Int') |
0 | 232 |
rset = self.execute('Any %(x)s', {'x': True}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
233 |
self.assertEqual(rset.description[0][0], 'Boolean') |
0 | 234 |
rset = self.execute('Any %(x)s', {'x': 1.0}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
235 |
self.assertEqual(rset.description[0][0], 'Float') |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
236 |
rset = self.execute('Any %(x)s', {'x': datetime.now()}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
237 |
self.assertEqual(rset.description[0][0], 'Datetime') |
0 | 238 |
rset = self.execute('Any %(x)s', {'x': 'str'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
239 |
self.assertEqual(rset.description[0][0], 'String') |
0 | 240 |
rset = self.execute('Any %(x)s', {'x': u'str'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
241 |
self.assertEqual(rset.description[0][0], 'String') |
0 | 242 |
|
243 |
||
244 |
class QuerierTC(BaseQuerierTC): |
|
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
245 |
def setUp(self): |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
246 |
self.__class__.repo = repo |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
247 |
super(QuerierTC, self).setUp() |
0 | 248 |
|
249 |
def test_encoding_pb(self): |
|
250 |
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
|
251 |
'Any X WHERE X is CWRType, X name "�wned_by"') |
0 | 252 |
|
253 |
def test_unknown_eid(self): |
|
254 |
# should return an empty result set |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
255 |
self.assertFalse(self.execute('Any X WHERE X eid 99999999')) |
1787 | 256 |
|
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
|
257 |
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
|
258 |
# 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
|
259 |
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
|
260 |
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
|
261 |
|
1949
9064102b4deb
test Bytes storage/retreival
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
262 |
def test_bytes_storage(self): |
3587 | 263 |
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
|
264 |
{'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
|
265 |
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
|
266 |
self.assertIsInstance(fdata, Binary) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
267 |
self.assertEqual(fdata.getvalue(), 'xxx') |
1949
9064102b4deb
test Bytes storage/retreival
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
268 |
|
0 | 269 |
# selection queries tests ################################################# |
1787 | 270 |
|
0 | 271 |
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
|
272 |
rset = self.execute('Any X ORDERBY X WHERE X is CWGroup') |
0 | 273 |
result, descr = rset.rows, rset.description |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
274 |
self.assertEqual(tuplify(result), [(2,), (3,), (4,), (5,)]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
275 |
self.assertEqual(descr, [('CWGroup',), ('CWGroup',), ('CWGroup',), ('CWGroup',)]) |
1787 | 276 |
|
0 | 277 |
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
|
278 |
rset = self.execute('Any X ORDERBY N WHERE X is CWGroup, X name N') |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
279 |
self.assertEqual(tuplify(rset.rows), [(2,), (3,), (4,), (5,)]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
280 |
self.assertEqual(rset.description, [('CWGroup',), ('CWGroup',), ('CWGroup',), ('CWGroup',)]) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
281 |
rset = self.execute('Any X ORDERBY N DESC WHERE X is CWGroup, X name N') |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
282 |
self.assertEqual(tuplify(rset.rows), [(5,), (4,), (3,), (2,)]) |
1787 | 283 |
|
0 | 284 |
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
|
285 |
rset = self.execute('Any N GROUPBY N WHERE X is CWGroup, X name N') |
0 | 286 |
result, descr = rset.rows, rset.description |
287 |
result.sort() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
288 |
self.assertEqual(tuplify(result), [('guests',), ('managers',), ('owners',), ('users',)]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
289 |
self.assertEqual(descr, [('String',), ('String',), ('String',), ('String',)]) |
1787 | 290 |
|
0 | 291 |
def test_select_is(self): |
292 |
rset = self.execute('Any X, TN ORDERBY TN LIMIT 10 WHERE X is T, T name TN') |
|
293 |
result, descr = rset.rows, rset.description |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
294 |
self.assertEqual(result[0][1], descr[0][0]) |
1787 | 295 |
|
0 | 296 |
def test_select_is_aggr(self): |
297 |
rset = self.execute('Any TN, COUNT(X) GROUPBY TN ORDERBY 2 DESC WHERE X is T, T name TN') |
|
298 |
result, descr = rset.rows, rset.description |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
299 |
self.assertEqual(descr[0][0], 'String') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
300 |
self.assertEqual(descr[0][1], 'Int') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
301 |
self.assertEqual(result[0][0], 'CWRelation') # XXX may change as schema evolve |
1787 | 302 |
|
0 | 303 |
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
|
304 |
rset = self.execute('Any N GROUPBY N ORDERBY N WHERE X is CWGroup, X name N') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
305 |
self.assertEqual(tuplify(rset.rows), [('guests',), ('managers',), ('owners',), ('users',)]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
306 |
self.assertEqual(rset.description, [('String',), ('String',), ('String',), ('String',)]) |
1787 | 307 |
|
0 | 308 |
def test_select_complex_groupby(self): |
309 |
rset = self.execute('Any N GROUPBY N WHERE X name N') |
|
310 |
rset = self.execute('Any N,MAX(D) GROUPBY N LIMIT 5 WHERE X name N, X creation_date D') |
|
1787 | 311 |
|
0 | 312 |
def test_select_inlined_groupby(self): |
313 |
seid = self.execute('State X WHERE X name "deactivated"')[0][0] |
|
314 |
rset = self.execute('Any U,L,S GROUPBY U,L,S WHERE X in_state S, U login L, S eid %s' % seid) |
|
1787 | 315 |
|
7392
230f2511ad28
[querier test] test groupby function call / column number
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7257
diff
changeset
|
316 |
def test_select_groupby_funccall(self): |
230f2511ad28
[querier test] test groupby function call / column number
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7257
diff
changeset
|
317 |
rset = self.execute('Any YEAR(CD), COUNT(X) GROUPBY YEAR(CD) WHERE X is CWUser, X creation_date CD') |
230f2511ad28
[querier test] test groupby function call / column number
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7257
diff
changeset
|
318 |
self.assertListEqual(rset.rows, [[date.today().year, 2]]) |
230f2511ad28
[querier test] test groupby function call / column number
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7257
diff
changeset
|
319 |
|
230f2511ad28
[querier test] test groupby function call / column number
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7257
diff
changeset
|
320 |
def test_select_groupby_colnumber(self): |
230f2511ad28
[querier test] test groupby function call / column number
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7257
diff
changeset
|
321 |
rset = self.execute('Any YEAR(CD), COUNT(X) GROUPBY 1 WHERE X is CWUser, X creation_date CD') |
230f2511ad28
[querier test] test groupby function call / column number
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7257
diff
changeset
|
322 |
self.assertListEqual(rset.rows, [[date.today().year, 2]]) |
230f2511ad28
[querier test] test groupby function call / column number
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7257
diff
changeset
|
323 |
|
0 | 324 |
def test_select_complex_orderby(self): |
325 |
rset1 = self.execute('Any N ORDERBY N WHERE X name N') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
326 |
self.assertEqual(sorted(rset1.rows), rset1.rows) |
0 | 327 |
rset = self.execute('Any N ORDERBY N LIMIT 5 OFFSET 1 WHERE X name N') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
328 |
self.assertEqual(rset.rows[0][0], rset1.rows[1][0]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
329 |
self.assertEqual(len(rset), 5) |
1787 | 330 |
|
0 | 331 |
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
|
332 |
rset = self.execute('Any X, TMP ORDERBY TMP WHERE X name TMP, X is CWGroup') |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
333 |
self.assertEqual(tuplify(rset.rows), [(2, 'guests',), (3, 'managers',), (4, 'owners',), (5, 'users',)]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
334 |
self.assertEqual(rset.description, [('CWGroup', 'String',), ('CWGroup', 'String',), ('CWGroup', 'String',), ('CWGroup', 'String',)]) |
1787 | 335 |
|
0 | 336 |
def test_select_6(self): |
337 |
self.execute("INSERT Personne X: X nom 'bidule'")[0] |
|
338 |
rset = self.execute('Any Y where X name TMP, Y nom in (TMP, "bidule")') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
339 |
#self.assertEqual(rset.description, [('Personne',), ('Personne',)]) |
0 | 340 |
self.assert_(('Personne',) in rset.description) |
341 |
rset = self.execute('DISTINCT Any Y where X name TMP, Y nom in (TMP, "bidule")') |
|
342 |
self.assert_(('Personne',) in rset.description) |
|
1787 | 343 |
|
0 | 344 |
def test_select_not_attr(self): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
345 |
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
|
346 |
seid = self.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
0 | 347 |
rset = self.execute('Personne X WHERE NOT X nom "bidule"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
348 |
self.assertEqual(len(rset.rows), 0, rset.rows) |
0 | 349 |
rset = self.execute('Personne X WHERE NOT X nom "bid"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
350 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 351 |
self.execute("SET P travaille S WHERE P nom 'bidule', S nom 'chouette'") |
352 |
rset = self.execute('Personne X WHERE NOT X travaille S') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
353 |
self.assertEqual(len(rset.rows), 0, rset.rows) |
1787 | 354 |
|
0 | 355 |
def test_select_is_in(self): |
356 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
357 |
self.execute("INSERT Societe X: X nom 'chouette'") |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
358 |
self.assertEqual(len(self.execute("Any X WHERE X is IN (Personne, Societe)")), |
0 | 359 |
2) |
1787 | 360 |
|
0 | 361 |
def test_select_not_rel(self): |
362 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
363 |
self.execute("INSERT Societe X: X nom 'chouette'") |
|
364 |
self.execute("INSERT Personne X: X nom 'autre'") |
|
365 |
self.execute("SET P travaille S WHERE P nom 'bidule', S nom 'chouette'") |
|
366 |
rset = self.execute('Personne X WHERE NOT X travaille S') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
367 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 368 |
rset = self.execute('Personne X WHERE NOT X travaille S, S nom "chouette"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
369 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
1787 | 370 |
|
0 | 371 |
def test_select_nonregr_inlined(self): |
372 |
self.execute("INSERT Note X: X para 'bidule'") |
|
373 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
374 |
self.execute("INSERT Personne X: X nom 'autre'") |
|
375 |
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
|
376 |
rset = self.execute('Any U,T ORDERBY T DESC WHERE U is CWUser, ' |
0 | 377 |
'N ecrit_par U, N type T')#, {'x': self.ueid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
378 |
self.assertEqual(len(rset.rows), 0) |
1787 | 379 |
|
0 | 380 |
def test_select_nonregr_edition_not(self): |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
381 |
groupeids = set((2, 3, 4)) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
382 |
groupreadperms = set(r[0] for r in self.execute('Any Y WHERE X name "CWGroup", Y eid IN(2, 3, 4), X read_permission Y')) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
383 |
rset = self.execute('DISTINCT Any Y WHERE X is CWEType, X name "CWGroup", Y eid IN(2, 3, 4), NOT X read_permission Y') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
384 |
self.assertEqual(sorted(r[0] for r in rset.rows), sorted(groupeids - groupreadperms)) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
385 |
rset = self.execute('DISTINCT Any Y WHERE X name "CWGroup", Y eid IN(2, 3, 4), NOT X read_permission Y') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
386 |
self.assertEqual(sorted(r[0] for r in rset.rows), sorted(groupeids - groupreadperms)) |
1787 | 387 |
|
0 | 388 |
def test_select_outer_join(self): |
389 |
peid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
390 |
peid2 = self.execute("INSERT Personne X: X nom 'autre'")[0][0] |
|
391 |
seid1 = self.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
|
392 |
seid2 = self.execute("INSERT Societe X: X nom 'chouetos'")[0][0] |
|
393 |
rset = self.execute('Any X,S ORDERBY X WHERE X travaille S?') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
394 |
self.assertEqual(rset.rows, [[peid1, None], [peid2, None]]) |
0 | 395 |
self.execute("SET P travaille S WHERE P nom 'bidule', S nom 'chouette'") |
396 |
rset = self.execute('Any X,S ORDERBY X WHERE X travaille S?') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
397 |
self.assertEqual(rset.rows, [[peid1, seid1], [peid2, None]]) |
0 | 398 |
rset = self.execute('Any S,X ORDERBY S WHERE X? travaille S') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
399 |
self.assertEqual(rset.rows, [[seid1, peid1], [seid2, None]]) |
1787 | 400 |
|
0 | 401 |
def test_select_outer_join_optimized(self): |
402 |
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
|
403 |
rset = self.execute('Any X WHERE X eid %(x)s, P? connait X', {'x':peid1}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
404 |
self.assertEqual(rset.rows, [[peid1]]) |
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
405 |
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
|
406 |
{'x':peid1}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
407 |
self.assertEqual(rset.rows, [[peid1]]) |
0 | 408 |
|
409 |
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
|
410 |
rset = self.execute('DISTINCT Any G WHERE U? in_group G') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
411 |
self.assertEqual(len(rset), 4) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
412 |
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
|
413 |
{'x': self.session.user.eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
414 |
self.assertEqual(len(rset), 4) |
0 | 415 |
|
416 |
def test_select_ambigous_outer_join(self): |
|
417 |
teid = self.execute("INSERT Tag X: X name 'tag'")[0][0] |
|
418 |
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
|
419 |
geid = self.execute("CWGroup G WHERE G name 'users'")[0][0] |
0 | 420 |
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
|
421 |
{'g': geid, 't': teid}) |
0 | 422 |
rset = self.execute("Any GN,TN ORDERBY GN WHERE T? tags G, T name TN, G name GN") |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
423 |
self.assertTrue(['users', 'tag'] in rset.rows) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
424 |
self.assertTrue(['activated', None] in rset.rows) |
0 | 425 |
rset = self.execute("Any GN,TN ORDERBY GN WHERE T tags G?, T name TN, G name GN") |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
426 |
self.assertEqual(rset.rows, [[None, 'tagbis'], ['users', 'tag']]) |
1787 | 427 |
|
0 | 428 |
def test_select_not_inline_rel(self): |
429 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
430 |
self.execute("INSERT Note X: X type 'a'") |
|
431 |
self.execute("INSERT Note X: X type 'b'") |
|
432 |
self.execute("SET X ecrit_par Y WHERE X type 'a', Y nom 'bidule'") |
|
433 |
rset = self.execute('Note X WHERE NOT X ecrit_par P') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
434 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
1787 | 435 |
|
0 | 436 |
def test_select_not_unlinked_multiple_solutions(self): |
437 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
438 |
self.execute("INSERT Note X: X type 'a'") |
|
439 |
self.execute("INSERT Note X: X type 'b'") |
|
440 |
self.execute("SET Y evaluee X WHERE X type 'a', Y nom 'bidule'") |
|
441 |
rset = self.execute('Note X WHERE NOT Y evaluee X') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
442 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 443 |
|
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
|
444 |
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
|
445 |
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
|
446 |
{'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
|
447 |
test_data = [('YEAR', 2001), ('MONTH', 2), ('DAY', 3), |
7904
f41bb38dda7c
[rql, sql] support for weekday function introduced in lgdp 1.7 (closes #1979717)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
448 |
('HOUR', 12), ('MINUTE', 13), ('WEEKDAY', 6)] |
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
|
449 |
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
|
450 |
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
|
451 |
% funcname) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
452 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
453 |
self.assertEqual(rset.rows[0][0], result) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
454 |
self.assertEqual(rset.description, [('Int',)]) |
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
|
455 |
|
7257
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
456 |
def test_regexp_based_pattern_matching(self): |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
457 |
peid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
458 |
peid2 = self.execute("INSERT Personne X: X nom 'cidule'")[0][0] |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
459 |
rset = self.execute('Any X WHERE X is Personne, X nom REGEXP "^b"') |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
460 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
461 |
self.assertEqual(rset.rows[0][0], peid1) |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
462 |
rset = self.execute('Any X WHERE X is Personne, X nom REGEXP "idu"') |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
463 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
beea955b45e2
[rql] basic support for regexp-based pattern matching
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7211
diff
changeset
|
464 |
|
0 | 465 |
def test_select_aggregat_count(self): |
466 |
rset = self.execute('Any COUNT(X)') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
467 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
468 |
self.assertEqual(len(rset.rows[0]), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
469 |
self.assertEqual(rset.description, [('Int',)]) |
1787 | 470 |
|
0 | 471 |
def test_select_aggregat_sum(self): |
472 |
rset = self.execute('Any SUM(O) WHERE X ordernum O') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
473 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
474 |
self.assertEqual(len(rset.rows[0]), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
475 |
self.assertEqual(rset.description, [('Int',)]) |
1787 | 476 |
|
0 | 477 |
def test_select_aggregat_min(self): |
478 |
rset = self.execute('Any MIN(X) WHERE X is Personne') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
479 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
480 |
self.assertEqual(len(rset.rows[0]), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
481 |
self.assertEqual(rset.description, [('Personne',)]) |
0 | 482 |
rset = self.execute('Any MIN(O) WHERE X ordernum O') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
483 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
484 |
self.assertEqual(len(rset.rows[0]), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
485 |
self.assertEqual(rset.description, [('Int',)]) |
1787 | 486 |
|
0 | 487 |
def test_select_aggregat_max(self): |
488 |
rset = self.execute('Any MAX(X) WHERE X is Personne') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
489 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
490 |
self.assertEqual(len(rset.rows[0]), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
491 |
self.assertEqual(rset.description, [('Personne',)]) |
0 | 492 |
rset = self.execute('Any MAX(O) WHERE X ordernum O') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
493 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
494 |
self.assertEqual(len(rset.rows[0]), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
495 |
self.assertEqual(rset.description, [('Int',)]) |
0 | 496 |
|
497 |
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
|
498 |
rset = self.execute('Any GROUP_CONCAT(N) WHERE X is CWGroup, X name N') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
499 |
self.assertTrue(rset) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
500 |
self.assertEqual(sorted(rset[0][0].split(', ')), ['guests', 'managers', |
0 | 501 |
'owners', 'users']) |
502 |
||
503 |
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
|
504 |
rset = self.execute('Any TEXT_LIMIT_SIZE(N, 3) WHERE X is CWGroup, X name N, X name "managers"') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
505 |
self.assertTrue(rset) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
506 |
self.assertEqual(rset[0][0], 'man...') |
0 | 507 |
self.execute("INSERT Basket X: X name 'bidule', X description '<b>hop hop</b>', X description_format 'text/html'") |
508 |
rset = self.execute('Any LIMIT_SIZE(D, DF, 3) WHERE X is Basket, X description D, X description_format DF') |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
509 |
self.assertTrue(rset) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
510 |
self.assertEqual(rset[0][0], 'hop...') |
0 | 511 |
|
512 |
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
|
513 |
rset = self.execute('DISTINCT Any X,N ORDERBY GROUP_SORT_VALUE(N) WHERE X is CWGroup, X name N, X name "managers"') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
514 |
self.assertEqual(len(rset), 1) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
515 |
self.assertEqual(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
|
516 |
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"') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
517 |
self.assertEqual(len(rset), 3) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
518 |
self.assertEqual(rset[0][1], 'owners') |
1787 | 519 |
|
0 | 520 |
def test_select_aggregat_sort(self): |
521 |
rset = self.execute('Any G, COUNT(U) GROUPBY G ORDERBY 2 WHERE U in_group G') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
522 |
self.assertEqual(len(rset.rows), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
523 |
self.assertEqual(len(rset.rows[0]), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
524 |
self.assertEqual(rset.description[0], ('CWGroup', 'Int',)) |
0 | 525 |
|
526 |
def test_select_aggregat_having(self): |
|
527 |
rset = self.execute('Any N,COUNT(RDEF) GROUPBY N ORDERBY 2,N ' |
|
528 |
'WHERE RT name N, RDEF relation_type RT ' |
|
529 |
'HAVING COUNT(RDEF) > 10') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
530 |
self.assertListEqual(rset.rows, |
5575
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
531 |
[[u'description_format', 12], |
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
532 |
[u'description', 13], |
8111
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
533 |
[u'name', 16], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
534 |
[u'created_by', 43], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
535 |
[u'creation_date', 43], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
536 |
[u'cw_source', 43], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
537 |
[u'cwuri', 43], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
538 |
[u'in_basket', 43], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
539 |
[u'is', 43], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
540 |
[u'is_instance_of', 43], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
541 |
[u'modification_date', 43], |
d1be698018d2
[server test] Fix tests regression from changeset 7980b36fb1aa
Julien Cristau <julien.cristau@logilab.fr>
parents:
8021
diff
changeset
|
542 |
[u'owned_by', 43]]) |
0 | 543 |
|
544 |
def test_select_aggregat_having_dumb(self): |
|
545 |
# dumb but should not raise an error |
|
546 |
rset = self.execute('Any U,COUNT(X) GROUPBY U ' |
|
547 |
'WHERE U eid %(x)s, X owned_by U ' |
|
548 |
'HAVING COUNT(X) > 10', {'x': self.ueid}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
549 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
550 |
self.assertEqual(rset.rows[0][0], self.ueid) |
0 | 551 |
|
5782
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
552 |
def test_select_having_non_aggregat_1(self): |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
553 |
rset = self.execute('Any L WHERE X login L, X creation_date CD ' |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
554 |
'HAVING YEAR(CD) = %s' % date.today().year) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
555 |
self.assertListEqual(rset.rows, |
5782
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
556 |
[[u'admin'], |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
557 |
[u'anon']]) |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
558 |
|
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
559 |
def test_select_having_non_aggregat_2(self): |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
560 |
rset = self.execute('Any L GROUPBY L WHERE X login L, X in_group G, ' |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
561 |
'X creation_date CD HAVING YEAR(CD) = %s OR COUNT(G) > 1' |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
562 |
% date.today().year) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
563 |
self.assertListEqual(rset.rows, |
5782
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
564 |
[[u'admin'], |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
565 |
[u'anon']]) |
8ff48d1a319f
[rql2sql] when using HAVING to by-pass rql limitation (not to filter on result of an aggregat function), we should emit SQL that doesn't use HAVING to avoid potential backend error because variables are not grouped. Closes #1061603.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5701
diff
changeset
|
566 |
|
0 | 567 |
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
|
568 |
"""need sqlite including http://www.sqlite.org/cvstrac/tktview?tn=3773 fix""" |
0 | 569 |
rset = self.execute('Any X ORDERBY X,D LIMIT 5 WHERE X creation_date D') |
570 |
result = rset.rows |
|
571 |
result.sort() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
572 |
self.assertEqual(tuplify(result), [(1,), (2,), (3,), (4,), (5,)]) |
1787 | 573 |
|
0 | 574 |
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
|
575 |
rset = self.execute('Any X, UPPER(L) ORDERBY L WHERE X is CWUser, X login L') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
576 |
self.assertEqual(len(rset.rows), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
577 |
self.assertEqual(rset.rows[0][1], 'ADMIN') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
578 |
self.assertEqual(rset.description[0], ('CWUser', 'String',)) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
579 |
self.assertEqual(rset.rows[1][1], 'ANON') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
580 |
self.assertEqual(rset.description[1], ('CWUser', 'String',)) |
0 | 581 |
eid = rset.rows[0][0] |
582 |
rset = self.execute('Any UPPER(L) WHERE X eid %s, X login L'%eid) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
583 |
self.assertEqual(rset.rows[0][0], 'ADMIN') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
584 |
self.assertEqual(rset.description, [('String',)]) |
0 | 585 |
|
6081
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
586 |
def test_select_float_abs(self): |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
587 |
# test positive number |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
588 |
eid = self.execute('INSERT Affaire A: A invoiced %(i)s', {'i': 1.2})[0][0] |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
589 |
rset = self.execute('Any ABS(I) WHERE X eid %(x)s, X invoiced I', {'x': eid}) |
6366 | 590 |
self.assertEqual(rset.rows[0][0], 1.2) |
6081
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
591 |
# test negative number |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
592 |
eid = self.execute('INSERT Affaire A: A invoiced %(i)s', {'i': -1.2})[0][0] |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
593 |
rset = self.execute('Any ABS(I) WHERE X eid %(x)s, X invoiced I', {'x': eid}) |
6366 | 594 |
self.assertEqual(rset.rows[0][0], 1.2) |
6081
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
595 |
|
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
596 |
def test_select_int_abs(self): |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
597 |
# test positive number |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
598 |
eid = self.execute('INSERT Affaire A: A duration %(d)s', {'d': 12})[0][0] |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
599 |
rset = self.execute('Any ABS(D) WHERE X eid %(x)s, X duration D', {'x': eid}) |
6366 | 600 |
self.assertEqual(rset.rows[0][0], 12) |
6081
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
601 |
# test negative number |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
602 |
eid = self.execute('INSERT Affaire A: A duration %(d)s', {'d': -12})[0][0] |
ede33e6400ab
[forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6050
diff
changeset
|
603 |
rset = self.execute('Any ABS(D) WHERE X eid %(x)s, X duration D', {'x': eid}) |
6366 | 604 |
self.assertEqual(rset.rows[0][0], 12) |
605 |
||
0 | 606 |
## def test_select_simplified(self): |
607 |
## ueid = self.session.user.eid |
|
608 |
## rset = self.execute('Any L WHERE %s login L'%ueid) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
609 |
## self.assertEqual(rset.rows[0][0], 'admin') |
0 | 610 |
## rset = self.execute('Any L WHERE %(x)s login L', {'x':ueid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
611 |
## self.assertEqual(rset.rows[0][0], 'admin') |
1787 | 612 |
|
0 | 613 |
def test_select_searchable_text_1(self): |
614 |
rset = self.execute(u"INSERT Personne X: X nom 'bid�le'") |
|
615 |
rset = self.execute(u"INSERT Societe X: X nom 'bid�le'") |
|
616 |
rset = self.execute("INSERT Societe X: X nom 'chouette'") |
|
617 |
self.commit() |
|
618 |
rset = self.execute('Any X where X has_text %(text)s', {'text': u'bid�le'}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
619 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
0 | 620 |
rset = self.execute(u'Any N where N has_text "bid�le"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
621 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
0 | 622 |
biduleeids = [r[0] for r in rset.rows] |
623 |
rset = self.execute(u'Any N where NOT N has_text "bid�le"') |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
624 |
self.assertFalse([r[0] for r in rset.rows if r[0] in biduleeids]) |
0 | 625 |
# duh? |
626 |
rset = self.execute('Any X WHERE X has_text %(text)s', {'text': u'�a'}) |
|
1787 | 627 |
|
0 | 628 |
def test_select_searchable_text_2(self): |
629 |
rset = self.execute("INSERT Personne X: X nom 'bidule'") |
|
630 |
rset = self.execute("INSERT Personne X: X nom 'chouette'") |
|
631 |
rset = self.execute("INSERT Societe X: X nom 'bidule'") |
|
632 |
self.commit() |
|
633 |
rset = self.execute('Personne N where N has_text "bidule"') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
634 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
1787 | 635 |
|
0 | 636 |
def test_select_searchable_text_3(self): |
637 |
rset = self.execute("INSERT Personne X: X nom 'bidule', X sexe 'M'") |
|
638 |
rset = self.execute("INSERT Personne X: X nom 'bidule', X sexe 'F'") |
|
639 |
rset = self.execute("INSERT Societe X: X nom 'bidule'") |
|
640 |
self.commit() |
|
641 |
rset = self.execute('Any X where X has_text "bidule" and X sexe "M"') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
642 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
1787 | 643 |
|
0 | 644 |
def test_select_multiple_searchable_text(self): |
645 |
self.execute(u"INSERT Personne X: X nom 'bid�le'") |
|
646 |
self.execute("INSERT Societe X: X nom 'chouette', S travaille X") |
|
647 |
self.execute(u"INSERT Personne X: X nom 'bid�le'") |
|
648 |
self.commit() |
|
649 |
rset = self.execute('Personne X WHERE X has_text %(text)s, X travaille S, S has_text %(text2)s', |
|
650 |
{'text': u'bid�le', |
|
651 |
'text2': u'chouette',} |
|
652 |
) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
653 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
1787 | 654 |
|
0 | 655 |
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
|
656 |
rset = self.execute('Any X WHERE X is CWGroup', build_descr=0) |
0 | 657 |
rset.rows.sort() |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
658 |
self.assertEqual(tuplify(rset.rows), [(2,), (3,), (4,), (5,)]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
659 |
self.assertEqual(rset.description, ()) |
0 | 660 |
|
661 |
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
|
662 |
rset = self.execute('CWGroup X ORDERBY N LIMIT 2 WHERE X name N') |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
663 |
self.assertEqual(tuplify(rset.rows), [(2,), (3,)]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
664 |
self.assertEqual(rset.description, [('CWGroup',), ('CWGroup',)]) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
665 |
rset = self.execute('CWGroup X ORDERBY N LIMIT 2 OFFSET 2 WHERE X name N') |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
666 |
self.assertEqual(tuplify(rset.rows), [(4,), (5,)]) |
1787 | 667 |
|
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
|
668 |
def test_select_symmetric(self): |
0 | 669 |
self.execute("INSERT Personne X: X nom 'machin'") |
670 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
671 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
672 |
self.execute("INSERT Personne X: X nom 'trucmuche'") |
|
673 |
self.execute("SET X connait Y WHERE X nom 'chouette', Y nom 'bidule'") |
|
674 |
self.execute("SET X connait Y WHERE X nom 'machin', Y nom 'chouette'") |
|
675 |
rset = self.execute('Any P where P connait P2') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
676 |
self.assertEqual(len(rset.rows), 3, rset.rows) |
0 | 677 |
rset = self.execute('Any P where NOT P connait P2') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
678 |
self.assertEqual(len(rset.rows), 1, rset.rows) # trucmuche |
0 | 679 |
rset = self.execute('Any P where P connait P2, P2 nom "bidule"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
680 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 681 |
rset = self.execute('Any P where P2 connait P, P2 nom "bidule"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
682 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 683 |
rset = self.execute('Any P where P connait P2, P2 nom "chouette"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
684 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
0 | 685 |
rset = self.execute('Any P where P2 connait P, P2 nom "chouette"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
686 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
1787 | 687 |
|
0 | 688 |
def test_select_inline(self): |
689 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
690 |
self.execute("INSERT Note X: X type 'a'") |
|
691 |
self.execute("SET X ecrit_par Y WHERE X type 'a', Y nom 'bidule'") |
|
692 |
rset = self.execute('Any N where N ecrit_par X, X nom "bidule"') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
693 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
1787 | 694 |
|
0 | 695 |
def test_select_creation_date(self): |
696 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
697 |
rset = self.execute('Any D WHERE X nom "bidule", X creation_date D') |
|
698 |
self.assertEqual(len(rset.rows), 1) |
|
699 |
||
700 |
def test_select_or_relation(self): |
|
701 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
702 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
703 |
self.execute("INSERT Societe X: X nom 'logilab'") |
|
704 |
self.execute("INSERT Societe X: X nom 'caesium'") |
|
705 |
self.execute("SET P travaille S WHERE P nom 'bidule', S nom 'logilab'") |
|
706 |
rset = self.execute('DISTINCT Any P WHERE P travaille S1 OR P travaille S2, S1 nom "logilab", S2 nom "caesium"') |
|
707 |
self.assertEqual(len(rset.rows), 1) |
|
708 |
self.execute("SET P travaille S WHERE P nom 'chouette', S nom 'caesium'") |
|
709 |
rset = self.execute('DISTINCT Any P WHERE P travaille S1 OR P travaille S2, S1 nom "logilab", S2 nom "caesium"') |
|
710 |
self.assertEqual(len(rset.rows), 2) |
|
1787 | 711 |
|
0 | 712 |
def test_select_or_sym_relation(self): |
713 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
714 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
715 |
self.execute("INSERT Personne X: X nom 'truc'") |
|
716 |
self.execute("SET P connait S WHERE P nom 'bidule', S nom 'chouette'") |
|
717 |
rset = self.execute('DISTINCT Any P WHERE S connait P, S nom "chouette"') |
|
718 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
|
719 |
rset = self.execute('DISTINCT Any P WHERE P connait S or S connait P, S nom "chouette"') |
|
720 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
|
721 |
self.execute("SET P connait S WHERE P nom 'chouette', S nom 'truc'") |
|
722 |
rset = self.execute('DISTINCT Any P WHERE S connait P, S nom "chouette"') |
|
723 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
|
724 |
rset = self.execute('DISTINCT Any P WHERE P connait S OR S connait P, S nom "chouette"') |
|
725 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
|
1787 | 726 |
|
0 | 727 |
def test_select_follow_relation(self): |
728 |
self.execute("INSERT Affaire X: X sujet 'cool'") |
|
729 |
self.execute("INSERT Societe X: X nom 'chouette'") |
|
730 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
731 |
self.execute("INSERT Note X: X para 'truc'") |
|
732 |
self.execute("SET S evaluee N WHERE S is Societe, N is Note") |
|
733 |
self.execute("INSERT Societe X: X nom 'bidule'") |
|
734 |
self.execute("INSERT Note X: X para 'troc'") |
|
735 |
self.execute("SET S evaluee N WHERE S nom 'bidule', N para 'troc'") |
|
736 |
rset = self.execute('DISTINCT Any A,N WHERE A concerne S, S evaluee N') |
|
737 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
|
738 |
||
739 |
def test_select_ordered_distinct_1(self): |
|
6194
2a1f8cabbe6a
[querier test] remove some actually bad tests that were passing thanks to a sqlite bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6189
diff
changeset
|
740 |
self.assertRaises(BadRQLQuery, |
2a1f8cabbe6a
[querier test] remove some actually bad tests that were passing thanks to a sqlite bug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6189
diff
changeset
|
741 |
self.execute, 'DISTINCT Any S ORDERBY R WHERE A is Affaire, A sujet S, A ref R') |
0 | 742 |
|
743 |
def test_select_ordered_distinct_2(self): |
|
744 |
self.execute("INSERT Affaire X: X sujet 'minor'") |
|
745 |
self.execute("INSERT Affaire X: X sujet 'zou'") |
|
746 |
self.execute("INSERT Affaire X: X sujet 'abcd'") |
|
747 |
rset = self.execute('DISTINCT Any S ORDERBY S WHERE A is Affaire, A sujet S') |
|
6196 | 748 |
self.assertEqual(rset.rows, [['abcd'], ['minor'], ['zou']]) |
1787 | 749 |
|
0 | 750 |
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
|
751 |
rset = self.execute('DISTINCT Any N ORDERBY GROUP_SORT_VALUE(N) WHERE X is CWGroup, X name N') |
0 | 752 |
self.assertEqual(rset.rows, [['owners'], ['guests'], ['users'], ['managers']]) |
753 |
||
754 |
def test_select_or_value(self): |
|
755 |
rset = self.execute('Any U WHERE U in_group G, G name "owners" OR G name "users"') |
|
756 |
self.assertEqual(len(rset.rows), 0) |
|
757 |
rset = self.execute('Any U WHERE U in_group G, G name "guests" OR G name "managers"') |
|
758 |
self.assertEqual(len(rset.rows), 2) |
|
759 |
||
760 |
def test_select_explicit_eid(self): |
|
761 |
rset = self.execute('Any X,E WHERE X owned_by U, X eid E, U eid %(u)s', {'u': self.session.user.eid}) |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
762 |
self.assertTrue(rset) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
763 |
self.assertEqual(rset.description[0][1], 'Int') |
1787 | 764 |
|
0 | 765 |
# def test_select_rewritten_optional(self): |
766 |
# eid = self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
767 |
# rset = self.execute('Any X WHERE X eid %(x)s, EXISTS(X owned_by U) OR EXISTS(X concerne S?, S owned_by U)', |
|
768 |
# {'x': eid}, 'x') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
769 |
# self.assertEqual(rset.rows, [[eid]]) |
1787 | 770 |
|
0 | 771 |
def test_today_bug(self): |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
772 |
self.execute("INSERT Tag X: X name 'bidule', X creation_date NOW") |
0 | 773 |
self.execute("INSERT Tag Y: Y name 'toto'") |
774 |
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
|
775 |
self.assert_(isinstance(rset.rows[0][0], datetime), rset.rows) |
0 | 776 |
rset = self.execute('Tag X WHERE X creation_date TODAY') |
777 |
self.assertEqual(len(rset.rows), 2) |
|
778 |
rset = self.execute('Any MAX(D) WHERE X is Tag, X creation_date D') |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
779 |
self.assertTrue(isinstance(rset[0][0], datetime), (rset[0][0], type(rset[0][0]))) |
0 | 780 |
|
781 |
def test_today(self): |
|
782 |
self.execute("INSERT Tag X: X name 'bidule', X creation_date TODAY") |
|
783 |
self.execute("INSERT Tag Y: Y name 'toto'") |
|
784 |
rset = self.execute('Tag X WHERE X creation_date TODAY') |
|
785 |
self.assertEqual(len(rset.rows), 2) |
|
786 |
||
787 |
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
|
788 |
rset = self.execute('Any N WHERE X is CWEType, X name N, X final %(val)s', |
0 | 789 |
{'val': True}) |
7484
45a350d6b22f
[repo test] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
790 |
self.assertEqual(sorted(r[0] for r in rset.rows), ['BigInt', 'Boolean', 'Bytes', |
7148
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
791 |
'Date', 'Datetime', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
792 |
'Decimal', 'Float', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
793 |
'Int', 'Interval', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
794 |
'Password', 'String', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
795 |
'TZDatetime', 'TZTime', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
796 |
'Time']) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
797 |
rset = self.execute('Any N WHERE X is CWEType, X name N, X final TRUE') |
7484
45a350d6b22f
[repo test] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
798 |
self.assertEqual(sorted(r[0] for r in rset.rows), ['BigInt', 'Boolean', 'Bytes', |
7148
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
799 |
'Date', 'Datetime', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
800 |
'Decimal', 'Float', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
801 |
'Int', 'Interval', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
802 |
'Password', 'String', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
803 |
'TZDatetime', 'TZTime', |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7088
diff
changeset
|
804 |
'Time']) |
7713
467c52ff9557
[sql] more test and fix boolean handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
805 |
req = self.session |
467c52ff9557
[sql] more test and fix boolean handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
806 |
req.create_entity('Personne', nom=u'louis', test=True) |
467c52ff9557
[sql] more test and fix boolean handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
807 |
self.assertEqual(len(req.execute('Any X WHERE X test %(val)s', {'val': True})), 1) |
467c52ff9557
[sql] more test and fix boolean handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
808 |
self.assertEqual(len(req.execute('Any X WHERE X test TRUE')), 1) |
467c52ff9557
[sql] more test and fix boolean handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
809 |
self.assertEqual(len(req.execute('Any X WHERE X test %(val)s', {'val': False})), 0) |
467c52ff9557
[sql] more test and fix boolean handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
810 |
self.assertEqual(len(req.execute('Any X WHERE X test FALSE')), 0) |
1787 | 811 |
|
0 | 812 |
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
|
813 |
rset = self.execute('Any X, "toto" ORDERBY X WHERE X is CWGroup') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
814 |
self.assertEqual(rset.rows, |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
815 |
map(list, zip((2,3,4,5), ('toto','toto','toto','toto',)))) |
0 | 816 |
self.assertIsInstance(rset[0][1], unicode) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
817 |
self.assertEqual(rset.description, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
818 |
zip(('CWGroup', 'CWGroup', 'CWGroup', 'CWGroup'), |
0 | 819 |
('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
|
820 |
rset = self.execute('Any X, %(value)s ORDERBY X WHERE X is CWGroup', {'value': 'toto'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
821 |
self.assertEqual(rset.rows, |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
822 |
map(list, zip((2,3,4,5), ('toto','toto','toto','toto',)))) |
0 | 823 |
self.assertIsInstance(rset[0][1], unicode) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
824 |
self.assertEqual(rset.description, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
825 |
zip(('CWGroup', 'CWGroup', 'CWGroup', 'CWGroup'), |
0 | 826 |
('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
|
827 |
rset = self.execute('Any X,GN WHERE X is CWUser, G is CWGroup, X login "syt", X in_group G, G name GN') |
0 | 828 |
|
829 |
def test_select_union(self): |
|
830 |
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
|
831 |
'((Any X,N WHERE X name N, X transition_of WF, WF workflow_of E, E name %(name)s)' |
0 | 832 |
' UNION ' |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
833 |
'(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
|
834 |
{'name': 'CWUser'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
835 |
self.assertEqual([x[1] for x in rset.rows], |
0 | 836 |
['activate', 'activated', 'deactivate', 'deactivated']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
837 |
self.assertEqual(rset.description, |
0 | 838 |
[('Transition', 'String'), ('State', 'String'), |
839 |
('Transition', 'String'), ('State', 'String')]) |
|
1787 | 840 |
|
0 | 841 |
def test_select_union_aggregat(self): |
842 |
# meaningless, the goal in to have group by done on different attribute |
|
843 |
# for each sub-query |
|
844 |
self.execute('(Any N,COUNT(X) GROUPBY N WHERE X name N, X is State)' |
|
845 |
' UNION ' |
|
846 |
'(Any N,COUNT(X) GROUPBY N ORDERBY 2 WHERE X login N)') |
|
1787 | 847 |
|
0 | 848 |
def test_select_union_aggregat_independant_group(self): |
849 |
self.execute('INSERT State X: X name "hop"') |
|
850 |
self.execute('INSERT State X: X name "hop"') |
|
851 |
self.execute('INSERT Transition X: X name "hop"') |
|
852 |
self.execute('INSERT Transition X: X name "hop"') |
|
853 |
rset = self.execute('Any N,NX ORDERBY 2 WITH N,NX BEING ' |
|
854 |
'((Any N,COUNT(X) GROUPBY N WHERE X name N, X is State HAVING COUNT(X)>1)' |
|
855 |
' UNION ' |
|
856 |
'(Any N,COUNT(X) GROUPBY N WHERE X name N, X is Transition HAVING COUNT(X)>1))') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
857 |
self.assertEqual(rset.rows, [[u'hop', 2], [u'hop', 2]]) |
1787 | 858 |
|
0 | 859 |
def test_select_union_selection_with_diff_variables(self): |
860 |
rset = self.execute('(Any N WHERE X name N, X is State)' |
|
861 |
' UNION ' |
|
862 |
'(Any NN WHERE XX name NN, XX is Transition)') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
863 |
self.assertEqual(sorted(r[0] for r in rset.rows), |
0 | 864 |
['abort', 'activate', 'activated', 'ben non', |
865 |
'deactivate', 'deactivated', 'done', 'en cours', |
|
866 |
'end', 'finie', 'markasdone', 'pitetre', 'redoit', |
|
867 |
'start', 'todo']) |
|
1787 | 868 |
|
5701
41119f034735
[querier] fix rset description bug with some union queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5657
diff
changeset
|
869 |
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
|
870 |
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
|
871 |
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
|
872 |
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
|
873 |
' UNION ' |
41119f034735
[querier] fix rset description bug with some union queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5657
diff
changeset
|
874 |
'(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
|
875 |
{'x': eid1, 'y': eid2}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
876 |
self.assertEqual(rset.description[:], [('CWGroup',), ('CWUser',)]) |
5701
41119f034735
[querier] fix rset description bug with some union queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5657
diff
changeset
|
877 |
|
0 | 878 |
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
|
879 |
geid = self.execute("INSERT CWGroup X: X name 'lulufanclub'")[0][0] |
0 | 880 |
self.execute("SET U in_group G WHERE G name 'lulufanclub'") |
881 |
peid = self.execute("INSERT Personne X: X prenom 'lulu', X nom 'petit'")[0][0] |
|
882 |
rset = self.execute("Any X WHERE X prenom 'lulu'," |
|
883 |
"EXISTS (U in_group G, G name 'lulufanclub' OR G name 'managers');") |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
884 |
self.assertEqual(rset.rows, [[peid]]) |
0 | 885 |
|
886 |
def test_identity(self): |
|
887 |
eid = self.execute('Any X WHERE X identity Y, Y eid 1')[0][0] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
888 |
self.assertEqual(eid, 1) |
0 | 889 |
eid = self.execute('Any X WHERE Y identity X, Y eid 1')[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
890 |
self.assertEqual(eid, 1) |
0 | 891 |
login = self.execute('Any L WHERE X login "admin", X identity Y, Y login L')[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
892 |
self.assertEqual(login, 'admin') |
0 | 893 |
|
894 |
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
|
895 |
rset = self.execute('Any X, TODAY - CD WHERE X is CWUser, X creation_date CD') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
896 |
self.assertTrue(rset) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
897 |
self.assertEqual(rset.description[0][1], 'Interval') |
0 | 898 |
eid, = self.execute("INSERT Personne X: X nom 'bidule'")[0] |
899 |
rset = self.execute('Any X, NOW - CD WHERE X is Personne, X creation_date CD') |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
900 |
self.assertEqual(rset.description[0][1], 'Interval') |
0 | 901 |
|
6050
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
902 |
def test_select_subquery_aggregat_1(self): |
0 | 903 |
# percent users by groups |
904 |
self.execute('SET X in_group G WHERE G name "users"') |
|
905 |
rset = self.execute('Any GN, COUNT(X)*100/T GROUPBY GN ORDERBY 2,1' |
|
906 |
' 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
|
907 |
' WITH T BEING (Any COUNT(U) WHERE U is CWUser)') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
908 |
self.assertEqual(rset.rows, [[u'guests', 50], [u'managers', 50], [u'users', 100]]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
909 |
self.assertEqual(rset.description, [('String', 'Int'), ('String', 'Int'), ('String', 'Int')]) |
0 | 910 |
|
6050
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
911 |
def test_select_subquery_aggregat_2(self): |
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
912 |
expected = self.execute('Any X, 0, COUNT(T) GROUPBY X ' |
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
913 |
'WHERE X is Workflow, T transition_of X').rows |
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
914 |
rset = self.execute(''' |
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
915 |
Any P1,B,E WHERE P1 identity P2 WITH |
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
916 |
P1,B BEING (Any P,COUNT(T) GROUPBY P WHERE P is Workflow, T is Transition, |
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
917 |
T? transition_of P, T type "auto"), |
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
918 |
P2,E BEING (Any P,COUNT(T) GROUPBY P WHERE P is Workflow, T is Transition, |
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
919 |
T? transition_of P, T type "normal")''') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
920 |
self.assertEqual(sorted(rset.rows), sorted(expected)) |
6050
20af96a6fffc
[rql2sql] add test for rql bug #37423, which triggered a cw bug fixed by this changeset (infinite loop with some queries...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
921 |
|
0 | 922 |
def test_select_subquery_const(self): |
923 |
rset = self.execute('Any X WITH X BEING ((Any NULL) UNION (Any "toto"))') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
924 |
self.assertEqual(rset.rows, [[None], ['toto']]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
925 |
self.assertEqual(rset.description, [(None,), ('String',)]) |
1787 | 926 |
|
0 | 927 |
# insertion queries tests ################################################# |
1787 | 928 |
|
0 | 929 |
def test_insert_is(self): |
930 |
eid, = self.execute("INSERT Personne X: X nom 'bidule'")[0] |
|
931 |
etype, = self.execute("Any TN WHERE X is T, X eid %s, T name TN" % eid)[0] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
932 |
self.assertEqual(etype, 'Personne') |
0 | 933 |
self.execute("INSERT Personne X: X nom 'managers'") |
1787 | 934 |
|
0 | 935 |
def test_insert_1(self): |
936 |
rset = self.execute("INSERT Personne X: X nom 'bidule'") |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
937 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
938 |
self.assertEqual(rset.description, [('Personne',)]) |
0 | 939 |
rset = self.execute('Personne X WHERE X nom "bidule"') |
940 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
941 |
self.assertEqual(rset.description, [('Personne',)]) |
0 | 942 |
|
943 |
def test_insert_1_multiple(self): |
|
944 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
945 |
self.execute("INSERT Personne X: X nom 'chouette'") |
|
946 |
rset = self.execute("INSERT Societe Y: Y nom N, P travaille Y WHERE P nom N") |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
947 |
self.assertEqual(len(rset.rows), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
948 |
self.assertEqual(rset.description, [('Societe',), ('Societe',)]) |
0 | 949 |
|
950 |
def test_insert_2(self): |
|
951 |
rset = self.execute("INSERT Personne X, Personne Y: X nom 'bidule', Y nom 'tutu'") |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
952 |
self.assertEqual(rset.description, [('Personne', 'Personne')]) |
0 | 953 |
rset = self.execute('Personne X WHERE X nom "bidule" or X nom "tutu"') |
954 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
955 |
self.assertEqual(rset.description, [('Personne',), ('Personne',)]) |
0 | 956 |
|
957 |
def test_insert_3(self): |
|
958 |
self.execute("INSERT Personne X: X nom Y WHERE U login 'admin', U login Y") |
|
959 |
rset = self.execute('Personne X WHERE X nom "admin"') |
|
960 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
961 |
self.assertEqual(rset.description, [('Personne',)]) |
0 | 962 |
|
963 |
def test_insert_4(self): |
|
964 |
self.execute("INSERT Societe Y: Y nom 'toto'") |
|
965 |
self.execute("INSERT Personne X: X nom 'bidule', X travaille Y WHERE Y nom 'toto'") |
|
966 |
rset = self.execute('Any X, Y WHERE X nom "bidule", Y nom "toto", X travaille Y') |
|
967 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
968 |
self.assertEqual(rset.description, [('Personne', 'Societe',)]) |
1787 | 969 |
|
0 | 970 |
def test_insert_4bis(self): |
971 |
peid = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
972 |
seid = self.execute("INSERT Societe Y: Y nom 'toto', X travaille Y WHERE X eid %(x)s", |
|
973 |
{'x': str(peid)})[0][0] |
|
974 |
self.assertEqual(len(self.execute('Any X, Y WHERE X travaille Y')), 1) |
|
975 |
self.execute("INSERT Personne X: X nom 'chouette', X travaille Y WHERE Y eid %(x)s", |
|
976 |
{'x': str(seid)}) |
|
977 |
self.assertEqual(len(self.execute('Any X, Y WHERE X travaille Y')), 2) |
|
1787 | 978 |
|
0 | 979 |
def test_insert_4ter(self): |
980 |
peid = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
981 |
seid = self.execute("INSERT Societe Y: Y nom 'toto', X travaille Y WHERE X eid %(x)s", |
|
982 |
{'x': unicode(peid)})[0][0] |
|
983 |
self.assertEqual(len(self.execute('Any X, Y WHERE X travaille Y')), 1) |
|
984 |
self.execute("INSERT Personne X: X nom 'chouette', X travaille Y WHERE Y eid %(x)s", |
|
985 |
{'x': unicode(seid)}) |
|
986 |
self.assertEqual(len(self.execute('Any X, Y WHERE X travaille Y')), 2) |
|
987 |
||
988 |
def test_insert_5(self): |
|
989 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
990 |
self.execute("INSERT Societe Y: Y nom 'toto', X travaille Y WHERE X nom 'bidule'") |
|
991 |
rset = self.execute('Any X, Y WHERE X nom "bidule", Y nom "toto", X travaille Y') |
|
992 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
993 |
self.assertEqual(rset.description, [('Personne', 'Societe',)]) |
0 | 994 |
|
4765 | 995 |
def test_insert_5bis(self): |
996 |
peid = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
997 |
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
|
998 |
{'x': peid}) |
4765 | 999 |
rset = self.execute('Any X, Y WHERE X nom "bidule", Y nom "toto", X travaille Y') |
1000 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1001 |
self.assertEqual(rset.description, [('Personne', 'Societe',)]) |
4765 | 1002 |
|
0 | 1003 |
def test_insert_6(self): |
1004 |
self.execute("INSERT Personne X, Societe Y: X nom 'bidule', Y nom 'toto', X travaille Y") |
|
1005 |
rset = self.execute('Any X, Y WHERE X nom "bidule", Y nom "toto", X travaille Y') |
|
1006 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1007 |
self.assertEqual(rset.description, [('Personne', 'Societe',)]) |
0 | 1008 |
|
1009 |
def test_insert_7(self): |
|
1010 |
self.execute("INSERT Personne X, Societe Y: X nom N, Y nom 'toto', X travaille Y WHERE U login 'admin', U login N") |
|
1011 |
rset = self.execute('Any X, Y WHERE X nom "admin", Y nom "toto", X travaille Y') |
|
1012 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1013 |
self.assertEqual(rset.description, [('Personne', 'Societe',)]) |
0 | 1014 |
|
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
|
1015 |
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
|
1016 |
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
|
1017 |
rset = self.execute('Any X, Y WHERE Y nom "toto", X travaille Y') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1018 |
self.assertEqual(len(rset), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1019 |
self.assertEqual(rset.description, [('Personne', 'Societe',), |
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
|
1020 |
('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
|
1021 |
|
0 | 1022 |
def test_insert_8(self): |
1023 |
self.execute("INSERT Societe Y, Personne X: Y nom N, X nom 'toto', X travaille Y WHERE U login 'admin', U login N") |
|
1024 |
rset = self.execute('Any X, Y WHERE X nom "toto", Y nom "admin", X travaille Y') |
|
1025 |
self.assert_(rset.rows) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1026 |
self.assertEqual(rset.description, [('Personne', 'Societe',)]) |
0 | 1027 |
|
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
|
1028 |
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
|
1029 |
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
|
1030 |
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
|
1031 |
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
|
1032 |
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") |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1033 |
self.assertEqual(len(rset), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1034 |
self.assertEqual(rset.description, [('Personne',), ('Personne',)]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1035 |
# self.assertSetEqual(set(x.nom for x in rset.entities()), |
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
|
1036 |
# ['Lo', 'Gi']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1037 |
# self.assertSetEqual(set(y.nom for x in rset.entities() for y in x.travaille), |
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
|
1038 |
# ['Lo', 'Gi']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1039 |
# self.assertEqual([y.nom for x in rset.entities() for y in x.travaille_subdivision], |
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
|
1040 |
# ['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
|
1041 |
|
0 | 1042 |
def test_insert_query_error(self): |
1043 |
self.assertRaises(Exception, |
|
1044 |
self.execute, |
|
1045 |
"INSERT Personne X: X nom 'toto', X is Personne") |
|
1046 |
self.assertRaises(Exception, |
|
1047 |
self.execute, |
|
1048 |
"INSERT Personne X: X nom 'toto', X is_instance_of Personne") |
|
1049 |
self.assertRaises(QueryError, |
|
1050 |
self.execute, |
|
1051 |
"INSERT Personne X: X nom 'toto', X has_text 'tutu'") |
|
1052 |
||
1053 |
self.assertRaises(QueryError, |
|
1054 |
self.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1055 |
"INSERT CWUser X: X login 'toto', X eid %s" % cnx.user(self.session).eid) |
0 | 1056 |
|
1057 |
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
|
1058 |
rset = self.execute('INSERT CWUser E, EmailAddress EM: E login "X", E upassword "X", ' |
0 | 1059 |
'E primary_email EM, EM address "X", E in_group G ' |
1060 |
'WHERE G name "managers"') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1061 |
self.assertEqual(list(rset.description[0]), ['CWUser', 'EmailAddress']) |
1787 | 1062 |
|
0 | 1063 |
# deletion queries tests ################################################## |
1064 |
||
1065 |
def test_delete_1(self): |
|
1066 |
self.execute("INSERT Personne Y: Y nom 'toto'") |
|
1067 |
rset = self.execute('Personne X WHERE X nom "toto"') |
|
1068 |
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
|
1069 |
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
|
1070 |
self.assertEqual(drset.rows, rset.rows) |
0 | 1071 |
rset = self.execute('Personne X WHERE X nom "toto"') |
1072 |
self.assertEqual(len(rset.rows), 0) |
|
1787 | 1073 |
|
0 | 1074 |
def test_delete_2(self): |
1075 |
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") |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1076 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1077 |
self.assertEqual(len(rset[0]), 3) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1078 |
self.assertEqual(rset.description[0], ('Personne', 'Personne', 'Societe')) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1079 |
self.assertEqual(self.execute('Any N WHERE X nom N, X eid %s'% rset[0][0])[0][0], 'syt') |
0 | 1080 |
rset = self.execute('Personne X WHERE X travaille Y, Y nom "Logilab"') |
1081 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
|
1082 |
self.execute("DELETE X travaille Y WHERE X is Personne, Y nom 'Logilabo'") |
|
1083 |
rset = self.execute('Personne X WHERE X travaille Y, Y nom "Logilab"') |
|
1084 |
self.assertEqual(len(rset.rows), 2, rset.rows) |
|
1085 |
self.execute("DELETE X travaille Y WHERE X is Personne, Y nom 'Logilab'") |
|
1086 |
rset = self.execute('Personne X WHERE X travaille Y, Y nom "Logilab"') |
|
1087 |
self.assertEqual(len(rset.rows), 0, rset.rows) |
|
1088 |
||
1089 |
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
|
1090 |
s = self.user_groups_session('users') |
0 | 1091 |
peid, = self.o.execute(s, "INSERT Personne P: P nom 'toto'")[0] |
1092 |
seid, = self.o.execute(s, "INSERT Societe S: S nom 'logilab'")[0] |
|
1093 |
self.o.execute(s, "SET P travaille S") |
|
1094 |
rset = self.execute('Personne P WHERE P travaille S') |
|
1095 |
self.assertEqual(len(rset.rows), 1) |
|
1096 |
self.execute("DELETE X travaille Y WHERE X eid %s, Y eid %s" % (peid, seid)) |
|
1097 |
rset = self.execute('Personne P WHERE P travaille S') |
|
1098 |
self.assertEqual(len(rset.rows), 0) |
|
1099 |
||
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
|
1100 |
def test_delete_symmetric(self): |
0 | 1101 |
teid1 = self.execute("INSERT Folder T: T name 'toto'")[0][0] |
1102 |
teid2 = self.execute("INSERT Folder T: T name 'tutu'")[0][0] |
|
1103 |
self.execute('SET X see_also Y WHERE X eid %s, Y eid %s' % (teid1, teid2)) |
|
1104 |
rset = self.execute('Any X,Y WHERE X see_also Y') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1105 |
self.assertEqual(len(rset) , 2, rset.rows) |
0 | 1106 |
self.execute('DELETE X see_also Y WHERE X eid %s, Y eid %s' % (teid1, teid2)) |
1107 |
rset = self.execute('Any X,Y WHERE X see_also Y') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1108 |
self.assertEqual(len(rset) , 0) |
0 | 1109 |
self.execute('SET X see_also Y WHERE X eid %s, Y eid %s' % (teid1, teid2)) |
1110 |
rset = self.execute('Any X,Y WHERE X see_also Y') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1111 |
self.assertEqual(len(rset) , 2) |
0 | 1112 |
self.execute('DELETE X see_also Y WHERE X eid %s, Y eid %s' % (teid2, teid1)) |
1113 |
rset = self.execute('Any X,Y WHERE X see_also Y') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1114 |
self.assertEqual(len(rset) , 0) |
0 | 1115 |
|
1116 |
def test_nonregr_delete_cache(self): |
|
1117 |
"""test that relations are properly cleaned when an entity is deleted |
|
1118 |
(using cachekey on sql generation returned always the same query for an eid, |
|
1119 |
whatever the relation) |
|
1120 |
""" |
|
8222
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
1121 |
aeid, = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')[0] |
0 | 1122 |
# XXX would be nice if the rql below was enough... |
1123 |
#'INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y' |
|
8222
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
1124 |
eeid, = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y WHERE Y is EmailAddress')[0] |
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
1125 |
self.execute("DELETE Email X") |
2a92f0ec881d
[test] fix test broken by EmailAddress read permissions change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8127
diff
changeset
|
1126 |
sqlc = self.session.cnxset['system'] |
0 | 1127 |
sqlc.execute('SELECT * FROM recipients_relation') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1128 |
self.assertEqual(len(sqlc.fetchall()), 0) |
0 | 1129 |
sqlc.execute('SELECT * FROM owned_by_relation WHERE eid_from=%s'%eeid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1130 |
self.assertEqual(len(sqlc.fetchall()), 0) |
1787 | 1131 |
|
0 | 1132 |
def test_nonregr_delete_cache2(self): |
1133 |
eid = self.execute("INSERT Folder T: T name 'toto'")[0][0] |
|
1134 |
self.commit() |
|
1135 |
# 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
|
1136 |
self.execute("Any X WHERE X eid %(x)s", {'x': eid}) |
6189 | 1137 |
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
|
1138 |
self.execute("Folder X WHERE X eid %(x)s", {'x': eid}) |
6189 | 1139 |
self.execute("Folder X WHERE X eid %s" % eid) |
1140 |
self.execute("DELETE Folder T WHERE T eid %s" % eid) |
|
0 | 1141 |
self.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4848
diff
changeset
|
1142 |
rset = self.execute("Any X WHERE X eid %(x)s", {'x': eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1143 |
self.assertEqual(rset.rows, []) |
6189 | 1144 |
rset = self.execute("Any X WHERE X eid %s" % eid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1145 |
self.assertEqual(rset.rows, []) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4848
diff
changeset
|
1146 |
rset = self.execute("Folder X WHERE X eid %(x)s", {'x': eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1147 |
self.assertEqual(rset.rows, []) |
0 | 1148 |
rset = self.execute("Folder X WHERE X eid %s" %eid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1149 |
self.assertEqual(rset.rows, []) |
1787 | 1150 |
|
0 | 1151 |
# update queries tests #################################################### |
1152 |
||
1153 |
def test_update_1(self): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
1154 |
peid = self.execute("INSERT Personne Y: Y nom 'toto'")[0][0] |
0 | 1155 |
rset = self.execute('Personne X WHERE X nom "toto"') |
1156 |
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
|
1157 |
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
|
1158 |
self.assertEqual(tuplify(rset.rows), [(peid, 'tutu', 'original')]) |
0 | 1159 |
rset = self.execute('Any Y, Z WHERE X is Personne, X nom Y, X prenom Z') |
1160 |
self.assertEqual(tuplify(rset.rows), [('tutu', 'original')]) |
|
1787 | 1161 |
|
0 | 1162 |
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
|
1163 |
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
|
1164 |
rset = self.execute("SET X travaille Y WHERE X nom 'bidule', Y nom 'toto'") |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1165 |
self.assertEqual(tuplify(rset.rows), [(peid, seid)]) |
0 | 1166 |
rset = self.execute('Any X, Y WHERE X travaille Y') |
1167 |
self.assertEqual(len(rset.rows), 1) |
|
1787 | 1168 |
|
0 | 1169 |
def test_update_2bis(self): |
1170 |
rset = self.execute("INSERT Personne X, Societe Y: X nom 'bidule', Y nom 'toto'") |
|
1171 |
eid1, eid2 = rset[0][0], rset[0][1] |
|
1172 |
self.execute("SET X travaille Y WHERE X eid %(x)s, Y eid %(y)s", |
|
1173 |
{'x': str(eid1), 'y': str(eid2)}) |
|
1174 |
rset = self.execute('Any X, Y WHERE X travaille Y') |
|
1175 |
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
|
1176 |
# test add of an existant relation but with NOT X rel Y protection |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
1177 |
self.assertFalse(self.execute("SET X travaille Y WHERE X eid %(x)s, Y eid %(y)s," |
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
|
1178 |
"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
|
1179 |
{'x': str(eid1), 'y': str(eid2)})) |
1787 | 1180 |
|
0 | 1181 |
def test_update_2ter(self): |
1182 |
rset = self.execute("INSERT Personne X, Societe Y: X nom 'bidule', Y nom 'toto'") |
|
1183 |
eid1, eid2 = rset[0][0], rset[0][1] |
|
1184 |
self.execute("SET X travaille Y WHERE X eid %(x)s, Y eid %(y)s", |
|
1185 |
{'x': unicode(eid1), 'y': unicode(eid2)}) |
|
1186 |
rset = self.execute('Any X, Y WHERE X travaille Y') |
|
1187 |
self.assertEqual(len(rset.rows), 1) |
|
1787 | 1188 |
|
0 | 1189 |
def test_update_multiple1(self): |
1190 |
peid1 = self.execute("INSERT Personne Y: Y nom 'tutu'")[0][0] |
|
1191 |
peid2 = self.execute("INSERT Personne Y: Y nom 'toto'")[0][0] |
|
1192 |
self.execute("SET X nom 'tutu', Y nom 'toto' WHERE X nom 'toto', Y nom 'tutu'") |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1193 |
self.assertEqual(self.execute('Any X WHERE X nom "toto"').rows, [[peid1]]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1194 |
self.assertEqual(self.execute('Any X WHERE X nom "tutu"').rows, [[peid2]]) |
0 | 1195 |
|
1196 |
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
|
1197 |
ueid = self.execute("INSERT CWUser X: X login 'bob', X upassword 'toto'")[0][0] |
0 | 1198 |
peid1 = self.execute("INSERT Personne Y: Y nom 'turlu'")[0][0] |
1199 |
peid2 = self.execute("INSERT Personne Y: Y nom 'tutu'")[0][0] |
|
1200 |
self.execute('SET P1 owned_by U, P2 owned_by U ' |
|
1201 |
'WHERE P1 eid %s, P2 eid %s, U eid %s' % (peid1, peid2, ueid)) |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
1202 |
self.assertTrue(self.execute('Any X WHERE X eid %s, X owned_by U, U eid %s' |
0 | 1203 |
% (peid1, ueid))) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7713
diff
changeset
|
1204 |
self.assertTrue(self.execute('Any X WHERE X eid %s, X owned_by U, U eid %s' |
0 | 1205 |
% (peid2, ueid))) |
1206 |
||
1207 |
def test_update_math_expr(self): |
|
1208 |
orders = [r[0] for r in self.execute('Any O ORDERBY O WHERE ST name "Personne", X from_entity ST, X ordernum O')] |
|
1209 |
for i,v in enumerate(orders): |
|
1210 |
if v != orders[0]: |
|
1211 |
splitidx = i |
|
1212 |
break |
|
1213 |
self.execute('SET X ordernum Y+1 WHERE X from_entity SE, SE name "Personne", X ordernum Y, X ordernum >= %(order)s', |
|
1214 |
{'order': orders[splitidx]}) |
|
1215 |
orders2 = [r[0] for r in self.execute('Any O ORDERBY O WHERE ST name "Personne", X from_entity ST, X ordernum O')] |
|
1216 |
orders = orders[:splitidx] + [o+1 for o in orders[splitidx:]] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1217 |
self.assertEqual(orders2, orders) |
0 | 1218 |
|
1219 |
def test_update_string_concat(self): |
|
1220 |
beid = self.execute("INSERT Bookmark Y: Y title 'toto', Y path '/view'")[0][0] |
|
1221 |
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
|
1222 |
newname = self.execute('Any XN WHERE X eid %(x)s, X title XN', {'x': beid})[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1223 |
self.assertEqual(newname, 'toto-moved') |
1787 | 1224 |
|
0 | 1225 |
def test_update_query_error(self): |
1226 |
self.execute("INSERT Personne Y: Y nom 'toto'") |
|
1227 |
self.assertRaises(Exception, self.execute, "SET X nom 'toto', X is Personne") |
|
1228 |
self.assertRaises(QueryError, self.execute, "SET X nom 'toto', X has_text 'tutu' WHERE X is Personne") |
|
1229 |
self.assertRaises(QueryError, self.execute, "SET X login 'tutu', X eid %s" % cnx.user(self.session).eid) |
|
1230 |
||
8018
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1231 |
# HAVING on write queries test ############################################# |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1232 |
|
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1233 |
def test_update_having(self): |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1234 |
peid1 = self.execute("INSERT Personne Y: Y nom 'hop', Y tel 1")[0][0] |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1235 |
peid2 = self.execute("INSERT Personne Y: Y nom 'hop', Y tel 2")[0][0] |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1236 |
rset = self.execute("SET X tel 3 WHERE X tel TEL HAVING TEL&1=1") |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1237 |
self.assertEqual(tuplify(rset.rows), [(peid1, 3)]) |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1238 |
|
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1239 |
def test_insert_having(self): |
8019
eb83c52ffa0c
[test] unittest2 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8018
diff
changeset
|
1240 |
self.skipTest('unsupported yet') |
8018
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1241 |
self.execute("INSERT Personne Y: Y nom 'hop', Y tel 1")[0][0] |
8021
25fbfd84529f
useless debugged breaks test with python < 2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8019
diff
changeset
|
1242 |
self.assertFalse(self.execute("INSERT Personne Y: Y nom 'hop', Y tel 2 WHERE X tel XT HAVING XT&2=2")) |
25fbfd84529f
useless debugged breaks test with python < 2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8019
diff
changeset
|
1243 |
self.assertTrue(self.execute("INSERT Personne Y: Y nom 'hop', Y tel 2 WHERE X tel XT HAVING XT&1=1")) |
8018
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1244 |
|
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1245 |
def test_delete_having(self): |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1246 |
self.execute("INSERT Personne Y: Y nom 'hop', Y tel 1")[0][0] |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1247 |
self.assertFalse(self.execute("DELETE Personne Y WHERE X tel XT HAVING XT&2=2")) |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1248 |
self.assertTrue(self.execute("DELETE Personne Y WHERE X tel XT HAVING XT&1=1")) |
f01c80513274
[rql] closes #2054468: support for HAVING in SET/DELETE queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8002
diff
changeset
|
1249 |
|
0 | 1250 |
# upassword encryption tests ################################################# |
1787 | 1251 |
|
0 | 1252 |
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
|
1253 |
rset = self.execute("INSERT CWUser X: X login 'bob', X upassword 'toto'") |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1254 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1255 |
self.assertEqual(rset.description, [('CWUser',)]) |
0 | 1256 |
self.assertRaises(Unauthorized, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1257 |
self.execute, "Any P WHERE X is CWUser, X login 'bob', X upassword P") |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7397
diff
changeset
|
1258 |
cursor = self.cnxset['system'] |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1259 |
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
|
1260 |
% (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
|
1261 |
passwd = str(cursor.fetchone()[0]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1262 |
self.assertEqual(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
|
1263 |
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
|
1264 |
{'pwd': Binary(passwd)}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1265 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1266 |
self.assertEqual(rset.description, [('CWUser',)]) |
1787 | 1267 |
|
0 | 1268 |
def test_update_upassword(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1269 |
rset = self.execute("INSERT CWUser X: X login 'bob', X upassword %(pwd)s", {'pwd': 'toto'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1270 |
self.assertEqual(rset.description[0][0], 'CWUser') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1271 |
rset = self.execute("SET X upassword %(pwd)s WHERE X is CWUser, X login 'bob'", |
0 | 1272 |
{'pwd': 'tutu'}) |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7397
diff
changeset
|
1273 |
cursor = self.cnxset['system'] |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1274 |
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
|
1275 |
% (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
|
1276 |
passwd = str(cursor.fetchone()[0]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1277 |
self.assertEqual(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
|
1278 |
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
|
1279 |
{'pwd': Binary(passwd)}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1280 |
self.assertEqual(len(rset.rows), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1281 |
self.assertEqual(rset.description, [('CWUser',)]) |
0 | 1282 |
|
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1283 |
# ZT datetime tests ######################################################## |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1284 |
|
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1285 |
def test_tz_datetime(self): |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1286 |
self.execute("INSERT Personne X: X nom 'bob', X tzdatenaiss %(date)s", |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1287 |
{'date': datetime(1977, 6, 7, 2, 0, tzinfo=FixedOffset(1))}) |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1288 |
datenaiss = self.execute("Any XD WHERE X nom 'bob', X tzdatenaiss XD")[0][0] |
7211
cacff15f847d
[timezone] ensure tzinfo is None
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7166
diff
changeset
|
1289 |
self.assertEqual(datenaiss.tzinfo, None) |
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1290 |
self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 1, 0)) |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1291 |
|
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7148
diff
changeset
|
1292 |
# non regression tests ##################################################### |
1787 | 1293 |
|
0 | 1294 |
def test_nonregr_1(self): |
1295 |
teid = self.execute("INSERT Tag X: X name 'tag'")[0][0] |
|
1296 |
self.execute("SET X tags Y WHERE X name 'tag', Y is State, Y name 'activated'") |
|
1297 |
rset = self.execute('Any X WHERE T tags X') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1298 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 1299 |
rset = self.execute('Any T WHERE T tags X, X is State') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1300 |
self.assertEqual(rset.rows, [[teid]]) |
0 | 1301 |
rset = self.execute('Any T WHERE T tags X') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1302 |
self.assertEqual(rset.rows, [[teid]]) |
0 | 1303 |
|
1304 |
def test_nonregr_2(self): |
|
1305 |
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
|
1306 |
geid = self.execute("CWGroup G WHERE G name 'users'")[0][0] |
0 | 1307 |
self.execute("SET X tags Y WHERE X eid %(t)s, Y eid %(g)s", |
1308 |
{'g': geid, 't': teid}) |
|
1309 |
rset = self.execute('Any X WHERE E eid %(x)s, E tags X', |
|
1310 |
{'x': teid}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1311 |
self.assertEqual(rset.rows, [[geid]]) |
1787 | 1312 |
|
0 | 1313 |
def test_nonregr_3(self): |
1314 |
"""bad sql generated on the second query (destination_state is not |
|
1315 |
detected as an inlined relation) |
|
1316 |
""" |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
1317 |
rset = self.execute('Any S,ES,T WHERE S state_of WF, WF workflow_of ET, ET name "CWUser",' |
0 | 1318 |
'ES allowed_transition T, T destination_state S') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1319 |
self.assertEqual(len(rset.rows), 2) |
0 | 1320 |
|
1321 |
def test_nonregr_4(self): |
|
1322 |
# fix variables'type, else we get (nb of entity types with a 'name' attribute)**3 |
|
1323 |
# union queries and that make for instance a 266Ko sql query which is refused |
|
1324 |
# by the server (or client lib) |
|
1325 |
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
|
1326 |
'ER is CWRType, SE is CWEType, OE is CWEType') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1327 |
self.assertEqual(len(rset), 1) |
0 | 1328 |
|
1329 |
def test_nonregr_5(self): |
|
1330 |
# jpl #15505: equivalent queries returning different result sets |
|
1331 |
teid1 = self.execute("INSERT Folder X: X name 'hop'")[0][0] |
|
1332 |
teid2 = self.execute("INSERT Folder X: X name 'hip'")[0][0] |
|
1333 |
neid = self.execute("INSERT Note X: X todo_by U, X filed_under T WHERE U login 'admin', T name 'hop'")[0][0] |
|
1334 |
weid = self.execute("INSERT Affaire X: X concerne N, X filed_under T WHERE N is Note, T name 'hip'")[0][0] |
|
1335 |
rset1 = self.execute('Any N,U WHERE N filed_under T, T eid %s,' |
|
1336 |
'N todo_by U, W concerne N,' |
|
1337 |
'W is Affaire, W filed_under A, A eid %s' % (teid1, teid2)) |
|
1338 |
rset2 = self.execute('Any N,U WHERE N filed_under T, T eid %s,' |
|
1339 |
'N todo_by U, W concerne N,' |
|
1340 |
'W filed_under A, A eid %s' % (teid1, teid2)) |
|
1341 |
rset3 = self.execute('Any N,U WHERE N todo_by U, T eid %s,' |
|
1342 |
'N filed_under T, W concerne N,' |
|
1343 |
'W is Affaire, W filed_under A, A eid %s' % (teid1, teid2)) |
|
1344 |
rset4 = self.execute('Any N,U WHERE N todo_by U, T eid %s,' |
|
1345 |
'N filed_under T, W concerne N,' |
|
1346 |
'W filed_under A, A eid %s' % (teid1, teid2)) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1347 |
self.assertEqual(rset1.rows, rset2.rows) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1348 |
self.assertEqual(rset1.rows, rset3.rows) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1349 |
self.assertEqual(rset1.rows, rset4.rows) |
1787 | 1350 |
|
0 | 1351 |
def test_nonregr_6(self): |
1352 |
self.execute('Any N,COUNT(S) GROUPBY N ORDERBY COUNT(N) WHERE S name N, S is State') |
|
1787 | 1353 |
|
0 | 1354 |
def test_sqlite_encoding(self): |
1355 |
"""XXX this test was trying to show a bug on use of lower which only |
|
1356 |
occurs with non ascii string and misconfigured locale |
|
1357 |
""" |
|
1358 |
self.execute("INSERT Tag X: X name %(name)s," |
|
1359 |
"X modification_date %(modification_date)s," |
|
1360 |
"X creation_date %(creation_date)s", |
|
1361 |
{'name': u'�name0', |
|
1362 |
'modification_date': '2003/03/12 11:00', |
|
1363 |
'creation_date': '2000/07/03 11:00'}) |
|
1364 |
rset = self.execute('Any lower(N) ORDERBY LOWER(N) WHERE X is Tag, X name N,' |
|
1365 |
'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
|
1366 |
{'x':self.session.user.eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1367 |
self.assertEqual(rset.rows, [[u'\xe9name0']]) |
0 | 1368 |
|
1369 |
||
1370 |
def test_nonregr_description(self): |
|
1371 |
"""check that a correct description is built in case where infered |
|
1372 |
solutions may be "fusionned" into one by the querier while all solutions |
|
1373 |
are needed to build the result's description |
|
1374 |
""" |
|
1375 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
1376 |
self.execute("INSERT Societe Y: Y nom 'toto'") |
|
1377 |
beid = self.execute("INSERT Basket B: B name 'mybasket'")[0][0] |
|
1378 |
self.execute("SET X in_basket B WHERE X is Personne") |
|
1379 |
self.execute("SET X in_basket B WHERE X is Societe") |
|
1380 |
rset = self.execute('Any X WHERE X in_basket B, B eid %s' % beid) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1381 |
self.assertEqual(len(rset), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1382 |
self.assertEqual(rset.description, [('Personne',), ('Societe',)]) |
0 | 1383 |
|
1384 |
||
1385 |
def test_nonregr_cache_1(self): |
|
1386 |
peid = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
1387 |
beid = self.execute("INSERT Basket X: X name 'tag'")[0][0] |
|
1388 |
self.execute("SET X in_basket Y WHERE X is Personne, Y eid %(y)s", |
|
1389 |
{'y': beid}) |
|
1390 |
rset = self.execute("Any X WHERE X in_basket B, B eid %(x)s", |
|
1391 |
{'x': beid}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1392 |
self.assertEqual(rset.rows, [[peid]]) |
0 | 1393 |
rset = self.execute("Any X WHERE X in_basket B, B eid %(x)s", |
1394 |
{'x': beid}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1395 |
self.assertEqual(rset.rows, [[peid]]) |
0 | 1396 |
|
1397 |
def test_nonregr_has_text_cache(self): |
|
1398 |
eid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
|
1399 |
eid2 = self.execute("INSERT Personne X: X nom 'tag'")[0][0] |
|
1400 |
self.commit() |
|
1401 |
rset = self.execute("Any X WHERE X has_text %(text)s", {'text': 'bidule'}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1402 |
self.assertEqual(rset.rows, [[eid1]]) |
0 | 1403 |
rset = self.execute("Any X WHERE X has_text %(text)s", {'text': 'tag'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1404 |
self.assertEqual(rset.rows, [[eid2]]) |
0 | 1405 |
|
1406 |
def test_nonregr_sortterm_management(self): |
|
1407 |
"""Error: Variable has no attribute 'sql' in rql2sql.py (visit_variable) |
|
1408 |
||
1409 |
cause: old variable ref inserted into a fresh rqlst copy |
|
1410 |
(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
|
1411 |
|
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
|
1412 |
need sqlite including http://www.sqlite.org/cvstrac/tktview?tn=3773 fix |
0 | 1413 |
""" |
1414 |
self.execute('Any X ORDERBY D DESC WHERE X creation_date D') |
|
1787 | 1415 |
|
0 | 1416 |
def test_nonregr_extra_joins(self): |
1417 |
ueid = self.session.user.eid |
|
1418 |
teid1 = self.execute("INSERT Folder X: X name 'folder1'")[0][0] |
|
1419 |
teid2 = self.execute("INSERT Folder X: X name 'folder2'")[0][0] |
|
1420 |
neid1 = self.execute("INSERT Note X: X para 'note1'")[0][0] |
|
1421 |
neid2 = self.execute("INSERT Note X: X para 'note2'")[0][0] |
|
1422 |
self.execute("SET X filed_under Y WHERE X eid %s, Y eid %s" |
|
1423 |
% (neid1, teid1)) |
|
1424 |
self.execute("SET X filed_under Y WHERE X eid %s, Y eid %s" |
|
1425 |
% (neid2, teid2)) |
|
1426 |
self.execute("SET X todo_by Y WHERE X is Note, Y eid %s" % ueid) |
|
1427 |
rset = self.execute('Any N WHERE N todo_by U, N is Note, U eid %s, N filed_under T, T eid %s' |
|
1428 |
% (ueid, teid1)) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1429 |
self.assertEqual(len(rset), 1) |
0 | 1430 |
|
1431 |
def test_nonregr_XXX(self): |
|
1432 |
teid = self.execute('Transition S WHERE S name "deactivate"')[0][0] |
|
1433 |
rset = self.execute('Any O WHERE O is State, ' |
|
1434 |
'S eid %(x)s, S transition_of ET, O state_of ET', {'x': teid}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1435 |
self.assertEqual(len(rset), 2) |
0 | 1436 |
rset = self.execute('Any O WHERE O is State, NOT S destination_state O, ' |
1437 |
'S eid %(x)s, S transition_of ET, O state_of ET', {'x': teid}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1438 |
self.assertEqual(len(rset), 1) |
0 | 1439 |
|
1440 |
||
1441 |
def test_nonregr_set_datetime(self): |
|
1442 |
# huum, psycopg specific |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
439
diff
changeset
|
1443 |
self.execute('SET X creation_date %(date)s WHERE X eid 1', {'date': date.today()}) |
0 | 1444 |
|
1445 |
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
|
1446 |
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
|
1447 |
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
|
1448 |
"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
|
1449 |
{'x':ueid, 'firstname': u'jean', 'surname': u'paul'}) |
1787 | 1450 |
|
0 | 1451 |
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
|
1452 |
ueid = self.execute("INSERT CWUser X: X login 'bob', X upassword 'toto', X in_group G " |
0 | 1453 |
"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
|
1454 |
rset = self.execute("CWUser U") |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1455 |
self.assertEqual(len(rset), 3) # bob + admin + anon |
0 | 1456 |
rset = self.execute("Any U WHERE NOT U owned_by U") |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1457 |
self.assertEqual(len(rset), 0) # even admin created at repo initialization time should belong to itself |
0 | 1458 |
|
1459 |
def test_nonreg_update_index(self): |
|
1460 |
# this is the kind of queries generated by "cubicweb-ctl db-check -ry" |
|
1461 |
self.execute("SET X description D WHERE X is State, X description D") |
|
1462 |
||
1463 |
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
|
1464 |
uteid = self.execute('Any ET WHERE ET name "CWUser"')[0][0] |
0 | 1465 |
self.execute('Any X, ET WHERE X is ET, ET eid %s' % uteid) |
1466 |
||
1467 |
def test_nonregr_orderby(self): |
|
1468 |
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
|
1469 |
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 | 1470 |
|
1471 |
def test_nonregr_solution_cache(self): |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1472 |
self.skipTest('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
|
1473 |
rset = self.execute('Any X WHERE X is CWUser, X eid %(x)s', {'x':self.ueid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1474 |
self.assertEqual(len(rset), 1) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1475 |
rset = self.execute('Any X WHERE X is CWUser, X eid %(x)s', {'x':12345}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6209
diff
changeset
|
1476 |
self.assertEqual(len(rset), 0) |
0 | 1477 |
|
1478 |
def test_nonregr_final_norestr(self): |
|
1479 |
self.assertRaises(BadRQLQuery, self.execute, 'Date X') |
|
1480 |
||
7394
d11d88bd08e8
[rql2sql] fix generated sql for eid comparison. closes #1638695
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7211
diff
changeset
|
1481 |
def test_nonregr_eid_cmp(self): |
d11d88bd08e8
[rql2sql] fix generated sql for eid comparison. closes #1638695
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7211
diff
changeset
|
1482 |
peid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
d11d88bd08e8
[rql2sql] fix generated sql for eid comparison. closes #1638695
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7211
diff
changeset
|
1483 |
peid2 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0] |
d11d88bd08e8
[rql2sql] fix generated sql for eid comparison. closes #1638695
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7211
diff
changeset
|
1484 |
rset = self.execute('Any X,Y WHERE X is Personne, Y is Personne, X nom XD, Y nom XD, X eid Z, Y eid > Z') |
d11d88bd08e8
[rql2sql] fix generated sql for eid comparison. closes #1638695
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7211
diff
changeset
|
1485 |
self.assertEqual(rset.rows, [[peid1, peid2]]) |
d11d88bd08e8
[rql2sql] fix generated sql for eid comparison. closes #1638695
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7211
diff
changeset
|
1486 |
rset = self.execute('Any X,Y WHERE X nom XD, Y nom XD, X eid Z, Y eid > Z') |
d11d88bd08e8
[rql2sql] fix generated sql for eid comparison. closes #1638695
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7211
diff
changeset
|
1487 |
self.assertEqual(rset.rows, [[peid1, peid2]]) |
0 | 1488 |
|
7523
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1489 |
def test_nonregr_has_text_ambiguity_1(self): |
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1490 |
peid = self.execute("INSERT CWUser X: X login 'bidule', X upassword 'bidule', X in_group G WHERE G name 'users'")[0][0] |
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1491 |
aeid = self.execute("INSERT Affaire X: X ref 'bidule'")[0][0] |
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1492 |
self.commit() |
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1493 |
rset = self.execute('Any X WHERE X is CWUser, X has_text "bidule"') |
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1494 |
self.assertEqual(rset.rows, [[peid]]) |
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1495 |
rset = self.execute('Any X WHERE X is CWUser, X has_text "bidule", X in_state S, S name SN') |
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1496 |
self.assertEqual(rset.rows, [[peid]]) |
f6856231cc51
[rql annotation] fix bad invariant variable w/ has_text relation: this is only true when has_text will be used as principal (though we don't know that yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7394
diff
changeset
|
1497 |
|
8127
96d343a5e01b
[rql2sql] None for attributes in kwargs generate IS NULL, so should be considered in sql cache key. Closes #2116693
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8111
diff
changeset
|
1498 |
|
96d343a5e01b
[rql2sql] None for attributes in kwargs generate IS NULL, so should be considered in sql cache key. Closes #2116693
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8111
diff
changeset
|
1499 |
def test_nonregr_sql_cache(self): |
96d343a5e01b
[rql2sql] None for attributes in kwargs generate IS NULL, so should be considered in sql cache key. Closes #2116693
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8111
diff
changeset
|
1500 |
# different SQL generated when 'name' is None or not (IS NULL). |
96d343a5e01b
[rql2sql] None for attributes in kwargs generate IS NULL, so should be considered in sql cache key. Closes #2116693
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8111
diff
changeset
|
1501 |
self.assertFalse(self.execute('Any X WHERE X is CWEType, X name %(name)s', {'name': None})) |
96d343a5e01b
[rql2sql] None for attributes in kwargs generate IS NULL, so should be considered in sql cache key. Closes #2116693
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8111
diff
changeset
|
1502 |
self.assertTrue(self.execute('Any X WHERE X is CWEType, X name %(name)s', {'name': 'CWEType'})) |
96d343a5e01b
[rql2sql] None for attributes in kwargs generate IS NULL, so should be considered in sql cache key. Closes #2116693
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8111
diff
changeset
|
1503 |
|
0 | 1504 |
if __name__ == '__main__': |
1505 |
unittest_main() |