author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Mon, 23 Aug 2010 09:07:20 +0200 | |
branch | stable |
changeset 6134 | 272cfcc10a28 |
parent 6099 | b22a4a3895df |
child 6142 | 8bc6eac1fac1 |
child 6168 | a52ea49434c8 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1905
diff
changeset
|
19 |
"""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
|
20 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1905
diff
changeset
|
21 |
""" |
0 | 22 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
821
diff
changeset
|
23 |
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
|
24 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
25 |
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
|
26 |
from cubicweb.devtools.testlib import CubicWebTC |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4015
diff
changeset
|
27 |
from cubicweb.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
|
28 |
from cubicweb.entities import fetch_config |
0 | 29 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
30 |
class EntityTC(CubicWebTC): |
1640 | 31 |
|
0 | 32 |
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
|
33 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
0 | 34 |
self.failUnless(e) |
35 |
||
36 |
def test_yams_inheritance(self): |
|
748 | 37 |
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
|
38 |
e = self.vreg['etypes'].etype_class('SubNote')(self.request()) |
748 | 39 |
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
|
40 |
e2 = self.vreg['etypes'].etype_class('SubNote')(self.request()) |
0 | 41 |
self.assertIs(e.__class__, e2.__class__) |
42 |
||
43 |
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
|
44 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
0 | 45 |
self.assertEquals(e.eid, None) |
46 |
self.assertEquals(e.has_eid(), False) |
|
47 |
e.eid = 'X' |
|
48 |
self.assertEquals(e.has_eid(), False) |
|
49 |
e.eid = 0 |
|
50 |
self.assertEquals(e.has_eid(), True) |
|
51 |
e.eid = 2 |
|
52 |
self.assertEquals(e.has_eid(), True) |
|
1640 | 53 |
|
0 | 54 |
def test_copy(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
55 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
56 |
req.create_entity('Tag', name=u'x') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
57 |
p = req.create_entity('Personne', nom=u'toto') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
58 |
oe = req.create_entity('Note', type=u'x') |
0 | 59 |
self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
60 |
{'t': oe.eid, 'u': p.eid}) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
61 |
self.execute('SET TAG tags X WHERE X eid %(x)s', {'x': oe.eid}) |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
62 |
e = req.create_entity('Note', type=u'z') |
0 | 63 |
e.copy_relations(oe.eid) |
64 |
self.assertEquals(len(e.ecrit_par), 1) |
|
65 |
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
|
66 |
self.assertEquals(len(e.reverse_tags), 1) |
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
67 |
# 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
|
68 |
self.assertEquals(len(e.created_by), 0) |
1640 | 69 |
|
0 | 70 |
def test_copy_with_nonmeta_composite_inlined(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
71 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
72 |
p = req.create_entity('Personne', nom=u'toto') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
73 |
oe = req.create_entity('Note', type=u'x') |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
74 |
self.schema['ecrit_par'].rdef('Note', 'Personne').composite = 'subject' |
0 | 75 |
self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
76 |
{'t': oe.eid, 'u': p.eid}) |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
77 |
e = req.create_entity('Note', type=u'z') |
0 | 78 |
e.copy_relations(oe.eid) |
79 |
self.failIf(e.ecrit_par) |
|
80 |
self.failUnless(oe.ecrit_par) |
|
1640 | 81 |
|
0 | 82 |
def test_copy_with_composite(self): |
83 |
user = self.user() |
|
84 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
85 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}).get_entity(0, 0) |
0 | 86 |
self.assertEquals(e.use_email[0].address, "toto@logilab.org") |
87 |
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
|
88 |
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
|
89 |
'WHERE G name "users"')[0][0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
90 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': usereid}).get_entity(0, 0) |
0 | 91 |
e.copy_relations(user.eid) |
92 |
self.failIf(e.use_email) |
|
93 |
self.failIf(e.primary_email) |
|
1640 | 94 |
|
0 | 95 |
def test_copy_with_non_initial_state(self): |
96 |
user = self.user() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
97 |
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
|
98 |
{'pwd': 'toto'}).get_entity(0, 0) |
0 | 99 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
100 |
user.cw_adapt_to('IWorkflowable').fire_transition('deactivate') |
0 | 101 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
102 |
eid2 = self.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
103 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': eid2}).get_entity(0, 0) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
104 |
e.copy_relations(user.eid) |
0 | 105 |
self.commit() |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
106 |
e.cw_clear_relation_cache('in_state', 'subject') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
107 |
self.assertEquals(e.cw_adapt_to('IWorkflowable').state, 'activated') |
0 | 108 |
|
109 |
def test_related_cache_both(self): |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
110 |
user = self.execute('Any X WHERE X eid %(x)s', {'x':self.user().eid}).get_entity(0, 0) |
0 | 111 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
112 |
self.commit() |
|
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
113 |
self.assertEquals(user._cw_related_cache, {}) |
0 | 114 |
email = user.primary_email[0] |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
115 |
self.assertEquals(sorted(user._cw_related_cache), ['primary_email_subject']) |
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
116 |
self.assertEquals(email._cw_related_cache.keys(), ['primary_email_object']) |
0 | 117 |
groups = user.in_group |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
118 |
self.assertEquals(sorted(user._cw_related_cache), ['in_group_subject', 'primary_email_subject']) |
0 | 119 |
for group in groups: |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
120 |
self.failIf('in_group_subject' in group._cw_related_cache, group._cw_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
|
121 |
|
0 | 122 |
def test_related_limit(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
123 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
124 |
p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
0 | 125 |
for tag in u'abcd': |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
126 |
req.create_entity('Tag', name=tag) |
0 | 127 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
128 |
self.assertEquals(len(p.related('tags', 'object', limit=2)), 2) |
|
129 |
self.assertEquals(len(p.related('tags', 'object')), 4) |
|
130 |
||
1640 | 131 |
|
0 | 132 |
def test_fetch_rql(self): |
133 |
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
|
134 |
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
|
135 |
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
|
136 |
Note = self.vreg['etypes'].etype_class('Note') |
0 | 137 |
peschema = Personne.e_schema |
138 |
seschema = Societe.e_schema |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
139 |
peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '1*' |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
140 |
peschema.subjrels['connait'].rdef(peschema, peschema).cardinality = '11' |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
141 |
peschema.subjrels['evaluee'].rdef(peschema, Note.e_schema).cardinality = '1*' |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
142 |
seschema.subjrels['evaluee'].rdef(seschema, Note.e_schema).cardinality = '1*' |
0 | 143 |
# testing basic fetch_attrs attribute |
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 ORDERBY AA ASC ' |
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 modification_date AC') |
0 | 147 |
pfetch_attrs = Personne.fetch_attrs |
148 |
sfetch_attrs = Societe.fetch_attrs |
|
149 |
try: |
|
150 |
# testing unknown attributes |
|
151 |
Personne.fetch_attrs = ('bloug', 'beep') |
|
1640 | 152 |
self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne') |
0 | 153 |
# testing one non final relation |
154 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
155 |
self.assertEquals(Personne.fetch_rql(user), |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
156 |
'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
|
157 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
0 | 158 |
# testing two non final relations |
159 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee') |
|
160 |
self.assertEquals(Personne.fetch_rql(user), |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
161 |
'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
|
162 |
'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
|
163 |
'X evaluee AE?, AE modification_date AF') |
0 | 164 |
# testing one non final relation with recursion |
165 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
166 |
Societe.fetch_attrs = ('nom', 'evaluee') |
|
167 |
self.assertEquals(Personne.fetch_rql(user), |
|
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
168 |
'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
|
169 |
'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
|
170 |
'AC evaluee AE?, AE modification_date AF' |
0 | 171 |
) |
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4460
diff
changeset
|
172 |
# testing symmetric relation |
0 | 173 |
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
|
174 |
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
|
175 |
'WHERE X is Personne, X nom AA, X connait AB?') |
0 | 176 |
# testing optional relation |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
177 |
peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '?*' |
0 | 178 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
179 |
Societe.fetch_attrs = ('nom',) |
|
180 |
self.assertEquals(Personne.fetch_rql(user), |
|
181 |
'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') |
|
182 |
# testing relation with cardinality > 1 |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
183 |
peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '**' |
0 | 184 |
self.assertEquals(Personne.fetch_rql(user), |
185 |
'Any X,AA,AB ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB') |
|
186 |
# XXX test unauthorized attribute |
|
187 |
finally: |
|
188 |
Personne.fetch_attrs = pfetch_attrs |
|
189 |
Societe.fetch_attrs = sfetch_attrs |
|
190 |
||
4630
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
191 |
def test_related_rql_base(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
|
192 |
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
|
193 |
Note = self.vreg['etypes'].etype_class('Note') |
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4681
diff
changeset
|
194 |
SubNote = self.vreg['etypes'].etype_class('SubNote') |
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
195 |
self.failUnless(issubclass(self.vreg['etypes'].etype_class('SubNote'), Note)) |
744 | 196 |
Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type')) |
197 |
Note.fetch_attrs, Note.fetch_order = fetch_config(('type',)) |
|
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4681
diff
changeset
|
198 |
SubNote.fetch_attrs, SubNote.fetch_order = fetch_config(('type',)) |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
199 |
p = self.request().create_entity('Personne', nom=u'pouet') |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
200 |
self.assertEquals(p.cw_related_rql('evaluee'), |
744 | 201 |
'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, ' |
202 |
'X type AA, X modification_date AB') |
|
203 |
Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) |
|
204 |
# XXX |
|
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
205 |
self.assertEquals(p.cw_related_rql('evaluee'), |
4672 | 206 |
'Any X,AA ORDERBY AA DESC ' |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4672
diff
changeset
|
207 |
'WHERE E eid %(x)s, E evaluee X, X modification_date AA') |
3672
554a588ffaea
[entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
208 |
|
554a588ffaea
[entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
209 |
tag = self.vreg['etypes'].etype_class('Tag')(self.request()) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
210 |
self.assertEquals(tag.cw_related_rql('tags', 'subject'), |
4672 | 211 |
'Any X,AA ORDERBY AA DESC ' |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4672
diff
changeset
|
212 |
'WHERE E eid %(x)s, E tags X, X modification_date AA') |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
213 |
self.assertEquals(tag.cw_related_rql('tags', 'subject', ('Personne',)), |
3672
554a588ffaea
[entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
214 |
'Any X,AA,AB ORDERBY AA ASC ' |
3771 | 215 |
'WHERE E eid %(x)s, E tags X, X is IN (Personne), X nom AA, ' |
3672
554a588ffaea
[entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
216 |
'X modification_date AB') |
1640 | 217 |
|
4630
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
218 |
def test_related_rql_ambigous_cant_use_fetch_order(self): |
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
219 |
tag = self.vreg['etypes'].etype_class('Tag')(self.request()) |
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
220 |
for ttype in self.schema['tags'].objects(): |
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
221 |
self.vreg['etypes'].etype_class(ttype).fetch_attrs = ('modification_date',) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
222 |
self.assertEquals(tag.cw_related_rql('tags', 'subject'), |
4630
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
223 |
'Any X,AA ORDERBY AA DESC ' |
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
224 |
'WHERE E eid %(x)s, E tags X, X modification_date AA') |
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
225 |
|
3241
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_1(self): |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
227 |
user = self.request().user |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
228 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
3241
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 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
|
230 |
'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
|
231 |
self.create_user('toto') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
232 |
self.login('toto') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
233 |
user = self.request().user |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
234 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
235 |
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
|
236 |
'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
|
237 |
user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
238 |
self.assertRaises(Unauthorized, user.cw_unrelated_rql, 'use_email', 'EmailAddress', 'subject') |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
239 |
self.login('anon') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
240 |
user = self.request().user |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
241 |
self.assertRaises(Unauthorized, user.cw_unrelated_rql, 'use_email', 'EmailAddress', 'subject') |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
242 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
243 |
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
|
244 |
email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
245 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
246 |
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
|
247 |
'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') |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
248 |
#rql = email.cw_unrelated_rql('use_email', 'Person', 'object')[0] |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
249 |
#self.assertEquals(rql, '') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
250 |
self.login('anon') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
251 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
252 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
253 |
self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
254 |
'WHERE NOT EXISTS(S use_email O), O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
255 |
'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)') |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
256 |
#rql = email.cw_unrelated_rql('use_email', 'Person', 'object')[0] |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
257 |
#self.assertEquals(rql, '') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
258 |
|
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
259 |
def test_unrelated_rql_security_nonexistant(self): |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
260 |
self.login('anon') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
261 |
email = self.vreg['etypes'].etype_class('EmailAddress')(self.request()) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
262 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
263 |
self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
264 |
'WHERE S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
265 |
'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)') |
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
266 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
267 |
def test_unrelated_base(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
268 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
269 |
p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
270 |
e = req.create_entity('Tag', name=u'x') |
0 | 271 |
related = [r.eid for r in e.tags] |
272 |
self.failUnlessEqual(related, []) |
|
1341 | 273 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
0 | 274 |
self.failUnless(p.eid in unrelated) |
275 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
276 |
e = self.execute('Any X WHERE X is Tag').get_entity(0, 0) |
1341 | 277 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
0 | 278 |
self.failIf(p.eid in unrelated) |
279 |
||
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
280 |
def test_unrelated_limit(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
281 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
282 |
e = req.create_entity('Tag', name=u'x') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
283 |
req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
284 |
req.create_entity('Personne', nom=u'thenault', prenom=u'sylvain') |
1341 | 285 |
self.assertEquals(len(e.unrelated('tags', 'Personne', 'subject', limit=1)), |
0 | 286 |
1) |
1640 | 287 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
self.create_user('toto') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
296 |
self.login('toto') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
297 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
self.login('anon') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
307 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
308 |
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
|
309 |
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
|
310 |
user = self.request().user |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
311 |
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
|
312 |
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
|
313 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
314 |
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
|
315 |
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
|
316 |
unrelated = [r[0] for r in e.unrelated('in_group', 'CWGroup', 'subject')] |
0 | 317 |
# should be default groups but owners, i.e. managers, users, guests |
318 |
self.assertEquals(len(unrelated), 3) |
|
319 |
||
320 |
def test_printable_value_string(self): |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
321 |
e = self.request().create_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
0 | 322 |
content_format=u'text/rest') |
323 |
self.assertEquals(e.printable_value('content'), |
|
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
324 |
'<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
|
325 |
e['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
0 | 326 |
e['content_format'] = 'text/html' |
327 |
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
|
328 |
'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
0 | 329 |
e['content'] = 'du *texte*' |
330 |
e['content_format'] = 'text/plain' |
|
331 |
self.assertEquals(e.printable_value('content'), |
|
332 |
'<p>\ndu *texte*\n</p>') |
|
333 |
e['title'] = 'zou' |
|
334 |
e['content'] = '''\ |
|
335 |
a title |
|
336 |
======= |
|
337 |
du :eid:`1:*ReST*`''' |
|
338 |
e['content_format'] = 'text/rest' |
|
339 |
self.assertEquals(e.printable_value('content', format='text/plain'), |
|
340 |
e['content']) |
|
341 |
||
342 |
e['content'] = u'<b>yo (zou éà ;)</b>' |
|
343 |
e['content_format'] = 'text/html' |
|
344 |
self.assertEquals(e.printable_value('content', format='text/plain').strip(), |
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
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
|
350 |
'<h1>zou</h1>') |
1640 | 351 |
|
0 | 352 |
|
353 |
def test_printable_value_bytes(self): |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
354 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
355 |
e = req.create_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python', |
3587 | 356 |
data_encoding=u'ascii', data_name=u'toto.py') |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4015
diff
changeset
|
357 |
from cubicweb import mttransforms |
0 | 358 |
if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
5631
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
359 |
import pygments |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
360 |
if tuple(int(i) for i in pygments.__version__.split('.')[:2]) >= (1, 3): |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
361 |
self.assertEquals(e.printable_value('data'), |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
362 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span> |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
363 |
</pre></div> |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
364 |
''') |
5634
e01cf2013bf1
stop being dumb please
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5631
diff
changeset
|
365 |
else: |
5631
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
366 |
self.assertEquals(e.printable_value('data'), |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
367 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
0 | 368 |
</pre></div> |
369 |
''') |
|
370 |
else: |
|
371 |
self.assertEquals(e.printable_value('data'), |
|
372 |
'''<pre class="python"> |
|
373 |
<span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
|
374 |
</pre> |
|
375 |
''') |
|
1640 | 376 |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
377 |
e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
3587 | 378 |
data_encoding=u'utf-8', data_name=u'toto.txt') |
0 | 379 |
self.assertEquals(e.printable_value('data'), |
380 |
u'<p><em>héhéhé</em></p>\n') |
|
381 |
||
382 |
def test_printable_value_bad_html(self): |
|
383 |
"""make sure we don't crash if we try to render invalid XHTML strings""" |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
384 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
385 |
e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
0 | 386 |
content_format=u'text/html') |
387 |
tidy = lambda x: x.replace('\n', '') |
|
388 |
self.assertEquals(tidy(e.printable_value('content')), |
|
389 |
'<div>R&D<br/></div>') |
|
390 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
391 |
self.assertEquals(tidy(e.printable_value('content')), |
|
392 |
u'yo !! R&D <div> pas fermé</div>') |
|
393 |
e['content'] = u'R&D' |
|
394 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D') |
|
395 |
e['content'] = u'R&D;' |
|
396 |
self.assertEquals(tidy(e.printable_value('content')), u'R&D;') |
|
397 |
e['content'] = u'yo !! R&D <div> pas fermé' |
|
398 |
self.assertEquals(tidy(e.printable_value('content')), |
|
399 |
u'yo !! R&D <div> pas fermé</div>') |
|
400 |
e['content'] = u'été <div> été' |
|
401 |
self.assertEquals(tidy(e.printable_value('content')), |
|
402 |
u'été <div> été</div>') |
|
403 |
e['content'] = u'C'est un exemple sérieux' |
|
404 |
self.assertEquals(tidy(e.printable_value('content')), |
|
405 |
u"C'est un exemple sérieux") |
|
3587 | 406 |
# make sure valid xhtml is left untouched |
407 |
e['content'] = u'<div>R&D<br/></div>' |
|
408 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
409 |
e['content'] = u'<div>été</div>' |
|
410 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
411 |
e['content'] = u'été' |
|
412 |
self.assertEquals(e.printable_value('content'), e['content']) |
|
413 |
e['content'] = u'hop\r\nhop\nhip\rmomo' |
|
414 |
self.assertEquals(e.printable_value('content'), u'hop\nhop\nhip\nmomo') |
|
415 |
||
416 |
def test_printable_value_bad_html_ms(self): |
|
417 |
self.skip('fix soup2xhtml to handle this test') |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
418 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
419 |
e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
3587 | 420 |
content_format=u'text/html') |
421 |
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
|
422 |
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
|
423 |
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
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
**{'drop_proprietary_attributes': True, |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
428 |
'output_xhtml': True, |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
429 |
'show_body_only' : True, |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
430 |
'quote-nbsp' : False, |
83aabc5e3de3
a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3241
diff
changeset
|
431 |
'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
|
432 |
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
|
433 |
u'<div>ms orifice produces weird html</div>') |
1640 | 434 |
|
435 |
||
0 | 436 |
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
|
437 |
e = self.vreg['etypes'].etype_class('File')(self.request()) |
0 | 438 |
e['description'] = 'du <em>html</em>' |
439 |
e['description_format'] = 'text/html' |
|
440 |
e['data'] = Binary('some <em>data</em>') |
|
3587 | 441 |
e['data_name'] = 'an html file' |
0 | 442 |
e['data_format'] = 'text/html' |
443 |
e['data_encoding'] = 'ascii' |
|
4015
4f8235204dda
some cw 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
444 |
e._cw.transaction_data = {} # XXX req should be a session |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5636
diff
changeset
|
445 |
self.assertEquals(e.cw_adapt_to('IFTIndexable').get_words(), |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5636
diff
changeset
|
446 |
{'C': [u'du', u'html', 'an', 'html', 'file', u'some', u'data']}) |
0 | 447 |
|
1640 | 448 |
|
0 | 449 |
def test_nonregr_relation_cache(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
450 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
451 |
p1 = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
452 |
p2 = req.create_entity('Personne', nom=u'toto') |
0 | 453 |
self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"') |
454 |
self.assertEquals(p1.evaluee[0].nom, "toto") |
|
455 |
self.failUnless(not p1.reverse_evaluee) |
|
1640 | 456 |
|
0 | 457 |
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
|
458 |
session = self.session |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
459 |
eid = session.execute( |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
460 |
'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
|
461 |
'WHERE U login "admin", S1 name "activated", S2 name "deactivated"')[0][0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
462 |
trinfo = self.execute('Any X WHERE X eid %(x)s', {'x': eid}).get_entity(0, 0) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
463 |
trinfo.complete() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
464 |
self.failUnless(isinstance(trinfo['creation_date'], datetime)) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
465 |
self.failUnless(trinfo.cw_relation_cached('from_state', 'subject')) |
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
466 |
self.failUnless(trinfo.cw_relation_cached('to_state', 'subject')) |
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
467 |
self.failUnless(trinfo.cw_relation_cached('wf_info_for', 'subject')) |
3587 | 468 |
self.assertEquals(trinfo.by_transition, ()) |
0 | 469 |
|
470 |
def test_request_cache(self): |
|
471 |
req = self.request() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
472 |
user = self.execute('CWUser X WHERE X login "admin"', req=req).get_entity(0, 0) |
0 | 473 |
state = user.in_state[0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
474 |
samestate = self.execute('State X WHERE X name "activated"', req=req).get_entity(0, 0) |
0 | 475 |
self.failUnless(state is samestate) |
476 |
||
477 |
def test_rest_path(self): |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
478 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
479 |
note = req.create_entity('Note', type=u'z') |
0 | 480 |
self.assertEquals(note.rest_path(), 'note/%s' % note.eid) |
481 |
# unique attr |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
482 |
tag = req.create_entity('Tag', name=u'x') |
0 | 483 |
self.assertEquals(tag.rest_path(), 'tag/x') |
484 |
# test explicit rest_attr |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
485 |
person = req.create_entity('Personne', prenom=u'john', nom=u'doe') |
0 | 486 |
self.assertEquals(person.rest_path(), 'personne/doe') |
487 |
# ambiguity test |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
488 |
person2 = req.create_entity('Personne', prenom=u'remi', nom=u'doe') |
4460
5c22869079b9
clear rest_path __unique cache in clear_all_caches, fix related test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
489 |
person.clear_all_caches() |
0 | 490 |
self.assertEquals(person.rest_path(), 'personne/eid/%s' % person.eid) |
491 |
self.assertEquals(person2.rest_path(), 'personne/eid/%s' % person2.eid) |
|
492 |
# unique attr with None value (wikiid in this case) |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
493 |
card1 = req.create_entity('Card', title=u'hop') |
0 | 494 |
self.assertEquals(card1.rest_path(), 'card/eid/%s' % card1.eid) |
6099
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
495 |
# don't use rest if we have /, ? or & in the path (breaks mod_proxy) |
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
496 |
card2 = req.create_entity('Card', title=u'pod', wikiid=u'zo/bi') |
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
497 |
self.assertEquals(card2.rest_path(), 'card/eid/%d' % card2.eid) |
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
498 |
card3 = req.create_entity('Card', title=u'pod', wikiid=u'zo&bi') |
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
499 |
self.assertEquals(card3.rest_path(), 'card/eid/%d' % card3.eid) |
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
500 |
card4 = req.create_entity('Card', title=u'pod', wikiid=u'zo?bi') |
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
501 |
self.assertEquals(card4.rest_path(), 'card/eid/%d' % card4.eid) |
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
502 |
|
0 | 503 |
|
504 |
def test_set_attributes(self): |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
505 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
506 |
person = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
0 | 507 |
self.assertEquals(person.prenom, u'adrien') |
508 |
self.assertEquals(person.nom, u'di mascio') |
|
509 |
person.set_attributes(prenom=u'sylvain', nom=u'thénault') |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
510 |
person = self.execute('Personne P').get_entity(0, 0) # XXX retreival needed ? |
0 | 511 |
self.assertEquals(person.prenom, u'sylvain') |
512 |
self.assertEquals(person.nom, u'thénault') |
|
513 |
||
1905
9c96dd7cc624
[tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1640
diff
changeset
|
514 |
def test_metainformation_and_external_absolute_url(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
515 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
516 |
note = req.create_entity('Note', type=u'z') |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
517 |
metainf = note.cw_metainformation() |
0 | 518 |
self.assertEquals(metainf, {'source': {'adapter': 'native', 'uri': 'system'}, 'type': u'Note', 'extid': None}) |
519 |
self.assertEquals(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid) |
|
520 |
metainf['source'] = metainf['source'].copy() |
|
521 |
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
|
522 |
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
|
523 |
self.assertEquals(note.absolute_url(), 'http://cubicweb2.com/note/1234') |
1640 | 524 |
|
2125
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
525 |
def test_absolute_url_empty_field(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
526 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
527 |
card = req.create_entity('Card', wikiid=u'', title=u'test') |
2125
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
528 |
self.assertEquals(card.absolute_url(), |
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
529 |
'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
|
530 |
|
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
531 |
def test_create_entity(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
532 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
533 |
p1 = req.create_entity('Personne', nom=u'fayolle', prenom=u'alexandre') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
534 |
p2 = req.create_entity('Personne', nom=u'campeas', prenom=u'aurelien') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
535 |
note = req.create_entity('Note', type=u'z') |
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
536 |
req = self.request() |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
537 |
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
|
538 |
connait=p1, evaluee=[p1, p2], |
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
539 |
reverse_ecrit_par=note) |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
540 |
self.assertEquals(p.nom, 'di mascio') |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
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
|
544 |
|
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
545 |
|
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
546 |
|
0 | 547 |
if __name__ == '__main__': |
548 |
from logilab.common.testlib import unittest_main |
|
549 |
unittest_main() |
|
550 |