author | sylvain.thenault@logilab.fr |
Thu, 23 Apr 2009 16:09:35 +0200 | |
branch | tls-sprint |
changeset 1449 | 7751785c0815 |
parent 1398 | 5fe84a5f7035 |
child 1640 | 65b60f177eb1 |
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 |
||
15 |
||
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()) |
|
21 |
||
22 |
||
23 |
class AttrDescIteratorTC(TestCase): |
|
24 |
"""TestCase for cubicweb.rset.attr_desc_iterator""" |
|
25 |
||
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)) |
|
38 |
||
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 |
||
52 |
class ResultSetTC(EnvBasedTC): |
|
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 |
||
70 |
||
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) |
|
82 |
||
83 |
||
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, []) |
|
105 |
||
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' |
|
115 |
||
116 |
rs2 = rs.filtered_rset(test_filter) |
|
117 |
self.assertEquals(len(rs2), 2) |
|
118 |
self.assertEquals([login for _, login in rs2], ['adim', 'syt']) |
|
119 |
||
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']]) |
|
131 |
||
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 |
|
138 |
||
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']) |
|
144 |
||
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 |
|
168 |
||
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']) |
|
176 |
||
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"]) |
|
201 |
||
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), []) |
|
219 |
||
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') |
|
224 |
||
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') |
|
633 | 230 |
with traced_selection(): |
231 |
self.assertEquals(e.view('text'), 'zou') |
|
0 | 232 |
self.assertEquals(pprelcachedict(e._related_cache), []) |
233 |
||
234 |
e = rset.get_entity(0, 1) |
|
235 |
self.assertEquals(e.row, 0) |
|
236 |
self.assertEquals(e.col, 1) |
|
237 |
self.assertEquals(e['login'], 'anon') |
|
238 |
self.assertRaises(KeyError, e.__getitem__, 'firstname') |
|
239 |
self.assertEquals(pprelcachedict(e._related_cache), |
|
240 |
[]) |
|
241 |
e.complete() |
|
242 |
self.assertEquals(e['firstname'], None) |
|
243 |
self.assertEquals(e.view('text'), 'anon') |
|
244 |
self.assertEquals(pprelcachedict(e._related_cache), |
|
245 |
[]) |
|
246 |
||
247 |
self.assertRaises(NotAnEntity, rset.get_entity, 0, 2) |
|
248 |
self.assertRaises(NotAnEntity, rset.get_entity, 0, 3) |
|
249 |
||
250 |
def test_get_entity_relation_cache_compt(self): |
|
251 |
rset = self.execute('Any X,S WHERE X in_state S, X login "anon"') |
|
252 |
e = rset.get_entity(0, 0) |
|
253 |
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
|
254 |
# for_user / in_group are prefetched in CWUser __init__, in_state should |
0 | 255 |
# be filed from our query rset |
256 |
self.assertEquals(pprelcachedict(e._related_cache), |
|
257 |
[('in_state_subject', [seid])]) |
|
258 |
||
259 |
def test_get_entity_advanced_prefilled_cache(self): |
|
260 |
e = self.add_entity('Bookmark', title=u'zou', path=u'path') |
|
261 |
self.commit() |
|
262 |
rset = self.execute('Any X,U,S,XT,UL,SN WHERE X created_by U, U in_state S, ' |
|
263 |
'X title XT, S name SN, U login UL, X eid %s' % e.eid) |
|
264 |
e = rset.get_entity(0, 0) |
|
265 |
self.assertEquals(e['title'], 'zou') |
|
266 |
self.assertEquals(pprelcachedict(e._related_cache), |
|
267 |
[('created_by_subject', [5])]) |
|
268 |
# first level of recursion |
|
269 |
u = e.created_by[0] |
|
270 |
self.assertEquals(u['login'], 'admin') |
|
271 |
self.assertRaises(KeyError, u.__getitem__, 'firstname') |
|
272 |
# second level of recursion |
|
273 |
s = u.in_state[0] |
|
274 |
self.assertEquals(s['name'], 'activated') |
|
275 |
self.assertRaises(KeyError, s.__getitem__, 'description') |
|
276 |
||
277 |
||
278 |
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
|
279 |
eid = self.execute('INSERT CWUser E: E login "joe", E upassword "joe", E in_group G ' |
0 | 280 |
'WHERE G name "users"')[0][0] |
281 |
rset = self.execute('Any X,E WHERE X eid %(x)s, X primary_email E?', {'x': eid}) |
|
282 |
e = rset.get_entity(0, 0) |
|
283 |
# if any of the assertion below fails with a KeyError, the relation is not cached |
|
284 |
# related entities should be an empty list |
|
285 |
self.assertEquals(e.related_cache('primary_email', 'subject', True), []) |
|
286 |
# related rset should be an empty rset |
|
287 |
cached = e.related_cache('primary_email', 'subject', False) |
|
288 |
self.assertIsInstance(cached, ResultSet) |
|
289 |
self.assertEquals(cached.rowcount, 0) |
|
290 |
||
291 |
||
292 |
def test_get_entity_union(self): |
|
293 |
e = self.add_entity('Bookmark', title=u'manger', path=u'path') |
|
294 |
rset = self.execute('Any X,N ORDERBY N WITH X,N BEING ' |
|
295 |
'((Any X,N WHERE X is Bookmark, X title N)' |
|
296 |
' UNION ' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
297 |
' (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
|
298 |
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
|
299 |
('Bookmark', 'manger'), ('CWGroup', 'owners'), |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
692
diff
changeset
|
300 |
('CWGroup', 'users')) |
0 | 301 |
for entity in rset.entities(): # test get_entity for each row actually |
302 |
etype, n = expected[entity.row] |
|
303 |
self.assertEquals(entity.id, etype) |
|
304 |
attr = etype == 'Bookmark' and 'title' or 'name' |
|
305 |
self.assertEquals(entity[attr], n) |
|
306 |
||
572
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
307 |
def test_related_entity_optional(self): |
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
self.assertEquals(entity, None) |
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
312 |
self.assertEquals(rtype, None) |
9849fed789c9
test and fix potential error with None optional relation
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
313 |
|
0 | 314 |
def test_related_entity_union_subquery(self): |
315 |
e = self.add_entity('Bookmark', title=u'aaaa', path=u'path') |
|
316 |
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
|
317 |
'((Any X,N WHERE X is CWGroup, X name N)' |
0 | 318 |
' UNION ' |
319 |
' (Any X,N WHERE X is Bookmark, X title N))') |
|
320 |
entity, rtype = rset.related_entity(0, 1) |
|
321 |
self.assertEquals(entity.eid, e.eid) |
|
322 |
self.assertEquals(rtype, 'title') |
|
323 |
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
|
324 |
self.assertEquals(entity.id, 'CWGroup') |
0 | 325 |
self.assertEquals(rtype, 'name') |
326 |
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
|
327 |
'((Any X,N WHERE X is CWGroup, X name N)' |
0 | 328 |
' UNION ' |
329 |
' (Any X,N WHERE X is Bookmark, X title N))') |
|
330 |
entity, rtype = rset.related_entity(0, 1) |
|
331 |
self.assertEquals(entity.eid, e.eid) |
|
332 |
self.assertEquals(rtype, 'title') |
|
333 |
||
334 |
def test_entities(self): |
|
335 |
rset = self.execute('Any U,G WHERE U in_group G') |
|
336 |
# make sure we have at least one element |
|
337 |
self.failUnless(rset) |
|
338 |
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
|
339 |
set(['CWUser',])) |
0 | 340 |
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
|
341 |
set(['CWGroup',])) |
0 | 342 |
|
343 |
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
|
344 |
rset = self.execute(u'CWEType X WHERE X final FALSE, X meta FALSE') |
0 | 345 |
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
|
346 |
'Any X WHERE X final FALSE, X meta FALSE, X is CWEType') |
0 | 347 |
|
348 |
||
349 |
def test_searched_text(self): |
|
350 |
rset = self.execute(u'Any X WHERE X has_text "foobar"') |
|
351 |
self.assertEquals(rset.searched_text(), 'foobar') |
|
352 |
rset = self.execute(u'Any X WHERE X has_text %(text)s', {'text' : 'foo'}) |
|
353 |
self.assertEquals(rset.searched_text(), 'foo') |
|
354 |
||
355 |
||
356 |
if __name__ == '__main__': |
|
357 |
unittest_main() |