author | Rémi Cardona <remi.cardona@logilab.fr> |
Fri, 11 Sep 2015 18:01:36 +0200 | |
changeset 10665 | 79ff784cd8af |
parent 10612 | 84468b90e9c1 |
child 10691 | af266f27c4d5 |
permissions | -rw-r--r-- |
0 | 1 |
# coding: utf-8 |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
2 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
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:
4951
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6366 | 19 |
"""unit tests for module cubicweb.utils""" |
4536
02d0803a60b8
cleanup 2.5 __future__ imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4461
diff
changeset
|
20 |
|
10612
84468b90e9c1
[py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
21 |
from six import string_types |
10602
4845012cfc8e
[py3k] import 'pickle' using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10600
diff
changeset
|
22 |
from six.moves import cPickle as pickle |
10603
65ad6980976e
[py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10602
diff
changeset
|
23 |
from six.moves.urllib.parse import urlsplit |
4536
02d0803a60b8
cleanup 2.5 __future__ imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4461
diff
changeset
|
24 |
|
02d0803a60b8
cleanup 2.5 __future__ imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4461
diff
changeset
|
25 |
from rql import parse |
0 | 26 |
|
4850
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
27 |
from logilab.common.testlib import TestCase, unittest_main, mock_object |
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
572
diff
changeset
|
28 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
29 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 30 |
from cubicweb.rset import NotAnEntity, ResultSet, attr_desc_iterator |
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
31 |
from cubicweb import NoResultError, MultipleResultsError |
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
32 |
|
1640 | 33 |
|
0 | 34 |
def pprelcachedict(d): |
35 |
res = {} |
|
36 |
for k, (rset, related) in d.items(): |
|
37 |
res[k] = sorted(v.eid for v in related) |
|
38 |
return sorted(res.items()) |
|
1640 | 39 |
|
0 | 40 |
|
41 |
class AttrDescIteratorTC(TestCase): |
|
42 |
"""TestCase for cubicweb.rset.attr_desc_iterator""" |
|
1640 | 43 |
|
0 | 44 |
def test_relations_description(self): |
45 |
"""tests relations_description() function""" |
|
46 |
queries = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
47 |
'Any U,L,M where U is CWUser, U login L, U mail M' : [(1, 'login', 'subject'), (2, 'mail', 'subject')], |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
48 |
'Any U,L,M where U is CWUser, L is Foo, U mail M' : [(2, 'mail', 'subject')], |
0 | 49 |
'Any C,P where C is Company, C employs P' : [(1, 'employs', 'subject')], |
50 |
'Any C,P where C is Company, P employed_by P' : [], |
|
51 |
'Any C where C is Company, C employs P' : [], |
|
52 |
} |
|
53 |
for rql, relations in queries.items(): |
|
6915
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
54 |
result = list(attr_desc_iterator(parse(rql).children[0], 0, 0)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
55 |
self.assertEqual((rql, result), (rql, relations)) |
1640 | 56 |
|
0 | 57 |
def test_relations_description_indexed(self): |
58 |
"""tests relations_description() function""" |
|
59 |
queries = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
60 |
'Any C,U,P,L,M where C is Company, C employs P, U is CWUser, U login L, U mail M' : |
0 | 61 |
{0: [(2,'employs', 'subject')], 1: [(3,'login', 'subject'), (4,'mail', 'subject')]}, |
62 |
} |
|
63 |
for rql, results in queries.items(): |
|
6915
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
64 |
for idx, relations in results.items(): |
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
65 |
result = list(attr_desc_iterator(parse(rql).children[0], idx, idx)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
66 |
self.assertEqual(result, relations) |
0 | 67 |
|
7395
09ffcc04bd21
[rset] close #1683703: rset.get_entity crash on rql query with subquery and aggregat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7298
diff
changeset
|
68 |
def test_subquery_callfunc(self): |
09ffcc04bd21
[rset] close #1683703: rset.get_entity crash on rql query with subquery and aggregat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7298
diff
changeset
|
69 |
rql = ('Any A,B,C,COUNT(D) GROUPBY A,B,C WITH A,B,C,D BEING ' |
09ffcc04bd21
[rset] close #1683703: rset.get_entity crash on rql query with subquery and aggregat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7298
diff
changeset
|
70 |
'(Any YEAR(CD), MONTH(CD), S, X WHERE X is CWUser, X creation_date CD, X in_state S)') |
09ffcc04bd21
[rset] close #1683703: rset.get_entity crash on rql query with subquery and aggregat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7298
diff
changeset
|
71 |
rqlst = parse(rql) |
09ffcc04bd21
[rset] close #1683703: rset.get_entity crash on rql query with subquery and aggregat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7298
diff
changeset
|
72 |
select, col = rqlst.locate_subquery(2, 'CWUser', None) |
09ffcc04bd21
[rset] close #1683703: rset.get_entity crash on rql query with subquery and aggregat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7298
diff
changeset
|
73 |
result = list(attr_desc_iterator(select, col, 2)) |
09ffcc04bd21
[rset] close #1683703: rset.get_entity crash on rql query with subquery and aggregat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7298
diff
changeset
|
74 |
self.assertEqual(result, []) |
0 | 75 |
|
8085
51929d531aff
[rset] fix crash while building entity from rset w/ some subquery. Closes #2089055
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8048
diff
changeset
|
76 |
def test_subquery_callfunc_2(self): |
51929d531aff
[rset] fix crash while building entity from rset w/ some subquery. Closes #2089055
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8048
diff
changeset
|
77 |
rql = ('Any X,S,L WHERE X in_state S WITH X, L BEING (Any X,MAX(L) GROUPBY X WHERE X is CWUser, T wf_info_for X, T creation_date L)') |
51929d531aff
[rset] fix crash while building entity from rset w/ some subquery. Closes #2089055
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8048
diff
changeset
|
78 |
rqlst = parse(rql) |
51929d531aff
[rset] fix crash while building entity from rset w/ some subquery. Closes #2089055
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8048
diff
changeset
|
79 |
select, col = rqlst.locate_subquery(0, 'CWUser', None) |
51929d531aff
[rset] fix crash while building entity from rset w/ some subquery. Closes #2089055
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8048
diff
changeset
|
80 |
result = list(attr_desc_iterator(select, col, 0)) |
51929d531aff
[rset] fix crash while building entity from rset w/ some subquery. Closes #2089055
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8048
diff
changeset
|
81 |
self.assertEqual(result, [(1, 'in_state', 'subject')]) |
51929d531aff
[rset] fix crash while building entity from rset w/ some subquery. Closes #2089055
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8048
diff
changeset
|
82 |
|
0 | 83 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
84 |
class ResultSetTC(CubicWebTC): |
0 | 85 |
|
86 |
def setUp(self): |
|
87 |
super(ResultSetTC, self).setUp() |
|
88 |
self.rset = ResultSet([[12, 'adim'], [13, 'syt']], |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
89 |
'Any U,L where U is CWUser, U login L', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
90 |
description=[['CWUser', 'String'], ['Bar', 'String']]) |
4850
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
91 |
self.rset.req = mock_object(vreg=self.vreg) |
0 | 92 |
|
93 |
def compare_urls(self, url1, url2): |
|
94 |
info1 = urlsplit(url1) |
|
95 |
info2 = urlsplit(url2) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
96 |
self.assertEqual(info1[:3], info2[:3]) |
0 | 97 |
if info1[3] != info2[3]: |
98 |
params1 = dict(pair.split('=') for pair in info1[3].split('&')) |
|
99 |
params2 = dict(pair.split('=') for pair in info1[3].split('&')) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
100 |
self.assertDictEqual(params1, params2) |
0 | 101 |
|
5740
46207f491a51
[rset] make rsets picklable (again ?) #1056422
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5667
diff
changeset
|
102 |
def test_pickle(self): |
5747
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5740
diff
changeset
|
103 |
del self.rset.req |
10602
4845012cfc8e
[py3k] import 'pickle' using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10600
diff
changeset
|
104 |
# 373 for python 2.7's cPickle |
4845012cfc8e
[py3k] import 'pickle' using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10600
diff
changeset
|
105 |
# 376 for the old python pickle implementation |
4845012cfc8e
[py3k] import 'pickle' using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10600
diff
changeset
|
106 |
self.assertIn(len(pickle.dumps(self.rset)), (373, 376)) |
1640 | 107 |
|
0 | 108 |
def test_build_url(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
109 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
110 |
baseurl = req.base_url() |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
111 |
self.compare_urls(req.build_url('view', vid='foo', rql='yo'), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
112 |
'%sview?vid=foo&rql=yo' % baseurl) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
113 |
self.compare_urls(req.build_url('view', _restpath='task/title/go'), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
114 |
'%stask/title/go' % baseurl) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
115 |
#self.compare_urls(req.build_url('view', _restpath='/task/title/go'), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
116 |
# '%stask/title/go' % baseurl) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
117 |
# empty _restpath should not crash |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
118 |
self.compare_urls(req.build_url('view', _restpath=''), baseurl) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
119 |
self.assertNotIn('https', req.build_url('view', vid='foo', rql='yo', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
120 |
__secure__=True)) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
121 |
try: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
122 |
self.config.global_set_option('https-url', 'https://testing.fr/') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
123 |
self.assertTrue('https', req.build_url('view', vid='foo', rql='yo', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
124 |
__secure__=True)) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
125 |
self.compare_urls(req.build_url('view', vid='foo', rql='yo', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
126 |
__secure__=True), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
127 |
'%sview?vid=foo&rql=yo' % req.base_url(secure=True)) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
128 |
finally: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
129 |
self.config.global_set_option('https-url', None) |
1640 | 130 |
|
131 |
||
8048
10a0f73d834d
[rset] replace entity cw_rset on .limit(inplace=True) will avoid pb if the entity is still referenced by some other entity relations cache. Closes #2065643
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7395
diff
changeset
|
132 |
def test_build(self): |
0 | 133 |
"""test basic build of a ResultSet""" |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
134 |
rs = ResultSet([1,2,3], 'CWGroup X', description=['CWGroup', 'CWGroup', 'CWGroup']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
135 |
self.assertEqual(rs.rowcount, 3) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
136 |
self.assertEqual(rs.rows, [1,2,3]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
137 |
self.assertEqual(rs.description, ['CWGroup', 'CWGroup', 'CWGroup']) |
0 | 138 |
|
139 |
||
8048
10a0f73d834d
[rset] replace entity cw_rset on .limit(inplace=True) will avoid pb if the entity is still referenced by some other entity relations cache. Closes #2065643
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7395
diff
changeset
|
140 |
def test_limit(self): |
0 | 141 |
rs = ResultSet([[12000, 'adim'], [13000, 'syt'], [14000, 'nico']], |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
142 |
'Any U,L where U is CWUser, U login L', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
143 |
description=[['CWUser', 'String']] * 3) |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
144 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
145 |
rs.req = req |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
146 |
rs.vreg = self.vreg |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
147 |
self.assertEqual(rs.limit(2).rows, [[12000, 'adim'], [13000, 'syt']]) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
148 |
rs2 = rs.limit(2, offset=1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
149 |
self.assertEqual(rs2.rows, [[13000, 'syt'], [14000, 'nico']]) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
150 |
self.assertEqual(rs2.get_entity(0, 0).cw_row, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
151 |
self.assertEqual(rs.limit(2, offset=2).rows, [[14000, 'nico']]) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
152 |
self.assertEqual(rs.limit(2, offset=3).rows, []) |
1640 | 153 |
|
8048
10a0f73d834d
[rset] replace entity cw_rset on .limit(inplace=True) will avoid pb if the entity is still referenced by some other entity relations cache. Closes #2065643
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7395
diff
changeset
|
154 |
def test_limit_2(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
155 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
156 |
# drop user from cache for the sake of this test |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
157 |
req.drop_entity_cache(req.user.eid) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
158 |
rs = req.execute('Any E,U WHERE E is CWEType, E created_by U') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
159 |
# get entity on row 9. This will fill its created_by relation cache, |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
160 |
# with cwuser on row 9 as well |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
161 |
e1 = rs.get_entity(9, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
162 |
# get entity on row 10. This will fill its created_by relation cache, |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
163 |
# with cwuser built on row 9 |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
164 |
e2 = rs.get_entity(10, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
165 |
# limit result set from row 10 |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
166 |
rs.limit(1, 10, inplace=True) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
167 |
# get back eid |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
168 |
e = rs.get_entity(0, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
169 |
self.assertTrue(e2 is e) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
170 |
# rs.limit has properly removed cwuser for request cache, but it's |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
171 |
# still referenced by e/e2 relation cache |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
172 |
u = e.created_by[0] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
173 |
# now ensure this doesn't trigger IndexError because cwuser.cw_row is 9 |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
174 |
# while now rset has only one row |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
175 |
u.cw_rset[u.cw_row] |
0 | 176 |
|
8048
10a0f73d834d
[rset] replace entity cw_rset on .limit(inplace=True) will avoid pb if the entity is still referenced by some other entity relations cache. Closes #2065643
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7395
diff
changeset
|
177 |
def test_filter(self): |
0 | 178 |
rs = ResultSet([[12000, 'adim'], [13000, 'syt'], [14000, 'nico']], |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
179 |
'Any U,L where U is CWUser, U login L', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
180 |
description=[['CWUser', 'String']] * 3) |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
181 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
182 |
rs.req = req |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
183 |
rs.vreg = self.vreg |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
184 |
def test_filter(entity): |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
185 |
return entity.login != 'nico' |
1640 | 186 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
187 |
rs2 = rs.filtered_rset(test_filter) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
188 |
self.assertEqual(len(rs2), 2) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
189 |
self.assertEqual([login for _, login in rs2], ['adim', 'syt']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
190 |
self.assertEqual(rs2.description, rs.description[1:]) |
1640 | 191 |
|
8048
10a0f73d834d
[rset] replace entity cw_rset on .limit(inplace=True) will avoid pb if the entity is still referenced by some other entity relations cache. Closes #2065643
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7395
diff
changeset
|
192 |
def test_transform(self): |
0 | 193 |
rs = ResultSet([[12, 'adim'], [13, 'syt'], [14, 'nico']], |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
194 |
'Any U,L where U is CWUser, U login L', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
195 |
description=[['CWUser', 'String']] * 3) |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
196 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
197 |
rs.req = req |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
198 |
def test_transform(row, desc): |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
199 |
return row[1:], desc[1:] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
200 |
rs2 = rs.transformed_rset(test_transform) |
0 | 201 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
202 |
self.assertEqual(len(rs2), 3) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
203 |
self.assertEqual(list(rs2), [['adim'],['syt'],['nico']]) |
1640 | 204 |
|
8048
10a0f73d834d
[rset] replace entity cw_rset on .limit(inplace=True) will avoid pb if the entity is still referenced by some other entity relations cache. Closes #2065643
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7395
diff
changeset
|
205 |
def test_sort(self): |
0 | 206 |
rs = ResultSet([[12000, 'adim'], [13000, 'syt'], [14000, 'nico']], |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
207 |
'Any U,L where U is CWUser, U login L', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
208 |
description=[['CWUser', 'String']] * 3) |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
209 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
210 |
rs.req = req |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
211 |
rs.vreg = self.vreg |
1640 | 212 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
213 |
rs2 = rs.sorted_rset(lambda e:e.cw_attr_cache['login']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
214 |
self.assertEqual(len(rs2), 3) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
215 |
self.assertEqual([login for _, login in rs2], ['adim', 'nico', 'syt']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
216 |
# make sure rs is unchanged |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
217 |
self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico']) |
1640 | 218 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
219 |
rs2 = rs.sorted_rset(lambda e:e.cw_attr_cache['login'], reverse=True) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
220 |
self.assertEqual(len(rs2), 3) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
221 |
self.assertEqual([login for _, login in rs2], ['syt', 'nico', 'adim']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
222 |
# make sure rs is unchanged |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
223 |
self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico']) |
0 | 224 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
225 |
rs3 = rs.sorted_rset(lambda row: row[1], col=-1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
226 |
self.assertEqual(len(rs3), 3) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
227 |
self.assertEqual([login for _, login in rs3], ['adim', 'nico', 'syt']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
228 |
# make sure rs is unchanged |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
229 |
self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico']) |
0 | 230 |
|
8048
10a0f73d834d
[rset] replace entity cw_rset on .limit(inplace=True) will avoid pb if the entity is still referenced by some other entity relations cache. Closes #2065643
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7395
diff
changeset
|
231 |
def test_split(self): |
0 | 232 |
rs = ResultSet([[12000, 'adim', u'Adim chez les pinguins'], |
233 |
[12000, 'adim', u'Jardiner facile'], |
|
234 |
[13000, 'syt', u'Le carrelage en 42 leçons'], |
|
235 |
[14000, 'nico', u'La tarte tatin en 15 minutes'], |
|
236 |
[14000, 'nico', u"L'épluchage du castor commun"]], |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
237 |
'Any U, L, T WHERE U is CWUser, U login L,'\ |
0 | 238 |
'D created_by U, D title T', |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
239 |
description=[['CWUser', 'String', 'String']] * 5) |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
240 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
241 |
rs.req = req |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
242 |
rs.vreg = self.vreg |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
243 |
rsets = rs.split_rset(lambda e:e.cw_attr_cache['login']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
244 |
self.assertEqual(len(rsets), 3) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
245 |
self.assertEqual([login for _, login,_ in rsets[0]], ['adim', 'adim']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
246 |
self.assertEqual([login for _, login,_ in rsets[1]], ['syt']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
247 |
self.assertEqual([login for _, login,_ in rsets[2]], ['nico', 'nico']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
248 |
# make sure rs is unchanged |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
249 |
self.assertEqual([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico']) |
1640 | 250 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
251 |
rsets = rs.split_rset(lambda e:e.cw_attr_cache['login'], return_dict=True) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
252 |
self.assertEqual(len(rsets), 3) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
253 |
self.assertEqual([login for _, login,_ in rsets['nico']], ['nico', 'nico']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
254 |
self.assertEqual([login for _, login,_ in rsets['adim']], ['adim', 'adim']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
255 |
self.assertEqual([login for _, login,_ in rsets['syt']], ['syt']) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
256 |
# make sure rs is unchanged |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
257 |
self.assertEqual([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico']) |
0 | 258 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
259 |
rsets = rs.split_rset(lambda s: s.count('d'), col=2) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
260 |
self.assertEqual(len(rsets), 2) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
261 |
self.assertEqual([title for _, _, title in rsets[0]], |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
262 |
[u"Adim chez les pinguins", |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
263 |
u"Jardiner facile", |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
264 |
u"L'épluchage du castor commun",]) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
265 |
self.assertEqual([title for _, _, title in rsets[1]], |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
266 |
[u"Le carrelage en 42 leçons", |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
267 |
u"La tarte tatin en 15 minutes",]) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
268 |
# make sure rs is unchanged |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
269 |
self.assertEqual([title for _, _, title in rs], |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
270 |
[u'Adim chez les pinguins', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
271 |
u'Jardiner facile', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
272 |
u'Le carrelage en 42 leçons', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
273 |
u'La tarte tatin en 15 minutes', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
274 |
u"L'épluchage du castor commun"]) |
1640 | 275 |
|
0 | 276 |
def test_cached_syntax_tree(self): |
277 |
"""make sure syntax tree is cached""" |
|
278 |
rqlst1 = self.rset.syntax_tree() |
|
279 |
rqlst2 = self.rset.syntax_tree() |
|
10600
180aa08cad48
[tests] Replace use of deprecated TestCase.assert_
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10187
diff
changeset
|
280 |
self.assertIs(rqlst1, rqlst2) |
0 | 281 |
|
282 |
def test_get_entity_simple(self): |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
283 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
284 |
req.create_entity('CWUser', login=u'adim', upassword='adim', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
285 |
surname=u'di mascio', firstname=u'adrien') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
286 |
req.cnx.drop_entity_cache() |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
287 |
e = req.execute('Any X,T WHERE X login "adim", X surname T').get_entity(0, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
288 |
self.assertEqual(e.cw_attr_cache['surname'], 'di mascio') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
289 |
self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'firstname') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
290 |
self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'creation_date') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
291 |
self.assertEqual(pprelcachedict(e._cw_related_cache), []) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
292 |
e.complete() |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
293 |
self.assertEqual(e.cw_attr_cache['firstname'], 'adrien') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
294 |
self.assertEqual(pprelcachedict(e._cw_related_cache), []) |
1640 | 295 |
|
0 | 296 |
def test_get_entity_advanced(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
297 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
298 |
req.create_entity('Bookmark', title=u'zou', path=u'/view') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
299 |
req.cnx.drop_entity_cache() |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
300 |
req.execute('SET X bookmarked_by Y WHERE X is Bookmark, Y login "anon"') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
301 |
rset = req.execute('Any X,Y,XT,YN WHERE X bookmarked_by Y, X title XT, Y login YN') |
1640 | 302 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
303 |
e = rset.get_entity(0, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
304 |
self.assertEqual(e.cw_row, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
305 |
self.assertEqual(e.cw_col, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
306 |
self.assertEqual(e.cw_attr_cache['title'], 'zou') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
307 |
self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'path') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
308 |
self.assertEqual(e.view('text'), 'zou') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
309 |
self.assertEqual(pprelcachedict(e._cw_related_cache), []) |
1640 | 310 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
311 |
e = rset.get_entity(0, 1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
312 |
self.assertEqual(e.cw_row, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
313 |
self.assertEqual(e.cw_col, 1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
314 |
self.assertEqual(e.cw_attr_cache['login'], 'anon') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
315 |
self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'firstname') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
316 |
self.assertEqual(pprelcachedict(e._cw_related_cache), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
317 |
[]) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
318 |
e.complete() |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
319 |
self.assertEqual(e.cw_attr_cache['firstname'], None) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
320 |
self.assertEqual(e.view('text'), 'anon') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
321 |
self.assertEqual(pprelcachedict(e._cw_related_cache), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
322 |
[]) |
1640 | 323 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
324 |
self.assertRaises(NotAnEntity, rset.get_entity, 0, 2) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
325 |
self.assertRaises(NotAnEntity, rset.get_entity, 0, 3) |
0 | 326 |
|
327 |
def test_get_entity_relation_cache_compt(self): |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
328 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
329 |
rset = req.execute('Any X,S WHERE X in_state S, X login "anon"') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
330 |
e = rset.get_entity(0, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
331 |
seid = req.execute('State X WHERE X name "activated"')[0][0] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
332 |
# for_user / in_group are prefetched in CWUser __init__, in_state should |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
333 |
# be filed from our query rset |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
334 |
self.assertEqual(pprelcachedict(e._cw_related_cache), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
335 |
[('in_state_subject', [seid])]) |
0 | 336 |
|
337 |
def test_get_entity_advanced_prefilled_cache(self): |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
338 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
339 |
e = req.create_entity('Bookmark', title=u'zou', path=u'path') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
340 |
req.cnx.commit() |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
341 |
rset = req.execute('Any X,U,S,XT,UL,SN WHERE X created_by U, U in_state S, ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
342 |
'X title XT, S name SN, U login UL, X eid %s' % e.eid) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
343 |
e = rset.get_entity(0, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
344 |
self.assertEqual(e.cw_attr_cache['title'], 'zou') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
345 |
self.assertEqual(pprelcachedict(e._cw_related_cache), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
346 |
[('created_by_subject', [req.user.eid])]) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
347 |
# first level of recursion |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
348 |
u = e.created_by[0] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
349 |
self.assertEqual(u.cw_attr_cache['login'], 'admin') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
350 |
self.assertRaises(KeyError, u.cw_attr_cache.__getitem__, 'firstname') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
351 |
# second level of recursion |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
352 |
s = u.in_state[0] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
353 |
self.assertEqual(s.cw_attr_cache['name'], 'activated') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
354 |
self.assertRaises(KeyError, s.cw_attr_cache.__getitem__, 'description') |
0 | 355 |
|
1640 | 356 |
|
0 | 357 |
def test_get_entity_cache_with_left_outer_join(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
358 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
359 |
eid = req.execute('INSERT CWUser E: E login "joe", E upassword "joe", E in_group G ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
360 |
'WHERE G name "users"')[0][0] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
361 |
rset = req.execute('Any X,E WHERE X eid %(x)s, X primary_email E?', {'x': eid}) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
362 |
e = rset.get_entity(0, 0) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
363 |
# if any of the assertion below fails with a KeyError, the relation is not cached |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
364 |
# related entities should be an empty list |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
365 |
self.assertEqual(e._cw_related_cache['primary_email_subject'][True], ()) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
366 |
# related rset should be an empty rset |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
367 |
cached = e._cw_related_cache['primary_email_subject'][False] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
368 |
self.assertIsInstance(cached, ResultSet) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
369 |
self.assertEqual(cached.rowcount, 0) |
1640 | 370 |
|
0 | 371 |
|
372 |
def test_get_entity_union(self): |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
373 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
374 |
e = req.create_entity('Bookmark', title=u'manger', path=u'path') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
375 |
req.cnx.drop_entity_cache() |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
376 |
rset = req.execute('Any X,N ORDERBY N WITH X,N BEING ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
377 |
'((Any X,N WHERE X is Bookmark, X title N)' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
378 |
' UNION ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
379 |
' (Any X,N WHERE X is CWGroup, X name N))') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
380 |
expected = (('CWGroup', 'guests'), ('CWGroup', 'managers'), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
381 |
('Bookmark', 'manger'), ('CWGroup', 'owners'), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
382 |
('CWGroup', 'users')) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
383 |
for entity in rset.entities(): # test get_entity for each row actually |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
384 |
etype, n = expected[entity.cw_row] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
385 |
self.assertEqual(entity.cw_etype, etype) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
386 |
attr = etype == 'Bookmark' and 'title' or 'name' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
387 |
self.assertEqual(entity.cw_attr_cache[attr], n) |
1640 | 388 |
|
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
389 |
def test_one(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
390 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
391 |
req.create_entity('CWUser', login=u'cdevienne', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
392 |
upassword=u'cdevienne', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
393 |
surname=u'de Vienne', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
394 |
firstname=u'Christophe') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
395 |
e = req.execute('Any X WHERE X login "cdevienne"').one() |
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
396 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
397 |
self.assertEqual(e.surname, u'de Vienne') |
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
398 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
399 |
e = req.execute( |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
400 |
'Any X, N WHERE X login "cdevienne", X surname N').one() |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
401 |
self.assertEqual(e.surname, u'de Vienne') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
402 |
|
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
403 |
e = req.execute( |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
404 |
'Any N, X WHERE X login "cdevienne", X surname N').one(col=1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
405 |
self.assertEqual(e.surname, u'de Vienne') |
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
406 |
|
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
407 |
def test_one_no_rows(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
408 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
409 |
with self.assertRaises(NoResultError): |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
410 |
req.execute('Any X WHERE X login "patanok"').one() |
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
411 |
|
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
412 |
def test_one_multiple_rows(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
413 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
414 |
req.create_entity( |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
415 |
'CWUser', login=u'cdevienne', upassword=u'cdevienne', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
416 |
surname=u'de Vienne', firstname=u'Christophe') |
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
417 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
418 |
req.create_entity( |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
419 |
'CWUser', login=u'adim', upassword='adim', surname=u'di mascio', |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
420 |
firstname=u'adrien') |
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
421 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
422 |
with self.assertRaises(MultipleResultsError): |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
423 |
req.execute('Any X WHERE X is CWUser').one() |
9347
bd841d6ae723
[rset] New method: ResultSet.one()
Christophe de Vienne <cdevienne@gmail.com>
parents:
9331
diff
changeset
|
424 |
|
572
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
425 |
def test_related_entity_optional(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
426 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
427 |
e = req.create_entity('Bookmark', title=u'aaaa', path=u'path') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
428 |
rset = req.execute('Any B,U,L WHERE B bookmarked_by U?, U login L') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
429 |
entity, rtype = rset.related_entity(0, 2) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
430 |
self.assertEqual(entity, None) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
431 |
self.assertEqual(rtype, None) |
1640 | 432 |
|
6915
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
433 |
def test_related_entity_union_subquery_1(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
434 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
435 |
e = req.create_entity('Bookmark', title=u'aaaa', path=u'path') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
436 |
rset = req.execute('Any X,N ORDERBY N WITH X,N BEING ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
437 |
'((Any X,N WHERE X is CWGroup, X name N)' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
438 |
' UNION ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
439 |
' (Any X,N WHERE X is Bookmark, X title N))') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
440 |
entity, rtype = rset.related_entity(0, 1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
441 |
self.assertEqual(entity.eid, e.eid) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
442 |
self.assertEqual(rtype, 'title') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
443 |
self.assertEqual(entity.title, 'aaaa') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
444 |
entity, rtype = rset.related_entity(1, 1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
445 |
self.assertEqual(entity.cw_etype, 'CWGroup') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
446 |
self.assertEqual(rtype, 'name') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
447 |
self.assertEqual(entity.name, 'guests') |
6915
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
448 |
|
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
449 |
def test_related_entity_union_subquery_2(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
450 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
451 |
e = req.create_entity('Bookmark', title=u'aaaa', path=u'path') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
452 |
rset = req.execute('Any X,N ORDERBY N WHERE X is Bookmark WITH X,N BEING ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
453 |
'((Any X,N WHERE X is CWGroup, X name N)' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
454 |
' UNION ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
455 |
' (Any X,N WHERE X is Bookmark, X title N))') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
456 |
entity, rtype = rset.related_entity(0, 1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
457 |
self.assertEqual(entity.eid, e.eid) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
458 |
self.assertEqual(rtype, 'title') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
459 |
self.assertEqual(entity.title, 'aaaa') |
6915
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
460 |
|
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
461 |
def test_related_entity_union_subquery_3(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
462 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
463 |
e = req.create_entity('Bookmark', title=u'aaaa', path=u'path') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
464 |
rset = req.execute('Any X,N ORDERBY N WITH N,X BEING ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
465 |
'((Any N,X WHERE X is CWGroup, X name N)' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
466 |
' UNION ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
467 |
' (Any N,X WHERE X is Bookmark, X title N))') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
468 |
entity, rtype = rset.related_entity(0, 1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
469 |
self.assertEqual(entity.eid, e.eid) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
470 |
self.assertEqual(rtype, 'title') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
471 |
self.assertEqual(entity.title, 'aaaa') |
6915
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
472 |
|
99eb71b311e4
[rset] fix entity building for some result set with UNION and subqueries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6857
diff
changeset
|
473 |
def test_related_entity_union_subquery_4(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
474 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
475 |
e = req.create_entity('Bookmark', title=u'aaaa', path=u'path') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
476 |
rset = req.execute('Any X,X, N ORDERBY N WITH X,N BEING ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
477 |
'((Any X,N WHERE X is CWGroup, X name N)' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
478 |
' UNION ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
479 |
' (Any X,N WHERE X is Bookmark, X title N))') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
480 |
entity, rtype = rset.related_entity(0, 2) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
481 |
self.assertEqual(entity.eid, e.eid) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
482 |
self.assertEqual(rtype, 'title') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
483 |
self.assertEqual(entity.title, 'aaaa') |
1640 | 484 |
|
4427
410c99a917fa
fix rset.related_entity with variables coming from subquery while some others not
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
485 |
def test_related_entity_trap_subquery(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
486 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
487 |
req.create_entity('Bookmark', title=u'test bookmark', path=u'') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
488 |
req.execute('SET B bookmarked_by U WHERE U login "admin"') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
489 |
rset = req.execute('Any B,T,L WHERE B bookmarked_by U, U login L ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
490 |
'WITH B,T BEING (Any B,T WHERE B is Bookmark, B title T)') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
491 |
rset.related_entity(0, 2) |
4427
410c99a917fa
fix rset.related_entity with variables coming from subquery while some others not
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
492 |
|
6195
a0c4441e6ddf
[rset] add test for #1251252, actually fixed in rql; fix docstring and add comments in rset.related_entity to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
493 |
def test_related_entity_subquery_outerjoin(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
494 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
495 |
rset = req.execute('Any X,S,L WHERE X in_state S ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
496 |
'WITH X, L BEING (Any X,MAX(L) GROUPBY X ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
497 |
'WHERE X is CWUser, T? wf_info_for X, T creation_date L)') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
498 |
self.assertEqual(len(rset), 2) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
499 |
rset.related_entity(0, 1) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
500 |
rset.related_entity(0, 2) |
6195
a0c4441e6ddf
[rset] add test for #1251252, actually fixed in rql; fix docstring and add comments in rset.related_entity to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
501 |
|
0 | 502 |
def test_entities(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
503 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
504 |
rset = req.execute('Any U,G WHERE U in_group G') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
505 |
# make sure we have at least one element |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
506 |
self.assertTrue(rset) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
507 |
self.assertEqual(set(e.e_schema.type for e in rset.entities(0)), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
508 |
set(['CWUser',])) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
509 |
self.assertEqual(set(e.e_schema.type for e in rset.entities(1)), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
510 |
set(['CWGroup',])) |
0 | 511 |
|
6857
8d2062387134
[rset] add utility method to get entities and attributes from any rset
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6415
diff
changeset
|
512 |
def test_iter_rows_with_entities(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
513 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
514 |
rset = req.execute('Any U,UN,G,GN WHERE U in_group G, U login UN, G name GN') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
515 |
# make sure we have at least one element |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
516 |
self.assertTrue(rset) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
517 |
out = list(rset.iter_rows_with_entities())[0] |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
518 |
self.assertEqual( out[0].login, out[1] ) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
519 |
self.assertEqual( out[2].name, out[3] ) |
6857
8d2062387134
[rset] add utility method to get entities and attributes from any rset
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6415
diff
changeset
|
520 |
|
1640 | 521 |
def test_printable_rql(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
522 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
523 |
rset = req.execute(u'CWEType X WHERE X final FALSE') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
524 |
self.assertEqual(rset.printable_rql(), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
525 |
'Any X WHERE X final FALSE, X is CWEType') |
0 | 526 |
|
527 |
def test_searched_text(self): |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
528 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
529 |
rset = req.execute(u'Any X WHERE X has_text "foobar"') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
530 |
self.assertEqual(rset.searched_text(), 'foobar') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
531 |
rset = req.execute(u'Any X WHERE X has_text %(text)s', {'text' : 'foo'}) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
532 |
self.assertEqual(rset.searched_text(), 'foo') |
1640 | 533 |
|
4939
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
534 |
def test_union_limited_rql(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
535 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
536 |
rset = req.execute('(Any X,N WHERE X is Bookmark, X title N)' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
537 |
' UNION ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
538 |
'(Any X,N WHERE X is CWGroup, X name N)') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
539 |
rset.limit(2, 10, inplace=True) |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
540 |
self.assertEqual(rset.limited_rql(), |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
541 |
'Any A,B LIMIT 2 OFFSET 10 ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
542 |
'WITH A,B BEING (' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
543 |
'(Any X,N WHERE X is Bookmark, X title N) ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
544 |
'UNION ' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
545 |
'(Any X,N WHERE X is CWGroup, X name N)' |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
546 |
')') |
1640 | 547 |
|
5667
04cbd80fd5dc
[rset] do not break when rset.related_entity(x,y) is not an entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5426
diff
changeset
|
548 |
def test_count_users_by_date(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
549 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
550 |
rset = req.execute('Any D, COUNT(U) GROUPBY D WHERE U is CWUser, U creation_date D') |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
551 |
self.assertEqual(rset.related_entity(0,0), (None, None)) |
5667
04cbd80fd5dc
[rset] do not break when rset.related_entity(x,y) is not an entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5426
diff
changeset
|
552 |
|
5687
3ea39709b50e
[rset] Add a line break the first result in repr of multiple rows rset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5679
diff
changeset
|
553 |
def test_str(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
554 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
555 |
rset = req.execute('(Any X,N WHERE X is CWGroup, X name N)') |
10612
84468b90e9c1
[py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
556 |
self.assertIsInstance(str(rset), string_types) |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
557 |
self.assertEqual(len(str(rset).splitlines()), 1) |
5687
3ea39709b50e
[rset] Add a line break the first result in repr of multiple rows rset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5679
diff
changeset
|
558 |
|
3ea39709b50e
[rset] Add a line break the first result in repr of multiple rows rset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5679
diff
changeset
|
559 |
def test_repr(self): |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
560 |
with self.admin_access.web_request() as req: |
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
561 |
rset = req.execute('(Any X,N WHERE X is CWGroup, X name N)') |
10612
84468b90e9c1
[py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
562 |
self.assertIsInstance(repr(rset), string_types) |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
563 |
self.assertTrue(len(repr(rset).splitlines()) > 1) |
5687
3ea39709b50e
[rset] Add a line break the first result in repr of multiple rows rset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5679
diff
changeset
|
564 |
|
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
565 |
rset = req.execute('(Any X WHERE X is CWGroup, X name "managers")') |
10612
84468b90e9c1
[py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
566 |
self.assertIsInstance(str(rset), string_types) |
9656
19c423d9d215
[test] update unittest_rset to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
567 |
self.assertEqual(len(str(rset).splitlines()), 1) |
5687
3ea39709b50e
[rset] Add a line break the first result in repr of multiple rows rset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5679
diff
changeset
|
568 |
|
10180
ea10572fccfe
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9656
diff
changeset
|
569 |
def test_nonregr_symmetric_relation(self): |
ea10572fccfe
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9656
diff
changeset
|
570 |
# see https://www.cubicweb.org/ticket/4739253 |
ea10572fccfe
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9656
diff
changeset
|
571 |
with self.admin_access.client_cnx() as cnx: |
ea10572fccfe
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9656
diff
changeset
|
572 |
p1 = cnx.create_entity('Personne', nom=u'sylvain') |
ea10572fccfe
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9656
diff
changeset
|
573 |
cnx.create_entity('Personne', nom=u'denis', connait=p1) |
ea10572fccfe
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9656
diff
changeset
|
574 |
cnx.commit() |
ea10572fccfe
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9656
diff
changeset
|
575 |
rset = cnx.execute('Any X,Y WHERE X connait Y') |
ea10572fccfe
[rset] fix crash on displaying rset where some symmetric relation is used. Closes #4739253
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9656
diff
changeset
|
576 |
rset.get_entity(0, 1) # used to raise KeyError |
8085
51929d531aff
[rset] fix crash while building entity from rset w/ some subquery. Closes #2089055
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8048
diff
changeset
|
577 |
|
0 | 578 |
if __name__ == '__main__': |
579 |
unittest_main() |