author | sylvain.thenault@logilab.fr |
Thu, 09 Apr 2009 15:52:31 +0200 | |
branch | tls-sprint |
changeset 1322 | 92a2375b1de6 |
parent 1284 | 63ed4f4ff38d |
child 1341 | 9502d02630bf |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
"""unit tests for cubicweb.web.views.entities module""" |
|
3 |
||
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
821
diff
changeset
|
4 |
from datetime import datetime |
821
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
5 |
|
0 | 6 |
from cubicweb import Binary |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
821
diff
changeset
|
7 |
from cubicweb.devtools.apptest import EnvBasedTC |
821
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
8 |
from cubicweb.common.mttransforms import HAS_TAL |
0 | 9 |
|
10 |
class EntityTC(EnvBasedTC): |
|
11 |
||
12 |
## def setup_database(self): |
|
13 |
## self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
14 |
## self.add_entity('Task', title=u'fait ca !', description=u'et plus vite', start=now()) |
|
15 |
## self.add_entity('Tag', name=u'x') |
|
16 |
## self.add_entity('Link', title=u'perdu', url=u'http://www.perdu.com', |
|
17 |
## embed=False) |
|
18 |
||
19 |
def test_boolean_value(self): |
|
744 | 20 |
e = self.etype_instance('EUser') |
0 | 21 |
self.failUnless(e) |
22 |
||
23 |
def test_yams_inheritance(self): |
|
748 | 24 |
from entities import Note |
0 | 25 |
e = self.etype_instance('SubNote') |
748 | 26 |
self.assertIsInstance(e, Note) |
0 | 27 |
e2 = self.etype_instance('SubNote') |
28 |
self.assertIs(e.__class__, e2.__class__) |
|
29 |
||
30 |
def test_has_eid(self): |
|
744 | 31 |
e = self.etype_instance('EUser') |
0 | 32 |
self.assertEquals(e.eid, None) |
33 |
self.assertEquals(e.has_eid(), False) |
|
34 |
e.eid = 'X' |
|
35 |
self.assertEquals(e.has_eid(), False) |
|
36 |
e.eid = 0 |
|
37 |
self.assertEquals(e.has_eid(), True) |
|
38 |
e.eid = 2 |
|
39 |
self.assertEquals(e.has_eid(), True) |
|
40 |
||
41 |
def test_copy(self): |
|
42 |
self.add_entity('Tag', name=u'x') |
|
43 |
p = self.add_entity('Personne', nom=u'toto') |
|
44 |
oe = self.add_entity('Note', type=u'x') |
|
45 |
self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
|
46 |
{'t': oe.eid, 'u': p.eid}, ('t','u')) |
|
47 |
self.execute('SET TAG tags X WHERE X eid %(x)s', {'x': oe.eid}, 'x') |
|
48 |
e = self.add_entity('Note', type=u'z') |
|
49 |
e.copy_relations(oe.eid) |
|
50 |
self.assertEquals(len(e.ecrit_par), 1) |
|
51 |
self.assertEquals(e.ecrit_par[0].eid, p.eid) |
|
52 |
self.assertEquals(len(e.reverse_tags), 0) |
|
53 |
||
54 |
def test_copy_with_nonmeta_composite_inlined(self): |
|
55 |
p = self.add_entity('Personne', nom=u'toto') |
|
56 |
oe = self.add_entity('Note', type=u'x') |
|
57 |
self.schema['ecrit_par'].set_rproperty('Note', 'Personne', 'composite', 'subject') |
|
58 |
self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
|
59 |
{'t': oe.eid, 'u': p.eid}, ('t','u')) |
|
60 |
e = self.add_entity('Note', type=u'z') |
|
61 |
e.copy_relations(oe.eid) |
|
62 |
self.failIf(e.ecrit_par) |
|
63 |
self.failUnless(oe.ecrit_par) |
|
64 |
||
65 |
def test_copy_with_composite(self): |
|
66 |
user = self.user() |
|
67 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
|
68 |
e = self.entity('Any X WHERE X eid %(x)s', {'x':user.eid}, 'x') |
|
69 |
self.assertEquals(e.use_email[0].address, "toto@logilab.org") |
|
70 |
self.assertEquals(e.use_email[0].eid, adeleid) |
|
71 |
usereid = self.execute('INSERT EUser X: X login "toto", X upassword "toto", X in_group G, X in_state S ' |
|
72 |
'WHERE G name "users", S name "activated"')[0][0] |
|
73 |
e = self.entity('Any X WHERE X eid %(x)s', {'x':usereid}, 'x') |
|
74 |
e.copy_relations(user.eid) |
|
75 |
self.failIf(e.use_email) |
|
76 |
self.failIf(e.primary_email) |
|
77 |
||
78 |
def test_copy_with_non_initial_state(self): |
|
79 |
user = self.user() |
|
80 |
eid = self.execute('INSERT EUser X: X login "toto", X upassword %(pwd)s, X in_group G WHERE G name "users"', |
|
81 |
{'pwd': 'toto'})[0][0] |
|
82 |
self.commit() |
|
83 |
self.execute('SET X in_state S WHERE X eid %(x)s, S name "deactivated"', {'x': eid}, 'x') |
|
84 |
self.commit() |
|
85 |
eid2 = self.execute('INSERT EUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0] |
|
86 |
e = self.entity('Any X WHERE X eid %(x)s', {'x': eid2}, 'x') |
|
87 |
e.copy_relations(eid) |
|
88 |
self.commit() |
|
89 |
e.clear_related_cache('in_state', 'subject') |
|
90 |
self.assertEquals(e.state, 'activated') |
|
91 |
||
92 |
def test_related_cache_both(self): |
|
93 |
user = self.entity('Any X WHERE X eid %(x)s', {'x':self.user().eid}, 'x') |
|
94 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
|
95 |
self.commit() |
|
96 |
self.assertEquals(user._related_cache.keys(), []) |
|
97 |
email = user.primary_email[0] |
|
98 |
self.assertEquals(sorted(user._related_cache), ['primary_email_subject']) |
|
99 |
self.assertEquals(email._related_cache.keys(), ['primary_email_object']) |
|
100 |
groups = user.in_group |
|
101 |
self.assertEquals(sorted(user._related_cache), ['in_group_subject', 'primary_email_subject']) |
|
102 |
for group in groups: |
|
103 |
self.failIf('in_group_subject' in group._related_cache, group._related_cache.keys()) |
|
413
a7366dd3c33c
fix bug in entity.related_rql(): fetch_attr list / fetchorder weren't computed correctly
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
104 |
|
0 | 105 |
def test_related_limit(self): |
106 |
p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
107 |
for tag in u'abcd': |
|
108 |
self.add_entity('Tag', name=tag) |
|
109 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
|
110 |
self.assertEquals(len(p.related('tags', 'object', limit=2)), 2) |
|
111 |
self.assertEquals(len(p.related('tags', 'object')), 4) |
|
112 |
||
113 |
||
114 |
def test_fetch_rql(self): |
|
115 |
user = self.user() |
|
116 |
Personne = self.vreg.etype_class('Personne') |
|
117 |
Societe = self.vreg.etype_class('Societe') |
|
118 |
Note = self.vreg.etype_class('Note') |
|
119 |
peschema = Personne.e_schema |
|
120 |
seschema = Societe.e_schema |
|
121 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '1*') |
|
122 |
peschema.subject_relation('connait').set_rproperty(peschema, peschema, 'cardinality', '11') |
|
123 |
peschema.subject_relation('evaluee').set_rproperty(peschema, Note.e_schema, 'cardinality', '1*') |
|
124 |
seschema.subject_relation('evaluee').set_rproperty(seschema, Note.e_schema, 'cardinality', '1*') |
|
125 |
# testing basic fetch_attrs attribute |
|
126 |
self.assertEquals(Personne.fetch_rql(user), |
|
127 |
'Any X,AA,AB,AC ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB, X modification_date AC') |
|
128 |
pfetch_attrs = Personne.fetch_attrs |
|
129 |
sfetch_attrs = Societe.fetch_attrs |
|
130 |
try: |
|
131 |
# testing unknown attributes |
|
132 |
Personne.fetch_attrs = ('bloug', 'beep') |
|
133 |
self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne') |
|
134 |
# testing one non final relation |
|
135 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
136 |
self.assertEquals(Personne.fetch_rql(user), |
|
137 |
'Any X,AA,AB,AC,AD ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB, X travaille AC, AC nom AD') |
|
138 |
# testing two non final relations |
|
139 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee') |
|
140 |
self.assertEquals(Personne.fetch_rql(user), |
|
141 |
'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC WHERE X is Personne, X nom AA, ' |
|
142 |
'X prenom AB, X travaille AC, AC nom AD, X evaluee AE, AE modification_date AF') |
|
143 |
# testing one non final relation with recursion |
|
144 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
145 |
Societe.fetch_attrs = ('nom', 'evaluee') |
|
146 |
self.assertEquals(Personne.fetch_rql(user), |
|
147 |
'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC WHERE X is Personne, X nom AA, X prenom AB, ' |
|
148 |
'X travaille AC, AC nom AD, AC evaluee AE, AE modification_date AF' |
|
149 |
) |
|
150 |
# testing symetric relation |
|
151 |
Personne.fetch_attrs = ('nom', 'connait') |
|
152 |
self.assertEquals(Personne.fetch_rql(user), 'Any X,AA,AB ORDERBY AA ASC WHERE X is Personne, X nom AA, X connait AB') |
|
153 |
# testing optional relation |
|
154 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '?*') |
|
155 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
156 |
Societe.fetch_attrs = ('nom',) |
|
157 |
self.assertEquals(Personne.fetch_rql(user), |
|
158 |
'Any X,AA,AB,AC,AD ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
|
159 |
# testing relation with cardinality > 1 |
|
160 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '**') |
|
161 |
self.assertEquals(Personne.fetch_rql(user), |
|
162 |
'Any X,AA,AB ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB') |
|
163 |
# XXX test unauthorized attribute |
|
164 |
finally: |
|
165 |
Personne.fetch_attrs = pfetch_attrs |
|
166 |
Societe.fetch_attrs = sfetch_attrs |
|
167 |
||
413
a7366dd3c33c
fix bug in entity.related_rql(): fetch_attr list / fetchorder weren't computed correctly
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
168 |
def test_related_rql(self): |
a7366dd3c33c
fix bug in entity.related_rql(): fetch_attr list / fetchorder weren't computed correctly
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
169 |
from cubicweb.entities import fetch_config |
a7366dd3c33c
fix bug in entity.related_rql(): fetch_attr list / fetchorder weren't computed correctly
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
170 |
Personne = self.vreg.etype_class('Personne') |
744 | 171 |
Note = self.vreg.etype_class('Note') |
172 |
Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type')) |
|
173 |
Note.fetch_attrs, Note.fetch_order = fetch_config(('type',)) |
|
174 |
aff = self.add_entity('Personne', nom=u'pouet') |
|
175 |
self.assertEquals(aff.related_rql('evaluee'), |
|
176 |
'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, ' |
|
177 |
'X type AA, X modification_date AB') |
|
178 |
Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) |
|
179 |
# XXX |
|
180 |
self.assertEquals(aff.related_rql('evaluee'), |
|
181 |
'Any X,AA ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E evaluee X, X modification_date AA') |
|
413
a7366dd3c33c
fix bug in entity.related_rql(): fetch_attr list / fetchorder weren't computed correctly
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
182 |
|
0 | 183 |
def test_entity_unrelated(self): |
184 |
p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
185 |
e = self.add_entity('Tag', name=u'x') |
|
186 |
rschema = e.e_schema.subject_relation('tags') |
|
187 |
related = [r.eid for r in e.tags] |
|
188 |
self.failUnlessEqual(related, []) |
|
189 |
unrelated = [reid for rview, reid in e.vocabulary(rschema, 'subject')] |
|
190 |
self.failUnless(p.eid in unrelated) |
|
191 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
|
192 |
e = self.entity('Any X WHERE X is Tag') |
|
193 |
unrelated = [reid for rview, reid in e.vocabulary(rschema, 'subject')] |
|
194 |
self.failIf(p.eid in unrelated) |
|
195 |
||
196 |
def test_entity_unrelated_limit(self): |
|
197 |
e = self.add_entity('Tag', name=u'x') |
|
198 |
self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
199 |
self.add_entity('Personne', nom=u'di mascio', prenom=u'gwen') |
|
200 |
rschema = e.e_schema.subject_relation('tags') |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
821
diff
changeset
|
201 |
self.assertEquals(len(e.unrelated(rschema, 'Personne', 'subject', limit=1)), |
0 | 202 |
1) |
203 |
||
204 |
def test_new_entity_unrelated(self): |
|
205 |
e = self.etype_instance('EUser') |
|
206 |
rschema = e.e_schema.subject_relation('in_group') |
|
207 |
unrelated = [reid for rview, reid in e.vocabulary(rschema, 'subject')] |
|
208 |
# should be default groups but owners, i.e. managers, users, guests |
|
209 |
self.assertEquals(len(unrelated), 3) |
|
210 |
||
211 |
def test_printable_value_string(self): |
|
212 |
e = self.add_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
|
213 |
content_format=u'text/rest') |
|
214 |
self.assertEquals(e.printable_value('content'), |
|
215 |
'<p>du <a class="reference" href="http://testing.fr/cubicweb/egroup/managers">*ReST*</a></p>\n') |
|
216 |
e['content'] = 'du <em>html</em> <ref rql="EUser X">users</ref>' |
|
217 |
e['content_format'] = 'text/html' |
|
218 |
self.assertEquals(e.printable_value('content'), |
|
219 |
'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=EUser%20X">users</a>') |
|
220 |
e['content'] = 'du *texte*' |
|
221 |
e['content_format'] = 'text/plain' |
|
222 |
self.assertEquals(e.printable_value('content'), |
|
223 |
'<p>\ndu *texte*\n</p>') |
|
224 |
e['title'] = 'zou' |
|
225 |
#e = self.etype_instance('Task') |
|
226 |
e['content'] = '''\ |
|
227 |
a title |
|
228 |
======= |
|
229 |
du :eid:`1:*ReST*`''' |
|
230 |
e['content_format'] = 'text/rest' |
|
231 |
self.assertEquals(e.printable_value('content', format='text/plain'), |
|
232 |
e['content']) |
|
233 |
||
234 |
e['content'] = u'<b>yo (zou éà ;)</b>' |
|
235 |
e['content_format'] = 'text/html' |
|
236 |
self.assertEquals(e.printable_value('content', format='text/plain').strip(), |
|
237 |
u'**yo (zou éà ;)**') |
|
821
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
238 |
if HAS_TAL: |
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
239 |
e['content'] = '<h1 tal:content="self/title">titre</h1>' |
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
240 |
e['content_format'] = 'text/cubicweb-page-template' |
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
241 |
self.assertEquals(e.printable_value('content'), |
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
242 |
'<h1>zou</h1>') |
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
243 |
|
0 | 244 |
|
245 |
def test_printable_value_bytes(self): |
|
246 |
e = self.add_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python', |
|
247 |
data_encoding=u'ascii', name=u'toto.py') |
|
248 |
from cubicweb.common import mttransforms |
|
249 |
if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
|
250 |
self.assertEquals(e.printable_value('data'), |
|
251 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
|
252 |
</pre></div> |
|
253 |
''') |
|
254 |
else: |
|
255 |
self.assertEquals(e.printable_value('data'), |
|
256 |
'''<pre class="python"> |
|
257 |
<span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
|
258 |
</pre> |
|
259 |
''') |
|
260 |
||
261 |
e = self.add_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
|
262 |
data_encoding=u'utf-8', name=u'toto.txt') |
|
263 |
self.assertEquals(e.printable_value('data'), |
|
264 |
u'<p><em>héhéhé</em></p>\n') |
|
265 |
||
266 |
def test_printable_value_bad_html(self): |
|
267 |
"""make sure we don't crash if we try to render invalid XHTML strings""" |
|
268 |
e = self.add_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
|
269 |
content_format=u'text/html') |
|
270 |
tidy = lambda x: x.replace('\n', '') |
|
271 |
self.assertEquals(tidy(e.printable_value('content')), |
|
272 |
'<div>R&D<br/></div>') |
|
273 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
274 |
self.assertEquals(tidy(e.printable_value('content')), |
|
275 |
u'yo !! R&D <div> pas fermé</div>') |
|
276 |
e['content'] = u'R&D' |
|
277 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D') |
|
278 |
e['content'] = u'R&D;' |
|
279 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D;') |
|
280 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
281 |
self.assertEquals(tidy(e.printable_value('content')), |
|
282 |
u'yo !! R&D <div> pas fermé</div>') |
|
283 |
e['content'] = u'été <div> été' |
|
284 |
self.assertEquals(tidy(e.printable_value('content')), |
|
285 |
u'été <div> été</div>') |
|
286 |
e['content'] = u'C'est un exemple sérieux' |
|
287 |
self.assertEquals(tidy(e.printable_value('content')), |
|
288 |
u"C'est un exemple sérieux") |
|
289 |
# make sure valid xhtml is left untouched |
|
290 |
e['content'] = u'<div>R&D<br/></div>' |
|
291 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
292 |
e['content'] = u'<div>été</div>' |
|
293 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
294 |
e['content'] = u'été' |
|
295 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
296 |
||
297 |
||
298 |
def test_fulltextindex(self): |
|
299 |
e = self.etype_instance('File') |
|
300 |
e['name'] = 'an html file' |
|
301 |
e['description'] = 'du <em>html</em>' |
|
302 |
e['description_format'] = 'text/html' |
|
303 |
e['data'] = Binary('some <em>data</em>') |
|
304 |
e['data_format'] = 'text/html' |
|
305 |
e['data_encoding'] = 'ascii' |
|
306 |
self.assertEquals(set(e.get_words()), |
|
307 |
set(['an', 'html', 'file', 'du', 'html', 'some', 'data'])) |
|
308 |
||
309 |
||
310 |
def test_nonregr_relation_cache(self): |
|
311 |
p1 = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
312 |
p2 = self.add_entity('Personne', nom=u'toto') |
|
313 |
self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"') |
|
314 |
self.assertEquals(p1.evaluee[0].nom, "toto") |
|
315 |
self.failUnless(not p1.reverse_evaluee) |
|
316 |
||
317 |
def test_complete_relation(self): |
|
318 |
self.execute('SET RT add_permission G WHERE RT name "wf_info_for", G name "managers"') |
|
319 |
self.commit() |
|
320 |
try: |
|
321 |
eid = self.execute('INSERT TrInfo X: X comment "zou", X wf_info_for U,' |
|
322 |
'X from_state S1, X to_state S2 WHERE ' |
|
323 |
'U login "admin", S1 name "activated", S2 name "deactivated"')[0][0] |
|
324 |
trinfo = self.entity('Any X WHERE X eid %(x)s', {'x': eid}, 'x') |
|
325 |
trinfo.complete() |
|
326 |
self.failUnless(trinfo.relation_cached('from_state', 'subject')) |
|
327 |
self.failUnless(trinfo.relation_cached('to_state', 'subject')) |
|
328 |
self.failUnless(trinfo.relation_cached('wf_info_for', 'subject')) |
|
329 |
# check with a missing relation |
|
330 |
eid = self.execute('INSERT TrInfo X: X comment "zou", X wf_info_for U,' |
|
331 |
'X to_state S2 WHERE ' |
|
332 |
'U login "admin", S2 name "activated"')[0][0] |
|
333 |
trinfo = self.entity('Any X WHERE X eid %(x)s', {'x': eid}, 'x') |
|
334 |
trinfo.complete() |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
821
diff
changeset
|
335 |
self.failUnless(isinstance(trinfo.creation_date, datetime)) |
0 | 336 |
self.failUnless(trinfo.relation_cached('from_state', 'subject')) |
337 |
self.failUnless(trinfo.relation_cached('to_state', 'subject')) |
|
338 |
self.failUnless(trinfo.relation_cached('wf_info_for', 'subject')) |
|
339 |
self.assertEquals(trinfo.from_state, []) |
|
340 |
finally: |
|
341 |
self.rollback() |
|
342 |
self.execute('DELETE RT add_permission G WHERE RT name "wf_info_for", G name "managers"') |
|
343 |
self.commit() |
|
344 |
||
345 |
def test_request_cache(self): |
|
346 |
req = self.request() |
|
347 |
user = self.entity('EUser X WHERE X login "admin"', req=req) |
|
348 |
state = user.in_state[0] |
|
349 |
samestate = self.entity('State X WHERE X name "activated"', req=req) |
|
350 |
self.failUnless(state is samestate) |
|
351 |
||
352 |
def test_rest_path(self): |
|
353 |
note = self.add_entity('Note', type=u'z') |
|
354 |
self.assertEquals(note.rest_path(), 'note/%s' % note.eid) |
|
355 |
# unique attr |
|
356 |
tag = self.add_entity('Tag', name=u'x') |
|
357 |
self.assertEquals(tag.rest_path(), 'tag/x') |
|
358 |
# test explicit rest_attr |
|
359 |
person = self.add_entity('Personne', prenom=u'john', nom=u'doe') |
|
360 |
self.assertEquals(person.rest_path(), 'personne/doe') |
|
361 |
# ambiguity test |
|
362 |
person2 = self.add_entity('Personne', prenom=u'remi', nom=u'doe') |
|
363 |
self.assertEquals(person.rest_path(), 'personne/eid/%s' % person.eid) |
|
364 |
self.assertEquals(person2.rest_path(), 'personne/eid/%s' % person2.eid) |
|
365 |
# unique attr with None value (wikiid in this case) |
|
366 |
card1 = self.add_entity('Card', title=u'hop') |
|
367 |
self.assertEquals(card1.rest_path(), 'card/eid/%s' % card1.eid) |
|
368 |
card2 = self.add_entity('Card', title=u'pod', wikiid=u'zob/i') |
|
369 |
self.assertEquals(card2.rest_path(), 'card/zob%2Fi') |
|
370 |
||
371 |
def test_set_attributes(self): |
|
372 |
person = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
373 |
self.assertEquals(person.prenom, u'adrien') |
|
374 |
self.assertEquals(person.nom, u'di mascio') |
|
375 |
person.set_attributes(prenom=u'sylvain', nom=u'thénault') |
|
376 |
person = self.entity('Personne P') # XXX retreival needed ? |
|
377 |
self.assertEquals(person.prenom, u'sylvain') |
|
378 |
self.assertEquals(person.nom, u'thénault') |
|
379 |
||
380 |
def test_metainformation(self): |
|
381 |
note = self.add_entity('Note', type=u'z') |
|
382 |
metainf = note.metainformation() |
|
383 |
self.assertEquals(metainf, {'source': {'adapter': 'native', 'uri': 'system'}, 'type': u'Note', 'extid': None}) |
|
384 |
self.assertEquals(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid) |
|
385 |
metainf['source'] = metainf['source'].copy() |
|
386 |
metainf['source']['base-url'] = 'http://cubicweb2.com/' |
|
387 |
self.assertEquals(note.absolute_url(), 'http://cubicweb2.com/note/%s' % note.eid) |
|
388 |
||
389 |
if __name__ == '__main__': |
|
390 |
from logilab.common.testlib import unittest_main |
|
391 |
unittest_main() |
|
392 |