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