author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 20 Aug 2009 17:57:56 +0200 | |
branch | 3.5 |
changeset 2931 | 17224e90a1c4 |
parent 2920 | 64322aa83a1d |
parent 2930 | d7c23b2c7538 |
child 2968 | 0e3460341023 |
child 3136 | ed303cf3a048 |
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) |
|
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
58 |
self.assertEquals(len(e.reverse_tags), 1) |
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
59 |
# check meta-relations are not copied, set on commit |
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
60 |
self.assertEquals(len(e.created_by), 0) |
1640 | 61 |
|
0 | 62 |
def test_copy_with_nonmeta_composite_inlined(self): |
63 |
p = self.add_entity('Personne', nom=u'toto') |
|
64 |
oe = self.add_entity('Note', type=u'x') |
|
65 |
self.schema['ecrit_par'].set_rproperty('Note', 'Personne', 'composite', 'subject') |
|
66 |
self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
|
67 |
{'t': oe.eid, 'u': p.eid}, ('t','u')) |
|
68 |
e = self.add_entity('Note', type=u'z') |
|
69 |
e.copy_relations(oe.eid) |
|
70 |
self.failIf(e.ecrit_par) |
|
71 |
self.failUnless(oe.ecrit_par) |
|
1640 | 72 |
|
0 | 73 |
def test_copy_with_composite(self): |
74 |
user = self.user() |
|
75 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
|
76 |
e = self.entity('Any X WHERE X eid %(x)s', {'x':user.eid}, 'x') |
|
77 |
self.assertEquals(e.use_email[0].address, "toto@logilab.org") |
|
78 |
self.assertEquals(e.use_email[0].eid, adeleid) |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
79 |
usereid = self.execute('INSERT CWUser X: X login "toto", X upassword "toto", X in_group G ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
80 |
'WHERE G name "users"')[0][0] |
0 | 81 |
e = self.entity('Any X WHERE X eid %(x)s', {'x':usereid}, 'x') |
82 |
e.copy_relations(user.eid) |
|
83 |
self.failIf(e.use_email) |
|
84 |
self.failIf(e.primary_email) |
|
1640 | 85 |
|
0 | 86 |
def test_copy_with_non_initial_state(self): |
87 |
user = self.user() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
88 |
user = self.execute('INSERT CWUser X: X login "toto", X upassword %(pwd)s, X in_group G WHERE G name "users"', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
89 |
{'pwd': 'toto'}).get_entity(0, 0) |
0 | 90 |
self.commit() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
91 |
user.fire_transition('deactivate') |
0 | 92 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
93 |
eid2 = self.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0] |
0 | 94 |
e = self.entity('Any X WHERE X eid %(x)s', {'x': eid2}, 'x') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
95 |
e.copy_relations(user.eid) |
0 | 96 |
self.commit() |
97 |
e.clear_related_cache('in_state', 'subject') |
|
98 |
self.assertEquals(e.state, 'activated') |
|
99 |
||
100 |
def test_related_cache_both(self): |
|
101 |
user = self.entity('Any X WHERE X eid %(x)s', {'x':self.user().eid}, 'x') |
|
102 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
|
103 |
self.commit() |
|
104 |
self.assertEquals(user._related_cache.keys(), []) |
|
105 |
email = user.primary_email[0] |
|
106 |
self.assertEquals(sorted(user._related_cache), ['primary_email_subject']) |
|
107 |
self.assertEquals(email._related_cache.keys(), ['primary_email_object']) |
|
108 |
groups = user.in_group |
|
109 |
self.assertEquals(sorted(user._related_cache), ['in_group_subject', 'primary_email_subject']) |
|
110 |
for group in groups: |
|
111 |
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
|
112 |
|
0 | 113 |
def test_related_limit(self): |
114 |
p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
115 |
for tag in u'abcd': |
|
116 |
self.add_entity('Tag', name=tag) |
|
117 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
|
118 |
self.assertEquals(len(p.related('tags', 'object', limit=2)), 2) |
|
119 |
self.assertEquals(len(p.related('tags', 'object')), 4) |
|
120 |
||
1640 | 121 |
|
0 | 122 |
def test_fetch_rql(self): |
123 |
user = self.user() |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
124 |
Personne = self.vreg['etypes'].etype_class('Personne') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
125 |
Societe = self.vreg['etypes'].etype_class('Societe') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
126 |
Note = self.vreg['etypes'].etype_class('Note') |
0 | 127 |
peschema = Personne.e_schema |
128 |
seschema = Societe.e_schema |
|
129 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '1*') |
|
130 |
peschema.subject_relation('connait').set_rproperty(peschema, peschema, 'cardinality', '11') |
|
131 |
peschema.subject_relation('evaluee').set_rproperty(peschema, Note.e_schema, 'cardinality', '1*') |
|
132 |
seschema.subject_relation('evaluee').set_rproperty(seschema, Note.e_schema, 'cardinality', '1*') |
|
133 |
# testing basic fetch_attrs attribute |
|
134 |
self.assertEquals(Personne.fetch_rql(user), |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
135 |
'Any X,AA,AB,AC ORDERBY AA ASC ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
136 |
'WHERE X is Personne, X nom AA, X prenom AB, X modification_date AC') |
0 | 137 |
pfetch_attrs = Personne.fetch_attrs |
138 |
sfetch_attrs = Societe.fetch_attrs |
|
139 |
try: |
|
140 |
# testing unknown attributes |
|
141 |
Personne.fetch_attrs = ('bloug', 'beep') |
|
1640 | 142 |
self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne') |
0 | 143 |
# testing one non final relation |
144 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
145 |
self.assertEquals(Personne.fetch_rql(user), |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
146 |
'Any X,AA,AB,AC,AD ORDERBY AA ASC ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
147 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
0 | 148 |
# testing two non final relations |
149 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee') |
|
150 |
self.assertEquals(Personne.fetch_rql(user), |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
151 |
'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
152 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
153 |
'X evaluee AE?, AE modification_date AF') |
0 | 154 |
# testing one non final relation with recursion |
155 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
156 |
Societe.fetch_attrs = ('nom', 'evaluee') |
|
157 |
self.assertEquals(Personne.fetch_rql(user), |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
158 |
'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
159 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
160 |
'AC evaluee AE?, AE modification_date AF' |
0 | 161 |
) |
162 |
# testing symetric relation |
|
163 |
Personne.fetch_attrs = ('nom', 'connait') |
|
2930
d7c23b2c7538
some test fixes, more in the 3.5 branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
164 |
self.assertEquals(Personne.fetch_rql(user), 'Any X,AA,AB ORDERBY AA ASC ' |
d7c23b2c7538
some test fixes, more in the 3.5 branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
165 |
'WHERE X is Personne, X nom AA, X connait AB?') |
0 | 166 |
# testing optional relation |
167 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '?*') |
|
168 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
169 |
Societe.fetch_attrs = ('nom',) |
|
170 |
self.assertEquals(Personne.fetch_rql(user), |
|
171 |
'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') |
|
172 |
# testing relation with cardinality > 1 |
|
173 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '**') |
|
174 |
self.assertEquals(Personne.fetch_rql(user), |
|
175 |
'Any X,AA,AB ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB') |
|
176 |
# XXX test unauthorized attribute |
|
177 |
finally: |
|
178 |
Personne.fetch_attrs = pfetch_attrs |
|
179 |
Societe.fetch_attrs = sfetch_attrs |
|
180 |
||
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
|
181 |
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
|
182 |
from cubicweb.entities import fetch_config |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
183 |
Personne = self.vreg['etypes'].etype_class('Personne') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
184 |
Note = self.vreg['etypes'].etype_class('Note') |
744 | 185 |
Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type')) |
186 |
Note.fetch_attrs, Note.fetch_order = fetch_config(('type',)) |
|
187 |
aff = self.add_entity('Personne', nom=u'pouet') |
|
188 |
self.assertEquals(aff.related_rql('evaluee'), |
|
189 |
'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, ' |
|
190 |
'X type AA, X modification_date AB') |
|
191 |
Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) |
|
192 |
# XXX |
|
193 |
self.assertEquals(aff.related_rql('evaluee'), |
|
194 |
'Any X,AA ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E evaluee X, X modification_date AA') |
|
1640 | 195 |
|
0 | 196 |
def test_entity_unrelated(self): |
197 |
p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
198 |
e = self.add_entity('Tag', name=u'x') |
|
199 |
related = [r.eid for r in e.tags] |
|
200 |
self.failUnlessEqual(related, []) |
|
1341 | 201 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
0 | 202 |
self.failUnless(p.eid in unrelated) |
203 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
|
204 |
e = self.entity('Any X WHERE X is Tag') |
|
1341 | 205 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
0 | 206 |
self.failIf(p.eid in unrelated) |
207 |
||
208 |
def test_entity_unrelated_limit(self): |
|
209 |
e = self.add_entity('Tag', name=u'x') |
|
210 |
self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
211 |
self.add_entity('Personne', nom=u'di mascio', prenom=u'gwen') |
|
1341 | 212 |
self.assertEquals(len(e.unrelated('tags', 'Personne', 'subject', limit=1)), |
0 | 213 |
1) |
1640 | 214 |
|
0 | 215 |
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
|
216 |
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
|
217 |
unrelated = [r[0] for r in e.unrelated('in_group', 'CWGroup', 'subject')] |
0 | 218 |
# should be default groups but owners, i.e. managers, users, guests |
219 |
self.assertEquals(len(unrelated), 3) |
|
220 |
||
221 |
def test_printable_value_string(self): |
|
222 |
e = self.add_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
|
223 |
content_format=u'text/rest') |
|
224 |
self.assertEquals(e.printable_value('content'), |
|
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
225 |
'<p>du <a class="reference" href="http://testing.fr/cubicweb/cwgroup/guests">*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
|
226 |
e['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
0 | 227 |
e['content_format'] = 'text/html' |
228 |
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
|
229 |
'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
0 | 230 |
e['content'] = 'du *texte*' |
231 |
e['content_format'] = 'text/plain' |
|
232 |
self.assertEquals(e.printable_value('content'), |
|
233 |
'<p>\ndu *texte*\n</p>') |
|
234 |
e['title'] = 'zou' |
|
235 |
#e = self.etype_instance('Task') |
|
236 |
e['content'] = '''\ |
|
237 |
a title |
|
238 |
======= |
|
239 |
du :eid:`1:*ReST*`''' |
|
240 |
e['content_format'] = 'text/rest' |
|
241 |
self.assertEquals(e.printable_value('content', format='text/plain'), |
|
242 |
e['content']) |
|
243 |
||
244 |
e['content'] = u'<b>yo (zou éà ;)</b>' |
|
245 |
e['content_format'] = 'text/html' |
|
246 |
self.assertEquals(e.printable_value('content', format='text/plain').strip(), |
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
'<h1>zou</h1>') |
1640 | 253 |
|
0 | 254 |
|
255 |
def test_printable_value_bytes(self): |
|
256 |
e = self.add_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python', |
|
257 |
data_encoding=u'ascii', name=u'toto.py') |
|
258 |
from cubicweb.common import mttransforms |
|
259 |
if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
|
260 |
self.assertEquals(e.printable_value('data'), |
|
261 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
|
262 |
</pre></div> |
|
263 |
''') |
|
264 |
else: |
|
265 |
self.assertEquals(e.printable_value('data'), |
|
266 |
'''<pre class="python"> |
|
267 |
<span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
|
268 |
</pre> |
|
269 |
''') |
|
1640 | 270 |
|
0 | 271 |
e = self.add_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
272 |
data_encoding=u'utf-8', name=u'toto.txt') |
|
273 |
self.assertEquals(e.printable_value('data'), |
|
274 |
u'<p><em>héhéhé</em></p>\n') |
|
275 |
||
276 |
def test_printable_value_bad_html(self): |
|
277 |
"""make sure we don't crash if we try to render invalid XHTML strings""" |
|
278 |
e = self.add_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
|
279 |
content_format=u'text/html') |
|
280 |
tidy = lambda x: x.replace('\n', '') |
|
281 |
self.assertEquals(tidy(e.printable_value('content')), |
|
282 |
'<div>R&D<br/></div>') |
|
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'R&D' |
|
287 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D') |
|
288 |
e['content'] = u'R&D;' |
|
289 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D;') |
|
290 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
291 |
self.assertEquals(tidy(e.printable_value('content')), |
|
292 |
u'yo !! R&D <div> pas fermé</div>') |
|
293 |
e['content'] = u'été <div> été' |
|
294 |
self.assertEquals(tidy(e.printable_value('content')), |
|
295 |
u'été <div> été</div>') |
|
296 |
e['content'] = u'C'est un exemple sérieux' |
|
297 |
self.assertEquals(tidy(e.printable_value('content')), |
|
298 |
u"C'est un exemple sérieux") |
|
299 |
# make sure valid xhtml is left untouched |
|
300 |
e['content'] = u'<div>R&D<br/></div>' |
|
301 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
302 |
e['content'] = u'<div>été</div>' |
|
303 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
304 |
e['content'] = u'été' |
|
305 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
2208
1c73148ed912
normalize line breaks (actually fix https://www.logilab.net/cwo/ticket/343754)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2125
diff
changeset
|
306 |
e['content'] = u'hop\r\nhop\nhip\rmomo' |
1c73148ed912
normalize line breaks (actually fix https://www.logilab.net/cwo/ticket/343754)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2125
diff
changeset
|
307 |
self.assertEquals(e.printable_value('content'), u'hop\nhop\nhip\nmomo') |
1640 | 308 |
|
309 |
||
0 | 310 |
def test_fulltextindex(self): |
311 |
e = self.etype_instance('File') |
|
312 |
e['name'] = 'an html file' |
|
313 |
e['description'] = 'du <em>html</em>' |
|
314 |
e['description_format'] = 'text/html' |
|
315 |
e['data'] = Binary('some <em>data</em>') |
|
316 |
e['data_format'] = 'text/html' |
|
317 |
e['data_encoding'] = 'ascii' |
|
1640 | 318 |
self.assertEquals(set(e.get_words()), |
0 | 319 |
set(['an', 'html', 'file', 'du', 'html', 'some', 'data'])) |
320 |
||
1640 | 321 |
|
0 | 322 |
def test_nonregr_relation_cache(self): |
323 |
p1 = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
324 |
p2 = self.add_entity('Personne', nom=u'toto') |
|
325 |
self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"') |
|
326 |
self.assertEquals(p1.evaluee[0].nom, "toto") |
|
327 |
self.failUnless(not p1.reverse_evaluee) |
|
1640 | 328 |
|
0 | 329 |
def test_complete_relation(self): |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
330 |
session = self.session() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
331 |
eid = session.unsafe_execute( |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
332 |
'INSERT TrInfo X: X comment "zou", X wf_info_for U, X from_state S1, X to_state S2 ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
333 |
'WHERE U login "admin", S1 name "activated", S2 name "deactivated"')[0][0] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
334 |
trinfo = self.entity('Any X WHERE X eid %(x)s', {'x': eid}, 'x') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
335 |
trinfo.complete() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
336 |
self.failUnless(isinstance(trinfo['creation_date'], datetime)) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
337 |
self.failUnless(trinfo.relation_cached('from_state', 'subject')) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
338 |
self.failUnless(trinfo.relation_cached('to_state', 'subject')) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
339 |
self.failUnless(trinfo.relation_cached('wf_info_for', 'subject')) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
340 |
self.assertEquals(trinfo.by_transition, []) |
0 | 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 |
||
1905
9c96dd7cc624
[tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1640
diff
changeset
|
377 |
def test_metainformation_and_external_absolute_url(self): |
0 | 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/' |
|
1905
9c96dd7cc624
[tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1640
diff
changeset
|
384 |
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
|
385 |
self.assertEquals(note.absolute_url(), 'http://cubicweb2.com/note/1234') |
1640 | 386 |
|
2125
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
387 |
def test_absolute_url_empty_field(self): |
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
388 |
card = self.add_entity('Card', wikiid=u'', title=u'test') |
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
389 |
self.assertEquals(card.absolute_url(), |
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
390 |
'http://testing.fr/cubicweb/card/eid/%s' % card.eid) |
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
391 |
|
0 | 392 |
if __name__ == '__main__': |
393 |
from logilab.common.testlib import unittest_main |
|
394 |
unittest_main() |
|
395 |