author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 19 May 2009 16:58:25 +0200 | |
branch | stable |
changeset 1872 | b49fdd5ce8d2 |
parent 1640 | 65b60f177eb1 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
# coding: utf-8 |
2 |
"""unit tests for module cubicweb.common.utils""" |
|
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
|
3 |
from __future__ import with_statement |
0 | 4 |
|
5 |
from logilab.common.testlib import TestCase, unittest_main |
|
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
|
6 |
|
0 | 7 |
from cubicweb.devtools.apptest import EnvBasedTC |
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
633
diff
changeset
|
8 |
from cubicweb.selectors import traced_selection |
0 | 9 |
|
10 |
from urlparse import urlsplit |
|
11 |
from rql import parse |
|
12 |
||
13 |
from cubicweb.rset import NotAnEntity, ResultSet, attr_desc_iterator |
|
14 |
||
1640 | 15 |
|
0 | 16 |
def pprelcachedict(d): |
17 |
res = {} |
|
18 |
for k, (rset, related) in d.items(): |
|
19 |
res[k] = sorted(v.eid for v in related) |
|
20 |
return sorted(res.items()) |
|
1640 | 21 |
|
0 | 22 |
|
23 |
class AttrDescIteratorTC(TestCase): |
|
24 |
"""TestCase for cubicweb.rset.attr_desc_iterator""" |
|
1640 | 25 |
|
0 | 26 |
def test_relations_description(self): |
27 |
"""tests relations_description() function""" |
|
28 |
queries = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
29 |
'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
|
30 |
'Any U,L,M where U is CWUser, L is Foo, U mail M' : [(2, 'mail', 'subject')], |
0 | 31 |
'Any C,P where C is Company, C employs P' : [(1, 'employs', 'subject')], |
32 |
'Any C,P where C is Company, P employed_by P' : [], |
|
33 |
'Any C where C is Company, C employs P' : [], |
|
34 |
} |
|
35 |
for rql, relations in queries.items(): |
|
36 |
result = list(attr_desc_iterator(parse(rql).children[0])) |
|
37 |
self.assertEquals((rql, result), (rql, relations)) |
|
1640 | 38 |
|
0 | 39 |
def test_relations_description_indexed(self): |
40 |
"""tests relations_description() function""" |
|
41 |
queries = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
42 |
'Any C,U,P,L,M where C is Company, C employs P, U is CWUser, U login L, U mail M' : |
0 | 43 |
{0: [(2,'employs', 'subject')], 1: [(3,'login', 'subject'), (4,'mail', 'subject')]}, |
44 |
} |
|
45 |
for rql, results in queries.items(): |
|
46 |
for var_index, relations in results.items(): |
|
47 |
result = list(attr_desc_iterator(parse(rql).children[0], var_index)) |
|
48 |
self.assertEquals(result, relations) |
|
49 |
||
50 |
||
51 |
||
1640 | 52 |
class ResultSetTC(EnvBasedTC): |
0 | 53 |
|
54 |
def setUp(self): |
|
55 |
super(ResultSetTC, self).setUp() |
|
56 |
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
|
57 |
'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
|
58 |
description=[['CWUser', 'String'], ['Bar', 'String']]) |
0 | 59 |
self.rset.vreg = self.vreg |
60 |
||
61 |
def compare_urls(self, url1, url2): |
|
62 |
info1 = urlsplit(url1) |
|
63 |
info2 = urlsplit(url2) |
|
64 |
self.assertEquals(info1[:3], info2[:3]) |
|
65 |
if info1[3] != info2[3]: |
|
66 |
params1 = dict(pair.split('=') for pair in info1[3].split('&')) |
|
67 |
params2 = dict(pair.split('=') for pair in info1[3].split('&')) |
|
68 |
self.assertDictEquals(params1, params2) |
|
69 |
||
1640 | 70 |
|
0 | 71 |
def test_build_url(self): |
72 |
req = self.request() |
|
73 |
baseurl = req.base_url() |
|
74 |
self.compare_urls(req.build_url('view', vid='foo', rql='yo'), |
|
75 |
'%sview?vid=foo&rql=yo' % baseurl) |
|
76 |
self.compare_urls(req.build_url('view', _restpath='task/title/go'), |
|
77 |
'%stask/title/go' % baseurl) |
|
78 |
#self.compare_urls(req.build_url('view', _restpath='/task/title/go'), |
|
79 |
# '%stask/title/go' % baseurl) |
|
80 |
# empty _restpath should not crash |
|
81 |
self.compare_urls(req.build_url('view', _restpath=''), baseurl) |
|
1640 | 82 |
|
83 |
||
0 | 84 |
def test_resultset_build(self): |
85 |
"""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
|
86 |
rs = ResultSet([1,2,3], 'CWGroup X', description=['CWGroup', 'CWGroup', 'CWGroup']) |
0 | 87 |
self.assertEquals(rs.rowcount, 3) |
88 |
self.assertEquals(rs.rows, [1,2,3]) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
89 |
self.assertEquals(rs.description, ['CWGroup', 'CWGroup', 'CWGroup']) |
0 | 90 |
|
91 |
||
92 |
def test_resultset_limit(self): |
|
93 |
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
|
94 |
'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
|
95 |
description=[['CWUser', 'String']] * 3) |
0 | 96 |
rs.req = self.request() |
97 |
rs.vreg = self.env.vreg |
|
98 |
||
99 |
self.assertEquals(rs.limit(2).rows, [[12000, 'adim'], [13000, 'syt']]) |
|
100 |
rs2 = rs.limit(2, offset=1) |
|
101 |
self.assertEquals(rs2.rows, [[13000, 'syt'], [14000, 'nico']]) |
|
102 |
self.assertEquals(rs2.get_entity(0, 0).row, 0) |
|
103 |
self.assertEquals(rs.limit(2, offset=2).rows, [[14000, 'nico']]) |
|
104 |
self.assertEquals(rs.limit(2, offset=3).rows, []) |
|
1640 | 105 |
|
0 | 106 |
|
107 |
def test_resultset_filter(self): |
|
108 |
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
|
109 |
'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
|
110 |
description=[['CWUser', 'String']] * 3) |
0 | 111 |
rs.req = self.request() |
112 |
rs.vreg = self.env.vreg |
|
113 |
def test_filter(entity): |
|
114 |
return entity.login != 'nico' |
|
1640 | 115 |
|
0 | 116 |
rs2 = rs.filtered_rset(test_filter) |
117 |
self.assertEquals(len(rs2), 2) |
|
118 |
self.assertEquals([login for _, login in rs2], ['adim', 'syt']) |
|
1640 | 119 |
|
0 | 120 |
def test_resultset_transform(self): |
121 |
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
|
122 |
'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
|
123 |
description=[['CWUser', 'String']] * 3) |
0 | 124 |
rs.req = self.request() |
125 |
def test_transform(row, desc): |
|
126 |
return row[1:], desc[1:] |
|
127 |
rs2 = rs.transformed_rset(test_transform) |
|
128 |
||
129 |
self.assertEquals(len(rs2), 3) |
|
130 |
self.assertEquals(list(rs2), [['adim'],['syt'],['nico']]) |
|
1640 | 131 |
|
0 | 132 |
def test_resultset_sort(self): |
133 |
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
|
134 |
'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
|
135 |
description=[['CWUser', 'String']] * 3) |
0 | 136 |
rs.req = self.request() |
137 |
rs.vreg = self.env.vreg |
|
1640 | 138 |
|
0 | 139 |
rs2 = rs.sorted_rset(lambda e:e['login']) |
140 |
self.assertEquals(len(rs2), 3) |
|
141 |
self.assertEquals([login for _, login in rs2], ['adim', 'nico', 'syt']) |
|
142 |
# make sure rs is unchanged |
|
143 |
self.assertEquals([login for _, login in rs], ['adim', 'syt', 'nico']) |
|
1640 | 144 |
|
0 | 145 |
rs2 = rs.sorted_rset(lambda e:e['login'], reverse=True) |
146 |
self.assertEquals(len(rs2), 3) |
|
147 |
self.assertEquals([login for _, login in rs2], ['syt', 'nico', 'adim']) |
|
148 |
# make sure rs is unchanged |
|
149 |
self.assertEquals([login for _, login in rs], ['adim', 'syt', 'nico']) |
|
150 |
||
151 |
rs3 = rs.sorted_rset(lambda row: row[1], col=-1) |
|
152 |
self.assertEquals(len(rs3), 3) |
|
153 |
self.assertEquals([login for _, login in rs3], ['adim', 'nico', 'syt']) |
|
154 |
# make sure rs is unchanged |
|
155 |
self.assertEquals([login for _, login in rs], ['adim', 'syt', 'nico']) |
|
156 |
||
157 |
def test_resultset_split(self): |
|
158 |
rs = ResultSet([[12000, 'adim', u'Adim chez les pinguins'], |
|
159 |
[12000, 'adim', u'Jardiner facile'], |
|
160 |
[13000, 'syt', u'Le carrelage en 42 leçons'], |
|
161 |
[14000, 'nico', u'La tarte tatin en 15 minutes'], |
|
162 |
[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
|
163 |
'Any U, L, T WHERE U is CWUser, U login L,'\ |
0 | 164 |
'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
|
165 |
description=[['CWUser', 'String', 'String']] * 5) |
0 | 166 |
rs.req = self.request() |
167 |
rs.vreg = self.env.vreg |
|
1640 | 168 |
|
0 | 169 |
rsets = rs.split_rset(lambda e:e['login']) |
170 |
self.assertEquals(len(rsets), 3) |
|
171 |
self.assertEquals([login for _, login,_ in rsets[0]], ['adim', 'adim']) |
|
172 |
self.assertEquals([login for _, login,_ in rsets[1]], ['syt']) |
|
173 |
self.assertEquals([login for _, login,_ in rsets[2]], ['nico', 'nico']) |
|
174 |
# make sure rs is unchanged |
|
175 |
self.assertEquals([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico']) |
|
1640 | 176 |
|
0 | 177 |
rsets = rs.split_rset(lambda e:e['login'], return_dict=True) |
178 |
self.assertEquals(len(rsets), 3) |
|
179 |
self.assertEquals([login for _, login,_ in rsets['nico']], ['nico', 'nico']) |
|
180 |
self.assertEquals([login for _, login,_ in rsets['adim']], ['adim', 'adim']) |
|
181 |
self.assertEquals([login for _, login,_ in rsets['syt']], ['syt']) |
|
182 |
# make sure rs is unchanged |
|
183 |
self.assertEquals([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico']) |
|
184 |
||
185 |
rsets = rs.split_rset(lambda s: s.count('d'), col=2) |
|
186 |
self.assertEquals(len(rsets), 2) |
|
187 |
self.assertEquals([title for _, _, title in rsets[0]], |
|
188 |
[u"Adim chez les pinguins", |
|
189 |
u"Jardiner facile", |
|
190 |
u"L'épluchage du castor commun",]) |
|
191 |
self.assertEquals([title for _, _, title in rsets[1]], |
|
192 |
[u"Le carrelage en 42 leçons", |
|
193 |
u"La tarte tatin en 15 minutes",]) |
|
194 |
# make sure rs is unchanged |
|
195 |
self.assertEquals([title for _, _, title in rs], |
|
196 |
[u'Adim chez les pinguins', |
|
197 |
u'Jardiner facile', |
|
198 |
u'Le carrelage en 42 leçons', |
|
199 |
u'La tarte tatin en 15 minutes', |
|
200 |
u"L'épluchage du castor commun"]) |
|
1640 | 201 |
|
0 | 202 |
def test_cached_syntax_tree(self): |
203 |
"""make sure syntax tree is cached""" |
|
204 |
rqlst1 = self.rset.syntax_tree() |
|
205 |
rqlst2 = self.rset.syntax_tree() |
|
206 |
self.assert_(rqlst1 is rqlst2) |
|
207 |
||
208 |
def test_get_entity_simple(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
209 |
self.add_entity('CWUser', login=u'adim', upassword='adim', |
0 | 210 |
surname=u'di mascio', firstname=u'adrien') |
211 |
e = self.entity('Any X,T WHERE X login "adim", X surname T') |
|
212 |
self.assertEquals(e['surname'], 'di mascio') |
|
213 |
self.assertRaises(KeyError, e.__getitem__, 'firstname') |
|
214 |
self.assertRaises(KeyError, e.__getitem__, 'creation_date') |
|
215 |
self.assertEquals(pprelcachedict(e._related_cache), []) |
|
216 |
e.complete() |
|
217 |
self.assertEquals(e['firstname'], 'adrien') |
|
218 |
self.assertEquals(pprelcachedict(e._related_cache), []) |
|
1640 | 219 |
|
0 | 220 |
def test_get_entity_advanced(self): |
221 |
self.add_entity('Bookmark', title=u'zou', path=u'/view') |
|
222 |
self.execute('SET X bookmarked_by Y WHERE X is Bookmark, Y login "anon"') |
|
223 |
rset = self.execute('Any X,Y,XT,YN WHERE X bookmarked_by Y, X title XT, Y login YN') |
|
1640 | 224 |
|
0 | 225 |
e = rset.get_entity(0, 0) |
226 |
self.assertEquals(e.row, 0) |
|
227 |
self.assertEquals(e.col, 0) |
|
228 |
self.assertEquals(e['title'], 'zou') |
|
229 |
self.assertRaises(KeyError, e.__getitem__, 'path') |
|
1640 | 230 |
self.assertEquals(e.view('text'), 'zou') |
0 | 231 |
self.assertEquals(pprelcachedict(e._related_cache), []) |
1640 | 232 |
|
0 | 233 |
e = rset.get_entity(0, 1) |
234 |
self.assertEquals(e.row, 0) |
|
235 |
self.assertEquals(e.col, 1) |
|
236 |
self.assertEquals(e['login'], 'anon') |
|
237 |
self.assertRaises(KeyError, e.__getitem__, 'firstname') |
|
238 |
self.assertEquals(pprelcachedict(e._related_cache), |
|
239 |
[]) |
|
240 |
e.complete() |
|
241 |
self.assertEquals(e['firstname'], None) |
|
242 |
self.assertEquals(e.view('text'), 'anon') |
|
243 |
self.assertEquals(pprelcachedict(e._related_cache), |
|
244 |
[]) |
|
1640 | 245 |
|
0 | 246 |
self.assertRaises(NotAnEntity, rset.get_entity, 0, 2) |
247 |
self.assertRaises(NotAnEntity, rset.get_entity, 0, 3) |
|
248 |
||
249 |
def test_get_entity_relation_cache_compt(self): |
|
250 |
rset = self.execute('Any X,S WHERE X in_state S, X login "anon"') |
|
251 |
e = rset.get_entity(0, 0) |
|
252 |
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
|
253 |
# for_user / in_group are prefetched in CWUser __init__, in_state should |
0 | 254 |
# be filed from our query rset |
255 |
self.assertEquals(pprelcachedict(e._related_cache), |
|
256 |
[('in_state_subject', [seid])]) |
|
257 |
||
258 |
def test_get_entity_advanced_prefilled_cache(self): |
|
259 |
e = self.add_entity('Bookmark', title=u'zou', path=u'path') |
|
260 |
self.commit() |
|
261 |
rset = self.execute('Any X,U,S,XT,UL,SN WHERE X created_by U, U in_state S, ' |
|
262 |
'X title XT, S name SN, U login UL, X eid %s' % e.eid) |
|
263 |
e = rset.get_entity(0, 0) |
|
264 |
self.assertEquals(e['title'], 'zou') |
|
265 |
self.assertEquals(pprelcachedict(e._related_cache), |
|
266 |
[('created_by_subject', [5])]) |
|
267 |
# first level of recursion |
|
268 |
u = e.created_by[0] |
|
269 |
self.assertEquals(u['login'], 'admin') |
|
270 |
self.assertRaises(KeyError, u.__getitem__, 'firstname') |
|
271 |
# second level of recursion |
|
272 |
s = u.in_state[0] |
|
273 |
self.assertEquals(s['name'], 'activated') |
|
274 |
self.assertRaises(KeyError, s.__getitem__, 'description') |
|
275 |
||
1640 | 276 |
|
0 | 277 |
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
|
278 |
eid = self.execute('INSERT CWUser E: E login "joe", E upassword "joe", E in_group G ' |
0 | 279 |
'WHERE G name "users"')[0][0] |
280 |
rset = self.execute('Any X,E WHERE X eid %(x)s, X primary_email E?', {'x': eid}) |
|
281 |
e = rset.get_entity(0, 0) |
|
282 |
# if any of the assertion below fails with a KeyError, the relation is not cached |
|
283 |
# related entities should be an empty list |
|
284 |
self.assertEquals(e.related_cache('primary_email', 'subject', True), []) |
|
285 |
# related rset should be an empty rset |
|
286 |
cached = e.related_cache('primary_email', 'subject', False) |
|
287 |
self.assertIsInstance(cached, ResultSet) |
|
288 |
self.assertEquals(cached.rowcount, 0) |
|
1640 | 289 |
|
0 | 290 |
|
291 |
def test_get_entity_union(self): |
|
292 |
e = self.add_entity('Bookmark', title=u'manger', path=u'path') |
|
293 |
rset = self.execute('Any X,N ORDERBY N WITH X,N BEING ' |
|
294 |
'((Any X,N WHERE X is Bookmark, X title N)' |
|
295 |
' UNION ' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
296 |
' (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
|
297 |
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
|
298 |
('Bookmark', 'manger'), ('CWGroup', 'owners'), |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
299 |
('CWGroup', 'users')) |
0 | 300 |
for entity in rset.entities(): # test get_entity for each row actually |
301 |
etype, n = expected[entity.row] |
|
302 |
self.assertEquals(entity.id, etype) |
|
303 |
attr = etype == 'Bookmark' and 'title' or 'name' |
|
304 |
self.assertEquals(entity[attr], n) |
|
1640 | 305 |
|
572
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
306 |
def test_related_entity_optional(self): |
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
307 |
e = self.add_entity('Bookmark', title=u'aaaa', path=u'path') |
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
308 |
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
|
309 |
entity, rtype = rset.related_entity(0, 2) |
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
310 |
self.assertEquals(entity, None) |
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
311 |
self.assertEquals(rtype, None) |
1640 | 312 |
|
0 | 313 |
def test_related_entity_union_subquery(self): |
314 |
e = self.add_entity('Bookmark', title=u'aaaa', path=u'path') |
|
315 |
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
|
316 |
'((Any X,N WHERE X is CWGroup, X name N)' |
0 | 317 |
' UNION ' |
318 |
' (Any X,N WHERE X is Bookmark, X title N))') |
|
319 |
entity, rtype = rset.related_entity(0, 1) |
|
320 |
self.assertEquals(entity.eid, e.eid) |
|
321 |
self.assertEquals(rtype, 'title') |
|
322 |
entity, rtype = rset.related_entity(1, 1) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
323 |
self.assertEquals(entity.id, 'CWGroup') |
0 | 324 |
self.assertEquals(rtype, 'name') |
325 |
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
|
326 |
'((Any X,N WHERE X is CWGroup, X name N)' |
0 | 327 |
' UNION ' |
328 |
' (Any X,N WHERE X is Bookmark, X title N))') |
|
329 |
entity, rtype = rset.related_entity(0, 1) |
|
330 |
self.assertEquals(entity.eid, e.eid) |
|
331 |
self.assertEquals(rtype, 'title') |
|
1640 | 332 |
|
0 | 333 |
def test_entities(self): |
334 |
rset = self.execute('Any U,G WHERE U in_group G') |
|
335 |
# make sure we have at least one element |
|
336 |
self.failUnless(rset) |
|
337 |
self.assertEquals(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
|
338 |
set(['CWUser',])) |
0 | 339 |
self.assertEquals(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
|
340 |
set(['CWGroup',])) |
0 | 341 |
|
1640 | 342 |
def test_printable_rql(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
343 |
rset = self.execute(u'CWEType X WHERE X final FALSE, X meta FALSE') |
0 | 344 |
self.assertEquals(rset.printable_rql(), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
345 |
'Any X WHERE X final FALSE, X meta FALSE, X is CWEType') |
0 | 346 |
|
347 |
||
348 |
def test_searched_text(self): |
|
349 |
rset = self.execute(u'Any X WHERE X has_text "foobar"') |
|
350 |
self.assertEquals(rset.searched_text(), 'foobar') |
|
351 |
rset = self.execute(u'Any X WHERE X has_text %(text)s', {'text' : 'foo'}) |
|
352 |
self.assertEquals(rset.searched_text(), 'foo') |
|
1640 | 353 |
|
354 |
||
0 | 355 |
if __name__ == '__main__': |
356 |
unittest_main() |