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