author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 13 Oct 2009 15:59:05 +0200 | |
changeset 3655 | af86ab65a282 |
parent 3589 | a5432f99f2d9 |
child 3674 | 387d51af966d |
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 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
12 |
from cubicweb import Binary, Unauthorized |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
13 |
from cubicweb.devtools.testlib import CubicWebTC |
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 |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
15 |
from cubicweb.entities import fetch_config |
0 | 16 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
17 |
class EntityTC(CubicWebTC): |
1640 | 18 |
|
0 | 19 |
def test_boolean_value(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
20 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
0 | 21 |
self.failUnless(e) |
22 |
||
23 |
def test_yams_inheritance(self): |
|
748 | 24 |
from entities import Note |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
25 |
e = self.vreg['etypes'].etype_class('SubNote')(self.request()) |
748 | 26 |
self.assertIsInstance(e, Note) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
27 |
e2 = self.vreg['etypes'].etype_class('SubNote')(self.request()) |
0 | 28 |
self.assertIs(e.__class__, e2.__class__) |
29 |
||
30 |
def test_has_eid(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
31 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
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) |
|
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
52 |
self.assertEquals(len(e.reverse_tags), 1) |
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
53 |
# 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
|
54 |
self.assertEquals(len(e.created_by), 0) |
1640 | 55 |
|
0 | 56 |
def test_copy_with_nonmeta_composite_inlined(self): |
57 |
p = self.add_entity('Personne', nom=u'toto') |
|
58 |
oe = self.add_entity('Note', type=u'x') |
|
59 |
self.schema['ecrit_par'].set_rproperty('Note', 'Personne', 'composite', 'subject') |
|
60 |
self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
|
61 |
{'t': oe.eid, 'u': p.eid}, ('t','u')) |
|
62 |
e = self.add_entity('Note', type=u'z') |
|
63 |
e.copy_relations(oe.eid) |
|
64 |
self.failIf(e.ecrit_par) |
|
65 |
self.failUnless(oe.ecrit_par) |
|
1640 | 66 |
|
0 | 67 |
def test_copy_with_composite(self): |
68 |
user = self.user() |
|
69 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
|
70 |
e = self.entity('Any X WHERE X eid %(x)s', {'x':user.eid}, 'x') |
|
71 |
self.assertEquals(e.use_email[0].address, "toto@logilab.org") |
|
72 |
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
|
73 |
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
|
74 |
'WHERE G name "users"')[0][0] |
0 | 75 |
e = self.entity('Any X WHERE X eid %(x)s', {'x':usereid}, 'x') |
76 |
e.copy_relations(user.eid) |
|
77 |
self.failIf(e.use_email) |
|
78 |
self.failIf(e.primary_email) |
|
1640 | 79 |
|
0 | 80 |
def test_copy_with_non_initial_state(self): |
81 |
user = self.user() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
82 |
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
|
83 |
{'pwd': 'toto'}).get_entity(0, 0) |
0 | 84 |
self.commit() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
85 |
user.fire_transition('deactivate') |
0 | 86 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
87 |
eid2 = self.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0] |
0 | 88 |
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
|
89 |
e.copy_relations(user.eid) |
0 | 90 |
self.commit() |
91 |
e.clear_related_cache('in_state', 'subject') |
|
92 |
self.assertEquals(e.state, 'activated') |
|
93 |
||
94 |
def test_related_cache_both(self): |
|
95 |
user = self.entity('Any X WHERE X eid %(x)s', {'x':self.user().eid}, 'x') |
|
96 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
|
97 |
self.commit() |
|
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
98 |
self.assertEquals(user._related_cache, {}) |
0 | 99 |
email = user.primary_email[0] |
100 |
self.assertEquals(sorted(user._related_cache), ['primary_email_subject']) |
|
101 |
self.assertEquals(email._related_cache.keys(), ['primary_email_object']) |
|
102 |
groups = user.in_group |
|
103 |
self.assertEquals(sorted(user._related_cache), ['in_group_subject', 'primary_email_subject']) |
|
104 |
for group in groups: |
|
105 |
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
|
106 |
|
0 | 107 |
def test_related_limit(self): |
108 |
p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
109 |
for tag in u'abcd': |
|
110 |
self.add_entity('Tag', name=tag) |
|
111 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
|
112 |
self.assertEquals(len(p.related('tags', 'object', limit=2)), 2) |
|
113 |
self.assertEquals(len(p.related('tags', 'object')), 4) |
|
114 |
||
1640 | 115 |
|
0 | 116 |
def test_fetch_rql(self): |
117 |
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
|
118 |
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
|
119 |
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
|
120 |
Note = self.vreg['etypes'].etype_class('Note') |
0 | 121 |
peschema = Personne.e_schema |
122 |
seschema = Societe.e_schema |
|
123 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '1*') |
|
124 |
peschema.subject_relation('connait').set_rproperty(peschema, peschema, 'cardinality', '11') |
|
125 |
peschema.subject_relation('evaluee').set_rproperty(peschema, Note.e_schema, 'cardinality', '1*') |
|
126 |
seschema.subject_relation('evaluee').set_rproperty(seschema, Note.e_schema, 'cardinality', '1*') |
|
127 |
# testing basic fetch_attrs attribute |
|
128 |
self.assertEquals(Personne.fetch_rql(user), |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
129 |
'Any X,AA,AB,AC ORDERBY AA ASC ' |
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
130 |
'WHERE X is Personne, X nom AA, X prenom AB, X modification_date AC') |
0 | 131 |
pfetch_attrs = Personne.fetch_attrs |
132 |
sfetch_attrs = Societe.fetch_attrs |
|
133 |
try: |
|
134 |
# testing unknown attributes |
|
135 |
Personne.fetch_attrs = ('bloug', 'beep') |
|
1640 | 136 |
self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne') |
0 | 137 |
# testing one non final relation |
138 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
139 |
self.assertEquals(Personne.fetch_rql(user), |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
140 |
'Any X,AA,AB,AC,AD ORDERBY AA ASC ' |
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
141 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
0 | 142 |
# testing two non final relations |
143 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee') |
|
144 |
self.assertEquals(Personne.fetch_rql(user), |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
145 |
'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC ' |
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
146 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
147 |
'X evaluee AE?, AE modification_date AF') |
0 | 148 |
# testing one non final relation with recursion |
149 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
150 |
Societe.fetch_attrs = ('nom', 'evaluee') |
|
151 |
self.assertEquals(Personne.fetch_rql(user), |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
152 |
'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC ' |
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
153 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
154 |
'AC evaluee AE?, AE modification_date AF' |
0 | 155 |
) |
156 |
# testing symetric relation |
|
157 |
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
|
158 |
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
|
159 |
'WHERE X is Personne, X nom AA, X connait AB?') |
0 | 160 |
# testing optional relation |
161 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '?*') |
|
162 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
163 |
Societe.fetch_attrs = ('nom',) |
|
164 |
self.assertEquals(Personne.fetch_rql(user), |
|
165 |
'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') |
|
166 |
# testing relation with cardinality > 1 |
|
167 |
peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '**') |
|
168 |
self.assertEquals(Personne.fetch_rql(user), |
|
169 |
'Any X,AA,AB ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB') |
|
170 |
# XXX test unauthorized attribute |
|
171 |
finally: |
|
172 |
Personne.fetch_attrs = pfetch_attrs |
|
173 |
Societe.fetch_attrs = sfetch_attrs |
|
174 |
||
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
|
175 |
def test_related_rql(self): |
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
|
176 |
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
|
177 |
Note = self.vreg['etypes'].etype_class('Note') |
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
178 |
self.failUnless(issubclass(self.vreg['etypes'].etype_class('SubNote'), Note)) |
744 | 179 |
Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type')) |
180 |
Note.fetch_attrs, Note.fetch_order = fetch_config(('type',)) |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
181 |
p = self.add_entity('Personne', nom=u'pouet') |
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
182 |
self.assertEquals(p.related_rql('evaluee'), |
744 | 183 |
'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, ' |
184 |
'X type AA, X modification_date AB') |
|
185 |
Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) |
|
186 |
# XXX |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
187 |
self.assertEquals(p.related_rql('evaluee'), |
744 | 188 |
'Any X,AA ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E evaluee X, X modification_date AA') |
1640 | 189 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
190 |
def test_unrelated_rql_security_1(self): |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
191 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
192 |
rql = user.unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
193 |
self.assertEquals(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
194 |
'WHERE NOT S use_email O, S eid %(x)s, O is EmailAddress, O address AA, O alias AB, O modification_date AC') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
195 |
self.create_user('toto') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
196 |
self.login('toto') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
197 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
198 |
rql = user.unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
199 |
self.assertEquals(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
200 |
'WHERE NOT S use_email O, S eid %(x)s, O is EmailAddress, O address AA, O alias AB, O modification_date AC') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
201 |
user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
202 |
self.assertRaises(Unauthorized, user.unrelated_rql, 'use_email', 'EmailAddress', 'subject') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
203 |
self.login('anon') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
204 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
205 |
self.assertRaises(Unauthorized, user.unrelated_rql, 'use_email', 'EmailAddress', 'subject') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
206 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
207 |
def test_unrelated_rql_security_2(self): |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
208 |
email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
209 |
rql = email.unrelated_rql('use_email', 'CWUser', 'object')[0] |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
210 |
self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ASC ' |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
211 |
'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
212 |
#rql = email.unrelated_rql('use_email', 'Person', 'object')[0] |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
213 |
#self.assertEquals(rql, '') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
214 |
self.login('anon') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
215 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}, 'x').get_entity(0, 0) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
216 |
rql = email.unrelated_rql('use_email', 'CWUser', 'object')[0] |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
217 |
self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
218 |
'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
219 |
'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
220 |
#rql = email.unrelated_rql('use_email', 'Person', 'object')[0] |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
221 |
#self.assertEquals(rql, '') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
222 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
223 |
def test_unrelated_base(self): |
0 | 224 |
p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
225 |
e = self.add_entity('Tag', name=u'x') |
|
226 |
related = [r.eid for r in e.tags] |
|
227 |
self.failUnlessEqual(related, []) |
|
1341 | 228 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
0 | 229 |
self.failUnless(p.eid in unrelated) |
230 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
|
231 |
e = self.entity('Any X WHERE X is Tag') |
|
1341 | 232 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
0 | 233 |
self.failIf(p.eid in unrelated) |
234 |
||
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
235 |
def test_unrelated_limit(self): |
0 | 236 |
e = self.add_entity('Tag', name=u'x') |
237 |
self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
238 |
self.add_entity('Personne', nom=u'thenault', prenom=u'sylvain') |
1341 | 239 |
self.assertEquals(len(e.unrelated('tags', 'Personne', 'subject', limit=1)), |
0 | 240 |
1) |
1640 | 241 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
242 |
def test_unrelated_security(self): |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
243 |
email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
244 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
245 |
self.assertEquals([x.login for x in rset.entities()], [u'admin', u'anon']) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
246 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
247 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
248 |
self.assertEquals([x.address for x in rset.entities()], [u'hop']) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
249 |
self.create_user('toto') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
250 |
self.login('toto') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
251 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}, 'x').get_entity(0, 0) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
252 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
253 |
self.assertEquals([x.login for x in rset.entities()], ['toto']) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
254 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
255 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
256 |
self.assertEquals([x.address for x in rset.entities()], ['hop']) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
257 |
user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
258 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
259 |
self.assertEquals([x.address for x in rset.entities()], []) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
260 |
self.login('anon') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
261 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}, 'x').get_entity(0, 0) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
262 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
263 |
self.assertEquals([x.login for x in rset.entities()], []) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
264 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
265 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
266 |
self.assertEquals([x.address for x in rset.entities()], []) |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
267 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
268 |
def test_unrelated_new_entity(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
269 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
270 |
unrelated = [r[0] for r in e.unrelated('in_group', 'CWGroup', 'subject')] |
0 | 271 |
# should be default groups but owners, i.e. managers, users, guests |
272 |
self.assertEquals(len(unrelated), 3) |
|
273 |
||
274 |
def test_printable_value_string(self): |
|
275 |
e = self.add_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
|
276 |
content_format=u'text/rest') |
|
277 |
self.assertEquals(e.printable_value('content'), |
|
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
278 |
'<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
|
279 |
e['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
0 | 280 |
e['content_format'] = 'text/html' |
281 |
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
|
282 |
'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
0 | 283 |
e['content'] = 'du *texte*' |
284 |
e['content_format'] = 'text/plain' |
|
285 |
self.assertEquals(e.printable_value('content'), |
|
286 |
'<p>\ndu *texte*\n</p>') |
|
287 |
e['title'] = 'zou' |
|
288 |
e['content'] = '''\ |
|
289 |
a title |
|
290 |
======= |
|
291 |
du :eid:`1:*ReST*`''' |
|
292 |
e['content_format'] = 'text/rest' |
|
293 |
self.assertEquals(e.printable_value('content', format='text/plain'), |
|
294 |
e['content']) |
|
295 |
||
296 |
e['content'] = u'<b>yo (zou éà ;)</b>' |
|
297 |
e['content_format'] = 'text/html' |
|
298 |
self.assertEquals(e.printable_value('content', format='text/plain').strip(), |
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
'<h1>zou</h1>') |
1640 | 305 |
|
0 | 306 |
|
307 |
def test_printable_value_bytes(self): |
|
308 |
e = self.add_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python', |
|
3587 | 309 |
data_encoding=u'ascii', data_name=u'toto.py') |
0 | 310 |
from cubicweb.common import mttransforms |
311 |
if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
|
312 |
self.assertEquals(e.printable_value('data'), |
|
3587 | 313 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span> |
0 | 314 |
</pre></div> |
315 |
''') |
|
316 |
else: |
|
317 |
self.assertEquals(e.printable_value('data'), |
|
318 |
'''<pre class="python"> |
|
319 |
<span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
|
320 |
</pre> |
|
321 |
''') |
|
1640 | 322 |
|
0 | 323 |
e = self.add_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
3587 | 324 |
data_encoding=u'utf-8', data_name=u'toto.txt') |
0 | 325 |
self.assertEquals(e.printable_value('data'), |
326 |
u'<p><em>héhéhé</em></p>\n') |
|
327 |
||
328 |
def test_printable_value_bad_html(self): |
|
329 |
"""make sure we don't crash if we try to render invalid XHTML strings""" |
|
330 |
e = self.add_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
|
331 |
content_format=u'text/html') |
|
332 |
tidy = lambda x: x.replace('\n', '') |
|
333 |
self.assertEquals(tidy(e.printable_value('content')), |
|
334 |
'<div>R&D<br/></div>') |
|
335 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
336 |
self.assertEquals(tidy(e.printable_value('content')), |
|
337 |
u'yo !! R&D <div> pas fermé</div>') |
|
338 |
e['content'] = u'R&D' |
|
339 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D') |
|
340 |
e['content'] = u'R&D;' |
|
341 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D;') |
|
342 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
343 |
self.assertEquals(tidy(e.printable_value('content')), |
|
344 |
u'yo !! R&D <div> pas fermé</div>') |
|
345 |
e['content'] = u'été <div> été' |
|
346 |
self.assertEquals(tidy(e.printable_value('content')), |
|
347 |
u'été <div> été</div>') |
|
348 |
e['content'] = u'C'est un exemple sérieux' |
|
349 |
self.assertEquals(tidy(e.printable_value('content')), |
|
350 |
u"C'est un exemple sérieux") |
|
3587 | 351 |
# make sure valid xhtml is left untouched |
352 |
e['content'] = u'<div>R&D<br/></div>' |
|
353 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
354 |
e['content'] = u'<div>été</div>' |
|
355 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
356 |
e['content'] = u'été' |
|
357 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
358 |
e['content'] = u'hop\r\nhop\nhip\rmomo' |
|
359 |
self.assertEquals(e.printable_value('content'), u'hop\nhop\nhip\nmomo') |
|
360 |
||
361 |
def test_printable_value_bad_html_ms(self): |
|
362 |
self.skip('fix soup2xhtml to handle this test') |
|
363 |
e = self.add_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
|
364 |
content_format=u'text/html') |
|
365 |
tidy = lambda x: x.replace('\n', '') |
|
3352
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
366 |
e['content'] = u'<div x:foo="bar">ms orifice produces weird html</div>' |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
367 |
self.assertEquals(tidy(e.printable_value('content')), |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
368 |
u'<div>ms orifice produces weird html</div>') |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
369 |
import tidy as tidymod # apt-get install python-tidy |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
370 |
tidy = lambda x: str(tidymod.parseString(x.encode('utf-8'), |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
371 |
**{'drop_proprietary_attributes': True, |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
372 |
'output_xhtml': True, |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
373 |
'show_body_only' : True, |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
374 |
'quote-nbsp' : False, |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
375 |
'char_encoding' : 'utf8'})).decode('utf-8').strip() |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
376 |
self.assertEquals(tidy(e.printable_value('content')), |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
377 |
u'<div>ms orifice produces weird html</div>') |
1640 | 378 |
|
379 |
||
0 | 380 |
def test_fulltextindex(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
381 |
e = self.vreg['etypes'].etype_class('File')(self.request()) |
0 | 382 |
e['description'] = 'du <em>html</em>' |
383 |
e['description_format'] = 'text/html' |
|
384 |
e['data'] = Binary('some <em>data</em>') |
|
3587 | 385 |
e['data_name'] = 'an html file' |
0 | 386 |
e['data_format'] = 'text/html' |
387 |
e['data_encoding'] = 'ascii' |
|
3587 | 388 |
e.req.transaction_data = {} # XXX req should be a session |
1640 | 389 |
self.assertEquals(set(e.get_words()), |
0 | 390 |
set(['an', 'html', 'file', 'du', 'html', 'some', 'data'])) |
391 |
||
1640 | 392 |
|
0 | 393 |
def test_nonregr_relation_cache(self): |
394 |
p1 = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
395 |
p2 = self.add_entity('Personne', nom=u'toto') |
|
396 |
self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"') |
|
397 |
self.assertEquals(p1.evaluee[0].nom, "toto") |
|
398 |
self.failUnless(not p1.reverse_evaluee) |
|
1640 | 399 |
|
0 | 400 |
def test_complete_relation(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
401 |
session = self.session |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
402 |
eid = session.unsafe_execute( |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
403 |
'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
|
404 |
'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
|
405 |
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
|
406 |
trinfo.complete() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
407 |
self.failUnless(isinstance(trinfo['creation_date'], datetime)) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
408 |
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
|
409 |
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
|
410 |
self.failUnless(trinfo.relation_cached('wf_info_for', 'subject')) |
3587 | 411 |
self.assertEquals(trinfo.by_transition, ()) |
0 | 412 |
|
413 |
def test_request_cache(self): |
|
414 |
req = self.request() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
415 |
user = self.entity('CWUser X WHERE X login "admin"', req=req) |
0 | 416 |
state = user.in_state[0] |
417 |
samestate = self.entity('State X WHERE X name "activated"', req=req) |
|
418 |
self.failUnless(state is samestate) |
|
419 |
||
420 |
def test_rest_path(self): |
|
421 |
note = self.add_entity('Note', type=u'z') |
|
422 |
self.assertEquals(note.rest_path(), 'note/%s' % note.eid) |
|
423 |
# unique attr |
|
424 |
tag = self.add_entity('Tag', name=u'x') |
|
425 |
self.assertEquals(tag.rest_path(), 'tag/x') |
|
426 |
# test explicit rest_attr |
|
427 |
person = self.add_entity('Personne', prenom=u'john', nom=u'doe') |
|
428 |
self.assertEquals(person.rest_path(), 'personne/doe') |
|
429 |
# ambiguity test |
|
430 |
person2 = self.add_entity('Personne', prenom=u'remi', nom=u'doe') |
|
431 |
self.assertEquals(person.rest_path(), 'personne/eid/%s' % person.eid) |
|
432 |
self.assertEquals(person2.rest_path(), 'personne/eid/%s' % person2.eid) |
|
433 |
# unique attr with None value (wikiid in this case) |
|
434 |
card1 = self.add_entity('Card', title=u'hop') |
|
435 |
self.assertEquals(card1.rest_path(), 'card/eid/%s' % card1.eid) |
|
436 |
card2 = self.add_entity('Card', title=u'pod', wikiid=u'zob/i') |
|
437 |
self.assertEquals(card2.rest_path(), 'card/zob%2Fi') |
|
438 |
||
439 |
def test_set_attributes(self): |
|
440 |
person = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
|
441 |
self.assertEquals(person.prenom, u'adrien') |
|
442 |
self.assertEquals(person.nom, u'di mascio') |
|
443 |
person.set_attributes(prenom=u'sylvain', nom=u'thénault') |
|
444 |
person = self.entity('Personne P') # XXX retreival needed ? |
|
445 |
self.assertEquals(person.prenom, u'sylvain') |
|
446 |
self.assertEquals(person.nom, u'thénault') |
|
447 |
||
1905
9c96dd7cc624
[tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1640
diff
changeset
|
448 |
def test_metainformation_and_external_absolute_url(self): |
0 | 449 |
note = self.add_entity('Note', type=u'z') |
450 |
metainf = note.metainformation() |
|
451 |
self.assertEquals(metainf, {'source': {'adapter': 'native', 'uri': 'system'}, 'type': u'Note', 'extid': None}) |
|
452 |
self.assertEquals(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid) |
|
453 |
metainf['source'] = metainf['source'].copy() |
|
454 |
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
|
455 |
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
|
456 |
self.assertEquals(note.absolute_url(), 'http://cubicweb2.com/note/1234') |
1640 | 457 |
|
2125
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
458 |
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
|
459 |
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
|
460 |
self.assertEquals(card.absolute_url(), |
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
461 |
'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
|
462 |
|
0 | 463 |
if __name__ == '__main__': |
464 |
from logilab.common.testlib import unittest_main |
|
465 |
unittest_main() |
|
466 |