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