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