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