author | Katia Saurfelt <katia.saurfelt@logilab.fr> |
Tue, 19 May 2009 14:31:42 +0200 | |
branch | stable |
changeset 1868 | af1ae863606d |
parent 1640 | 65b60f177eb1 |
child 1905 | 9c96dd7cc624 |
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) |
|
1640 | 18 |
|
0 | 19 |
def test_boolean_value(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
20 |
e = self.etype_instance('CWUser') |
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): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
31 |
e = self.etype_instance('CWUser') |
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) |
|
1640 | 40 |
|
0 | 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) |
|
1640 | 53 |
|
0 | 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) |
|
1640 | 64 |
|
0 | 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) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
71 |
usereid = self.execute('INSERT CWUser X: X login "toto", X upassword "toto", X in_group G, X in_state S ' |
0 | 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) |
|
1640 | 77 |
|
0 | 78 |
def test_copy_with_non_initial_state(self): |
79 |
user = self.user() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
80 |
eid = self.execute('INSERT CWUser X: X login "toto", X upassword %(pwd)s, X in_group G WHERE G name "users"', |
0 | 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() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
85 |
eid2 = self.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][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 |
||
1640 | 113 |
|
0 | 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') |
|
1640 | 133 |
self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne') |
0 | 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') |
|
1640 | 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 |
related = [r.eid for r in e.tags] |
|
187 |
self.failUnlessEqual(related, []) |
|
1341 | 188 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
0 | 189 |
self.failUnless(p.eid in unrelated) |
190 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
|
191 |
e = self.entity('Any X WHERE X is Tag') |
|
1341 | 192 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
0 | 193 |
self.failIf(p.eid in unrelated) |
194 |
||
195 |
def test_entity_unrelated_limit(self): |
|
196 |
e = self.add_entity('Tag', name=u'x') |
|
197 |
self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
198 |
self.add_entity('Personne', nom=u'di mascio', prenom=u'gwen') |
|
1341 | 199 |
self.assertEquals(len(e.unrelated('tags', 'Personne', 'subject', limit=1)), |
0 | 200 |
1) |
1640 | 201 |
|
0 | 202 |
def test_new_entity_unrelated(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
203 |
e = self.etype_instance('CWUser') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
204 |
unrelated = [r[0] for r in e.unrelated('in_group', 'CWGroup', 'subject')] |
0 | 205 |
# should be default groups but owners, i.e. managers, users, guests |
206 |
self.assertEquals(len(unrelated), 3) |
|
207 |
||
208 |
def test_printable_value_string(self): |
|
209 |
e = self.add_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
|
210 |
content_format=u'text/rest') |
|
211 |
self.assertEquals(e.printable_value('content'), |
|
1640 | 212 |
'<p>du <a class="reference" href="http://testing.fr/cubicweb/cwgroup/managers">*ReST*</a></p>\n') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
213 |
e['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
0 | 214 |
e['content_format'] = 'text/html' |
215 |
self.assertEquals(e.printable_value('content'), |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
216 |
'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
0 | 217 |
e['content'] = 'du *texte*' |
218 |
e['content_format'] = 'text/plain' |
|
219 |
self.assertEquals(e.printable_value('content'), |
|
220 |
'<p>\ndu *texte*\n</p>') |
|
221 |
e['title'] = 'zou' |
|
222 |
#e = self.etype_instance('Task') |
|
223 |
e['content'] = '''\ |
|
224 |
a title |
|
225 |
======= |
|
226 |
du :eid:`1:*ReST*`''' |
|
227 |
e['content_format'] = 'text/rest' |
|
228 |
self.assertEquals(e.printable_value('content', format='text/plain'), |
|
229 |
e['content']) |
|
230 |
||
231 |
e['content'] = u'<b>yo (zou éà ;)</b>' |
|
232 |
e['content_format'] = 'text/html' |
|
233 |
self.assertEquals(e.printable_value('content', format='text/plain').strip(), |
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
'<h1>zou</h1>') |
1640 | 240 |
|
0 | 241 |
|
242 |
def test_printable_value_bytes(self): |
|
243 |
e = self.add_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python', |
|
244 |
data_encoding=u'ascii', name=u'toto.py') |
|
245 |
from cubicweb.common import mttransforms |
|
246 |
if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
|
247 |
self.assertEquals(e.printable_value('data'), |
|
248 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
|
249 |
</pre></div> |
|
250 |
''') |
|
251 |
else: |
|
252 |
self.assertEquals(e.printable_value('data'), |
|
253 |
'''<pre class="python"> |
|
254 |
<span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
|
255 |
</pre> |
|
256 |
''') |
|
1640 | 257 |
|
0 | 258 |
e = self.add_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
259 |
data_encoding=u'utf-8', name=u'toto.txt') |
|
260 |
self.assertEquals(e.printable_value('data'), |
|
261 |
u'<p><em>héhéhé</em></p>\n') |
|
262 |
||
263 |
def test_printable_value_bad_html(self): |
|
264 |
"""make sure we don't crash if we try to render invalid XHTML strings""" |
|
265 |
e = self.add_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
|
266 |
content_format=u'text/html') |
|
267 |
tidy = lambda x: x.replace('\n', '') |
|
268 |
self.assertEquals(tidy(e.printable_value('content')), |
|
269 |
'<div>R&D<br/></div>') |
|
270 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
271 |
self.assertEquals(tidy(e.printable_value('content')), |
|
272 |
u'yo !! R&D <div> pas fermé</div>') |
|
273 |
e['content'] = u'R&D' |
|
274 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D') |
|
275 |
e['content'] = u'R&D;' |
|
276 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D;') |
|
277 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
278 |
self.assertEquals(tidy(e.printable_value('content')), |
|
279 |
u'yo !! R&D <div> pas fermé</div>') |
|
280 |
e['content'] = u'été <div> été' |
|
281 |
self.assertEquals(tidy(e.printable_value('content')), |
|
282 |
u'été <div> été</div>') |
|
283 |
e['content'] = u'C'est un exemple sérieux' |
|
284 |
self.assertEquals(tidy(e.printable_value('content')), |
|
285 |
u"C'est un exemple sérieux") |
|
286 |
# make sure valid xhtml is left untouched |
|
287 |
e['content'] = u'<div>R&D<br/></div>' |
|
288 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
289 |
e['content'] = u'<div>été</div>' |
|
290 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
291 |
e['content'] = u'été' |
|
292 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
1640 | 293 |
|
294 |
||
0 | 295 |
def test_fulltextindex(self): |
296 |
e = self.etype_instance('File') |
|
297 |
e['name'] = 'an html file' |
|
298 |
e['description'] = 'du <em>html</em>' |
|
299 |
e['description_format'] = 'text/html' |
|
300 |
e['data'] = Binary('some <em>data</em>') |
|
301 |
e['data_format'] = 'text/html' |
|
302 |
e['data_encoding'] = 'ascii' |
|
1640 | 303 |
self.assertEquals(set(e.get_words()), |
0 | 304 |
set(['an', 'html', 'file', 'du', 'html', 'some', 'data'])) |
305 |
||
1640 | 306 |
|
0 | 307 |
def test_nonregr_relation_cache(self): |
308 |
p1 = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
309 |
p2 = self.add_entity('Personne', nom=u'toto') |
|
310 |
self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"') |
|
311 |
self.assertEquals(p1.evaluee[0].nom, "toto") |
|
312 |
self.failUnless(not p1.reverse_evaluee) |
|
1640 | 313 |
|
0 | 314 |
def test_complete_relation(self): |
315 |
self.execute('SET RT add_permission G WHERE RT name "wf_info_for", G name "managers"') |
|
316 |
self.commit() |
|
317 |
try: |
|
318 |
eid = self.execute('INSERT TrInfo X: X comment "zou", X wf_info_for U,' |
|
319 |
'X from_state S1, X to_state S2 WHERE ' |
|
320 |
'U login "admin", S1 name "activated", S2 name "deactivated"')[0][0] |
|
321 |
trinfo = self.entity('Any X WHERE X eid %(x)s', {'x': eid}, 'x') |
|
322 |
trinfo.complete() |
|
323 |
self.failUnless(trinfo.relation_cached('from_state', 'subject')) |
|
324 |
self.failUnless(trinfo.relation_cached('to_state', 'subject')) |
|
325 |
self.failUnless(trinfo.relation_cached('wf_info_for', 'subject')) |
|
326 |
# check with a missing relation |
|
327 |
eid = self.execute('INSERT TrInfo X: X comment "zou", X wf_info_for U,' |
|
328 |
'X to_state S2 WHERE ' |
|
329 |
'U login "admin", S2 name "activated"')[0][0] |
|
330 |
trinfo = self.entity('Any X WHERE X eid %(x)s', {'x': eid}, 'x') |
|
331 |
trinfo.complete() |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
821
diff
changeset
|
332 |
self.failUnless(isinstance(trinfo.creation_date, datetime)) |
0 | 333 |
self.failUnless(trinfo.relation_cached('from_state', 'subject')) |
334 |
self.failUnless(trinfo.relation_cached('to_state', 'subject')) |
|
335 |
self.failUnless(trinfo.relation_cached('wf_info_for', 'subject')) |
|
336 |
self.assertEquals(trinfo.from_state, []) |
|
337 |
finally: |
|
338 |
self.rollback() |
|
339 |
self.execute('DELETE RT add_permission G WHERE RT name "wf_info_for", G name "managers"') |
|
340 |
self.commit() |
|
341 |
||
342 |
def test_request_cache(self): |
|
343 |
req = self.request() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
344 |
user = self.entity('CWUser X WHERE X login "admin"', req=req) |
0 | 345 |
state = user.in_state[0] |
346 |
samestate = self.entity('State X WHERE X name "activated"', req=req) |
|
347 |
self.failUnless(state is samestate) |
|
348 |
||
349 |
def test_rest_path(self): |
|
350 |
note = self.add_entity('Note', type=u'z') |
|
351 |
self.assertEquals(note.rest_path(), 'note/%s' % note.eid) |
|
352 |
# unique attr |
|
353 |
tag = self.add_entity('Tag', name=u'x') |
|
354 |
self.assertEquals(tag.rest_path(), 'tag/x') |
|
355 |
# test explicit rest_attr |
|
356 |
person = self.add_entity('Personne', prenom=u'john', nom=u'doe') |
|
357 |
self.assertEquals(person.rest_path(), 'personne/doe') |
|
358 |
# ambiguity test |
|
359 |
person2 = self.add_entity('Personne', prenom=u'remi', nom=u'doe') |
|
360 |
self.assertEquals(person.rest_path(), 'personne/eid/%s' % person.eid) |
|
361 |
self.assertEquals(person2.rest_path(), 'personne/eid/%s' % person2.eid) |
|
362 |
# unique attr with None value (wikiid in this case) |
|
363 |
card1 = self.add_entity('Card', title=u'hop') |
|
364 |
self.assertEquals(card1.rest_path(), 'card/eid/%s' % card1.eid) |
|
365 |
card2 = self.add_entity('Card', title=u'pod', wikiid=u'zob/i') |
|
366 |
self.assertEquals(card2.rest_path(), 'card/zob%2Fi') |
|
367 |
||
368 |
def test_set_attributes(self): |
|
369 |
person = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
370 |
self.assertEquals(person.prenom, u'adrien') |
|
371 |
self.assertEquals(person.nom, u'di mascio') |
|
372 |
person.set_attributes(prenom=u'sylvain', nom=u'thénault') |
|
373 |
person = self.entity('Personne P') # XXX retreival needed ? |
|
374 |
self.assertEquals(person.prenom, u'sylvain') |
|
375 |
self.assertEquals(person.nom, u'thénault') |
|
376 |
||
377 |
def test_metainformation(self): |
|
378 |
note = self.add_entity('Note', type=u'z') |
|
379 |
metainf = note.metainformation() |
|
380 |
self.assertEquals(metainf, {'source': {'adapter': 'native', 'uri': 'system'}, 'type': u'Note', 'extid': None}) |
|
381 |
self.assertEquals(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid) |
|
382 |
metainf['source'] = metainf['source'].copy() |
|
383 |
metainf['source']['base-url'] = 'http://cubicweb2.com/' |
|
384 |
self.assertEquals(note.absolute_url(), 'http://cubicweb2.com/note/%s' % note.eid) |
|
1640 | 385 |
|
0 | 386 |
if __name__ == '__main__': |
387 |
from logilab.common.testlib import unittest_main |
|
388 |
unittest_main() |
|
389 |