author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 06 Oct 2010 14:57:14 +0200 | |
changeset 6404 | 2013ef8f56e9 |
parent 6367 | d4c485ec1ca1 |
child 6415 | b0b0f097a72d |
permissions | -rw-r--r-- |
0 | 1 |
# coding: utf-8 |
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
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
|
02d0803a60b8
cleanup 2.5 __future__ imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4461
diff
changeset
|
21 |
from urlparse import urlsplit |
5740
46207f491a51
[rset] make rsets picklable (again ?) #1056422
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5667
diff
changeset
|
22 |
import pickle |
4536
02d0803a60b8
cleanup 2.5 __future__ imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4461
diff
changeset
|
23 |
|
02d0803a60b8
cleanup 2.5 __future__ imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4461
diff
changeset
|
24 |
from rql import parse |
0 | 25 |
|
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
|
26 |
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
|
27 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
28 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 29 |
from cubicweb.rset import NotAnEntity, ResultSet, attr_desc_iterator |
30 |
||
1640 | 31 |
|
0 | 32 |
def pprelcachedict(d): |
33 |
res = {} |
|
34 |
for k, (rset, related) in d.items(): |
|
35 |
res[k] = sorted(v.eid for v in related) |
|
36 |
return sorted(res.items()) |
|
1640 | 37 |
|
0 | 38 |
|
39 |
class AttrDescIteratorTC(TestCase): |
|
40 |
"""TestCase for cubicweb.rset.attr_desc_iterator""" |
|
1640 | 41 |
|
0 | 42 |
def test_relations_description(self): |
43 |
"""tests relations_description() function""" |
|
44 |
queries = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
45 |
'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
|
46 |
'Any U,L,M where U is CWUser, L is Foo, U mail M' : [(2, 'mail', 'subject')], |
0 | 47 |
'Any C,P where C is Company, C employs P' : [(1, 'employs', 'subject')], |
48 |
'Any C,P where C is Company, P employed_by P' : [], |
|
49 |
'Any C where C is Company, C employs P' : [], |
|
50 |
} |
|
51 |
for rql, relations in queries.items(): |
|
52 |
result = list(attr_desc_iterator(parse(rql).children[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
|
53 |
self.assertEqual((rql, result), (rql, relations)) |
1640 | 54 |
|
0 | 55 |
def test_relations_description_indexed(self): |
56 |
"""tests relations_description() function""" |
|
57 |
queries = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
58 |
'Any C,U,P,L,M where C is Company, C employs P, U is CWUser, U login L, U mail M' : |
0 | 59 |
{0: [(2,'employs', 'subject')], 1: [(3,'login', 'subject'), (4,'mail', 'subject')]}, |
60 |
} |
|
61 |
for rql, results in queries.items(): |
|
62 |
for var_index, relations in results.items(): |
|
63 |
result = list(attr_desc_iterator(parse(rql).children[0], var_index)) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
64 |
self.assertEqual(result, relations) |
0 | 65 |
|
66 |
||
67 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
68 |
class ResultSetTC(CubicWebTC): |
0 | 69 |
|
70 |
def setUp(self): |
|
71 |
super(ResultSetTC, self).setUp() |
|
72 |
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
|
73 |
'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
|
74 |
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
|
75 |
self.rset.req = mock_object(vreg=self.vreg) |
0 | 76 |
|
77 |
def compare_urls(self, url1, url2): |
|
78 |
info1 = urlsplit(url1) |
|
79 |
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
|
80 |
self.assertEqual(info1[:3], info2[:3]) |
0 | 81 |
if info1[3] != info2[3]: |
82 |
params1 = dict(pair.split('=') for pair in info1[3].split('&')) |
|
83 |
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
|
84 |
self.assertDictEqual(params1, params2) |
0 | 85 |
|
5740
46207f491a51
[rset] make rsets picklable (again ?) #1056422
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5667
diff
changeset
|
86 |
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
|
87 |
del self.rset.req |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
88 |
self.assertEqual(len(pickle.dumps(self.rset)), 392) |
1640 | 89 |
|
0 | 90 |
def test_build_url(self): |
91 |
req = self.request() |
|
92 |
baseurl = req.base_url() |
|
93 |
self.compare_urls(req.build_url('view', vid='foo', rql='yo'), |
|
94 |
'%sview?vid=foo&rql=yo' % baseurl) |
|
95 |
self.compare_urls(req.build_url('view', _restpath='task/title/go'), |
|
96 |
'%stask/title/go' % baseurl) |
|
97 |
#self.compare_urls(req.build_url('view', _restpath='/task/title/go'), |
|
98 |
# '%stask/title/go' % baseurl) |
|
99 |
# empty _restpath should not crash |
|
100 |
self.compare_urls(req.build_url('view', _restpath=''), baseurl) |
|
1640 | 101 |
|
102 |
||
0 | 103 |
def test_resultset_build(self): |
104 |
"""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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
self.assertEqual(rs.description, ['CWGroup', 'CWGroup', 'CWGroup']) |
0 | 109 |
|
110 |
||
111 |
def test_resultset_limit(self): |
|
112 |
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
|
113 |
'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
|
114 |
description=[['CWUser', 'String']] * 3) |
0 | 115 |
rs.req = self.request() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
116 |
rs.vreg = self.vreg |
0 | 117 |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
118 |
self.assertEqual(rs.limit(2).rows, [[12000, 'adim'], [13000, 'syt']]) |
0 | 119 |
rs2 = rs.limit(2, offset=1) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
120 |
self.assertEqual(rs2.rows, [[13000, 'syt'], [14000, 'nico']]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
121 |
self.assertEqual(rs2.get_entity(0, 0).cw_row, 0) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
122 |
self.assertEqual(rs.limit(2, offset=2).rows, [[14000, 'nico']]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
123 |
self.assertEqual(rs.limit(2, offset=3).rows, []) |
1640 | 124 |
|
0 | 125 |
|
126 |
def test_resultset_filter(self): |
|
127 |
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
|
128 |
'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
|
129 |
description=[['CWUser', 'String']] * 3) |
0 | 130 |
rs.req = self.request() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
131 |
rs.vreg = self.vreg |
0 | 132 |
def test_filter(entity): |
133 |
return entity.login != 'nico' |
|
1640 | 134 |
|
0 | 135 |
rs2 = rs.filtered_rset(test_filter) |
6340
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(len(rs2), 2) |
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([login for _, login in rs2], ['adim', 'syt']) |
1640 | 138 |
|
0 | 139 |
def test_resultset_transform(self): |
140 |
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
|
141 |
'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
|
142 |
description=[['CWUser', 'String']] * 3) |
0 | 143 |
rs.req = self.request() |
144 |
def test_transform(row, desc): |
|
145 |
return row[1:], desc[1:] |
|
146 |
rs2 = rs.transformed_rset(test_transform) |
|
147 |
||
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
148 |
self.assertEqual(len(rs2), 3) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
149 |
self.assertEqual(list(rs2), [['adim'],['syt'],['nico']]) |
1640 | 150 |
|
0 | 151 |
def test_resultset_sort(self): |
152 |
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
|
153 |
'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
|
154 |
description=[['CWUser', 'String']] * 3) |
0 | 155 |
rs.req = self.request() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
156 |
rs.vreg = self.vreg |
1640 | 157 |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
158 |
rs2 = rs.sorted_rset(lambda e:e.cw_attr_cache['login']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
159 |
self.assertEqual(len(rs2), 3) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
160 |
self.assertEqual([login for _, login in rs2], ['adim', 'nico', 'syt']) |
0 | 161 |
# make sure rs is unchanged |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
162 |
self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico']) |
1640 | 163 |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
164 |
rs2 = rs.sorted_rset(lambda e:e.cw_attr_cache['login'], reverse=True) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
165 |
self.assertEqual(len(rs2), 3) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
166 |
self.assertEqual([login for _, login in rs2], ['syt', 'nico', 'adim']) |
0 | 167 |
# make sure rs is unchanged |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
168 |
self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico']) |
0 | 169 |
|
170 |
rs3 = rs.sorted_rset(lambda row: row[1], col=-1) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
171 |
self.assertEqual(len(rs3), 3) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
172 |
self.assertEqual([login for _, login in rs3], ['adim', 'nico', 'syt']) |
0 | 173 |
# make sure rs is unchanged |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
174 |
self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico']) |
0 | 175 |
|
176 |
def test_resultset_split(self): |
|
177 |
rs = ResultSet([[12000, 'adim', u'Adim chez les pinguins'], |
|
178 |
[12000, 'adim', u'Jardiner facile'], |
|
179 |
[13000, 'syt', u'Le carrelage en 42 leçons'], |
|
180 |
[14000, 'nico', u'La tarte tatin en 15 minutes'], |
|
181 |
[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
|
182 |
'Any U, L, T WHERE U is CWUser, U login L,'\ |
0 | 183 |
'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
|
184 |
description=[['CWUser', 'String', 'String']] * 5) |
0 | 185 |
rs.req = self.request() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
186 |
rs.vreg = self.vreg |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
187 |
rsets = rs.split_rset(lambda e:e.cw_attr_cache['login']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
188 |
self.assertEqual(len(rsets), 3) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
189 |
self.assertEqual([login for _, login,_ in rsets[0]], ['adim', 'adim']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
190 |
self.assertEqual([login for _, login,_ in rsets[1]], ['syt']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
191 |
self.assertEqual([login for _, login,_ in rsets[2]], ['nico', 'nico']) |
0 | 192 |
# make sure rs is unchanged |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
193 |
self.assertEqual([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico']) |
1640 | 194 |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
195 |
rsets = rs.split_rset(lambda e:e.cw_attr_cache['login'], return_dict=True) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
196 |
self.assertEqual(len(rsets), 3) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
197 |
self.assertEqual([login for _, login,_ in rsets['nico']], ['nico', 'nico']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
198 |
self.assertEqual([login for _, login,_ in rsets['adim']], ['adim', 'adim']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
199 |
self.assertEqual([login for _, login,_ in rsets['syt']], ['syt']) |
0 | 200 |
# make sure rs is unchanged |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
201 |
self.assertEqual([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico']) |
0 | 202 |
|
203 |
rsets = rs.split_rset(lambda s: s.count('d'), col=2) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
204 |
self.assertEqual(len(rsets), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
205 |
self.assertEqual([title for _, _, title in rsets[0]], |
0 | 206 |
[u"Adim chez les pinguins", |
207 |
u"Jardiner facile", |
|
208 |
u"L'épluchage du castor commun",]) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
209 |
self.assertEqual([title for _, _, title in rsets[1]], |
0 | 210 |
[u"Le carrelage en 42 leçons", |
211 |
u"La tarte tatin en 15 minutes",]) |
|
212 |
# make sure rs is unchanged |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
213 |
self.assertEqual([title for _, _, title in rs], |
0 | 214 |
[u'Adim chez les pinguins', |
215 |
u'Jardiner facile', |
|
216 |
u'Le carrelage en 42 leçons', |
|
217 |
u'La tarte tatin en 15 minutes', |
|
218 |
u"L'épluchage du castor commun"]) |
|
1640 | 219 |
|
0 | 220 |
def test_cached_syntax_tree(self): |
221 |
"""make sure syntax tree is cached""" |
|
222 |
rqlst1 = self.rset.syntax_tree() |
|
223 |
rqlst2 = self.rset.syntax_tree() |
|
224 |
self.assert_(rqlst1 is rqlst2) |
|
225 |
||
226 |
def test_get_entity_simple(self): |
|
4461
a35c76ffed92
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4427
diff
changeset
|
227 |
self.request().create_entity('CWUser', login=u'adim', upassword='adim', |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
228 |
surname=u'di mascio', firstname=u'adrien') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4951
diff
changeset
|
229 |
e = self.execute('Any X,T WHERE X login "adim", X surname T').get_entity(0, 0) |
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
230 |
self.assertEqual(e.cw_attr_cache['surname'], 'di mascio') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
231 |
self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'firstname') |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
232 |
self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'creation_date') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
233 |
self.assertEqual(pprelcachedict(e._cw_related_cache), []) |
0 | 234 |
e.complete() |
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
235 |
self.assertEqual(e.cw_attr_cache['firstname'], 'adrien') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
236 |
self.assertEqual(pprelcachedict(e._cw_related_cache), []) |
1640 | 237 |
|
0 | 238 |
def test_get_entity_advanced(self): |
4461
a35c76ffed92
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4427
diff
changeset
|
239 |
self.request().create_entity('Bookmark', title=u'zou', path=u'/view') |
0 | 240 |
self.execute('SET X bookmarked_by Y WHERE X is Bookmark, Y login "anon"') |
241 |
rset = self.execute('Any X,Y,XT,YN WHERE X bookmarked_by Y, X title XT, Y login YN') |
|
1640 | 242 |
|
0 | 243 |
e = rset.get_entity(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
|
244 |
self.assertEqual(e.cw_row, 0) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
245 |
self.assertEqual(e.cw_col, 0) |
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
246 |
self.assertEqual(e.cw_attr_cache['title'], 'zou') |
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
247 |
self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'path') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
248 |
self.assertEqual(e.view('text'), 'zou') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
249 |
self.assertEqual(pprelcachedict(e._cw_related_cache), []) |
1640 | 250 |
|
0 | 251 |
e = rset.get_entity(0, 1) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
252 |
self.assertEqual(e.cw_row, 0) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
253 |
self.assertEqual(e.cw_col, 1) |
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
254 |
self.assertEqual(e.cw_attr_cache['login'], 'anon') |
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
255 |
self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'firstname') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
256 |
self.assertEqual(pprelcachedict(e._cw_related_cache), |
0 | 257 |
[]) |
258 |
e.complete() |
|
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
259 |
self.assertEqual(e.cw_attr_cache['firstname'], None) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
260 |
self.assertEqual(e.view('text'), 'anon') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
261 |
self.assertEqual(pprelcachedict(e._cw_related_cache), |
0 | 262 |
[]) |
1640 | 263 |
|
0 | 264 |
self.assertRaises(NotAnEntity, rset.get_entity, 0, 2) |
265 |
self.assertRaises(NotAnEntity, rset.get_entity, 0, 3) |
|
266 |
||
267 |
def test_get_entity_relation_cache_compt(self): |
|
268 |
rset = self.execute('Any X,S WHERE X in_state S, X login "anon"') |
|
269 |
e = rset.get_entity(0, 0) |
|
270 |
seid = self.execute('State X WHERE X name "activated"')[0][0] |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
271 |
# for_user / in_group are prefetched in CWUser __init__, in_state should |
0 | 272 |
# be filed from our query rset |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
273 |
self.assertEqual(pprelcachedict(e._cw_related_cache), |
0 | 274 |
[('in_state_subject', [seid])]) |
275 |
||
276 |
def test_get_entity_advanced_prefilled_cache(self): |
|
4461
a35c76ffed92
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4427
diff
changeset
|
277 |
e = self.request().create_entity('Bookmark', title=u'zou', path=u'path') |
0 | 278 |
self.commit() |
279 |
rset = self.execute('Any X,U,S,XT,UL,SN WHERE X created_by U, U in_state S, ' |
|
280 |
'X title XT, S name SN, U login UL, X eid %s' % e.eid) |
|
281 |
e = rset.get_entity(0, 0) |
|
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
282 |
self.assertEqual(e.cw_attr_cache['title'], 'zou') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
283 |
self.assertEqual(pprelcachedict(e._cw_related_cache), |
0 | 284 |
[('created_by_subject', [5])]) |
285 |
# first level of recursion |
|
286 |
u = e.created_by[0] |
|
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
287 |
self.assertEqual(u.cw_attr_cache['login'], 'admin') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
288 |
self.assertRaises(KeyError, u.cw_attr_cache.__getitem__, 'firstname') |
0 | 289 |
# second level of recursion |
290 |
s = u.in_state[0] |
|
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
291 |
self.assertEqual(s.cw_attr_cache['name'], 'activated') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5752
diff
changeset
|
292 |
self.assertRaises(KeyError, s.cw_attr_cache.__getitem__, 'description') |
0 | 293 |
|
1640 | 294 |
|
0 | 295 |
def test_get_entity_cache_with_left_outer_join(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
296 |
eid = self.execute('INSERT CWUser E: E login "joe", E upassword "joe", E in_group G ' |
0 | 297 |
'WHERE G name "users"')[0][0] |
298 |
rset = self.execute('Any X,E WHERE X eid %(x)s, X primary_email E?', {'x': eid}) |
|
299 |
e = rset.get_entity(0, 0) |
|
300 |
# if any of the assertion below fails with a KeyError, the relation is not cached |
|
301 |
# related entities should be an empty list |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
302 |
self.assertEqual(e._cw_relation_cache('primary_email', 'subject', True), ()) |
0 | 303 |
# related rset should be an empty rset |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
304 |
cached = e._cw_relation_cache('primary_email', 'subject', False) |
0 | 305 |
self.assertIsInstance(cached, ResultSet) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
306 |
self.assertEqual(cached.rowcount, 0) |
1640 | 307 |
|
0 | 308 |
|
309 |
def test_get_entity_union(self): |
|
4461
a35c76ffed92
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4427
diff
changeset
|
310 |
e = self.request().create_entity('Bookmark', title=u'manger', path=u'path') |
0 | 311 |
rset = self.execute('Any X,N ORDERBY N WITH X,N BEING ' |
312 |
'((Any X,N WHERE X is Bookmark, X title N)' |
|
313 |
' UNION ' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
314 |
' (Any X,N WHERE X is CWGroup, X name N))') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
315 |
expected = (('CWGroup', 'guests'), ('CWGroup', 'managers'), |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
316 |
('Bookmark', 'manger'), ('CWGroup', 'owners'), |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
317 |
('CWGroup', 'users')) |
0 | 318 |
for entity in rset.entities(): # test get_entity for each row actually |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3023
diff
changeset
|
319 |
etype, n = expected[entity.cw_row] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
320 |
self.assertEqual(entity.__regid__, etype) |
0 | 321 |
attr = etype == 'Bookmark' and 'title' or 'name' |
6367
d4c485ec1ca1
fix merge, some buffers weren't saved...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6366
diff
changeset
|
322 |
self.assertEqual(entity.cw_attr_cache[attr], n) |
1640 | 323 |
|
572
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
324 |
def test_related_entity_optional(self): |
4461
a35c76ffed92
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4427
diff
changeset
|
325 |
e = self.request().create_entity('Bookmark', title=u'aaaa', path=u'path') |
572
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
326 |
rset = self.execute('Any B,U,L WHERE B bookmarked_by U?, U login L') |
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
327 |
entity, rtype = rset.related_entity(0, 2) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
328 |
self.assertEqual(entity, None) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
329 |
self.assertEqual(rtype, None) |
1640 | 330 |
|
0 | 331 |
def test_related_entity_union_subquery(self): |
4461
a35c76ffed92
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4427
diff
changeset
|
332 |
e = self.request().create_entity('Bookmark', title=u'aaaa', path=u'path') |
0 | 333 |
rset = self.execute('Any X,N ORDERBY N WITH X,N BEING ' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
334 |
'((Any X,N WHERE X is CWGroup, X name N)' |
0 | 335 |
' UNION ' |
336 |
' (Any X,N WHERE X is Bookmark, X title N))') |
|
337 |
entity, rtype = rset.related_entity(0, 1) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
338 |
self.assertEqual(entity.eid, e.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
339 |
self.assertEqual(rtype, 'title') |
0 | 340 |
entity, rtype = rset.related_entity(1, 1) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
341 |
self.assertEqual(entity.__regid__, 'CWGroup') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
342 |
self.assertEqual(rtype, 'name') |
3016
5787d1cc8106
[rset] fix #231354 w/ rql 0.22.3 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
343 |
# |
0 | 344 |
rset = self.execute('Any X,N ORDERBY N WHERE X is Bookmark WITH X,N BEING ' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
345 |
'((Any X,N WHERE X is CWGroup, X name N)' |
0 | 346 |
' UNION ' |
347 |
' (Any X,N WHERE X is Bookmark, X title N))') |
|
348 |
entity, rtype = rset.related_entity(0, 1) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
349 |
self.assertEqual(entity.eid, e.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
350 |
self.assertEqual(rtype, 'title') |
3016
5787d1cc8106
[rset] fix #231354 w/ rql 0.22.3 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
351 |
# |
5787d1cc8106
[rset] fix #231354 w/ rql 0.22.3 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
352 |
rset = self.execute('Any X,N ORDERBY N WITH N,X BEING ' |
5787d1cc8106
[rset] fix #231354 w/ rql 0.22.3 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
353 |
'((Any N,X WHERE X is CWGroup, X name N)' |
5787d1cc8106
[rset] fix #231354 w/ rql 0.22.3 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
354 |
' UNION ' |
5787d1cc8106
[rset] fix #231354 w/ rql 0.22.3 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
355 |
' (Any N,X WHERE X is Bookmark, X title N))') |
5787d1cc8106
[rset] fix #231354 w/ rql 0.22.3 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
356 |
entity, rtype = rset.related_entity(0, 1) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
357 |
self.assertEqual(entity.eid, e.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
358 |
self.assertEqual(rtype, 'title') |
1640 | 359 |
|
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
|
360 |
def test_related_entity_trap_subquery(self): |
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
|
361 |
req = self.request() |
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
|
362 |
req.create_entity('Bookmark', title=u'test bookmark', path=u'') |
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
|
363 |
self.execute('SET B bookmarked_by U WHERE U login "admin"') |
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
|
364 |
rset = self.execute('Any B,T,L WHERE B bookmarked_by U, U login L ' |
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
|
365 |
'WITH B,T BEING (Any B,T WHERE B is Bookmark, B title T)') |
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
|
366 |
rset.related_entity(0, 2) |
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
|
367 |
|
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
|
368 |
def test_related_entity_subquery_outerjoin(self): |
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
|
369 |
rset = self.execute('Any X,S,L WHERE X in_state S ' |
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
|
370 |
'WITH X, L BEING (Any X,MAX(L) GROUPBY X ' |
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
|
371 |
'WHERE X is CWUser, T? wf_info_for X, T creation_date L)') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
372 |
self.assertEqual(len(rset), 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
|
373 |
rset.related_entity(0, 1) |
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
|
374 |
rset.related_entity(0, 2) |
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
|
375 |
|
0 | 376 |
def test_entities(self): |
377 |
rset = self.execute('Any U,G WHERE U in_group G') |
|
378 |
# make sure we have at least one element |
|
379 |
self.failUnless(rset) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
380 |
self.assertEqual(set(e.e_schema.type for e in rset.entities(0)), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
381 |
set(['CWUser',])) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
382 |
self.assertEqual(set(e.e_schema.type for e in rset.entities(1)), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
383 |
set(['CWGroup',])) |
0 | 384 |
|
1640 | 385 |
def test_printable_rql(self): |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2286
diff
changeset
|
386 |
rset = self.execute(u'CWEType X WHERE X final FALSE') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
387 |
self.assertEqual(rset.printable_rql(), |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2286
diff
changeset
|
388 |
'Any X WHERE X final FALSE, X is CWEType') |
0 | 389 |
|
390 |
def test_searched_text(self): |
|
391 |
rset = self.execute(u'Any X WHERE X has_text "foobar"') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
392 |
self.assertEqual(rset.searched_text(), 'foobar') |
0 | 393 |
rset = self.execute(u'Any X WHERE X has_text %(text)s', {'text' : 'foo'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
394 |
self.assertEqual(rset.searched_text(), 'foo') |
1640 | 395 |
|
4939
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
396 |
def test_union_limited_rql(self): |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
397 |
rset = self.execute('(Any X,N WHERE X is Bookmark, X title N)' |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
398 |
' UNION ' |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
399 |
'(Any X,N WHERE X is CWGroup, X name N)') |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
400 |
rset.limit(2, 10, inplace=True) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
401 |
self.assertEqual(rset.limited_rql(), |
4939
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
402 |
'Any A,B LIMIT 2 OFFSET 10 ' |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
403 |
'WITH A,B BEING (' |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
404 |
'(Any X,N WHERE X is Bookmark, X title N) ' |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
405 |
'UNION ' |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
406 |
'(Any X,N WHERE X is CWGroup, X name N)' |
349af486f5ed
fix limited_rql w/ UNION query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4536
diff
changeset
|
407 |
')') |
1640 | 408 |
|
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
|
409 |
def test_count_users_by_date(self): |
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
|
410 |
rset = self.execute('Any D, COUNT(U) GROUPBY D WHERE U is CWUser, U creation_date D') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
411 |
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
|
412 |
|
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
|
413 |
def test_str(self): |
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
|
414 |
rset = self.execute('(Any X,N WHERE X is CWGroup, X name N)') |
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
|
415 |
self.assertIsInstance(str(rset), basestring) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
416 |
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
|
417 |
|
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
|
418 |
def test_repr(self): |
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
|
419 |
rset = self.execute('(Any X,N WHERE X is CWGroup, X name N)') |
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
|
420 |
self.assertIsInstance(repr(rset), basestring) |
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
|
421 |
self.assertTrue(len(repr(rset).splitlines()) > 1) |
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
|
422 |
|
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
|
423 |
rset = self.execute('(Any X WHERE X is CWGroup, X name "managers")') |
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
|
424 |
self.assertIsInstance(str(rset), basestring) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6195
diff
changeset
|
425 |
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
|
426 |
|
0 | 427 |
if __name__ == '__main__': |
428 |
unittest_main() |