author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 15 Jul 2010 12:03:13 +0200 | |
branch | stable |
changeset 5976 | 00b1b6b906cf |
parent 5424 | 8ecbcbff9777 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1 |
# 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:
4252
diff
changeset
|
2 |
# 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:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# 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:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# 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:
4252
diff
changeset
|
7 |
# 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:
4252
diff
changeset
|
8 |
# 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:
4252
diff
changeset
|
9 |
# 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:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# 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:
4252
diff
changeset
|
12 |
# 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:
4252
diff
changeset
|
13 |
# 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:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# 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:
4252
diff
changeset
|
17 |
# 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:
1802
diff
changeset
|
18 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
20 |
""" |
0 | 21 |
from cubicweb.goa.testlib import * |
22 |
||
23 |
from urllib import unquote |
|
24 |
||
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
25 |
from cubicweb import ValidationError |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
26 |
from cubicweb.uilib import rql_for_eid |
0 | 27 |
|
28 |
from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect |
|
29 |
||
30 |
from cubicweb.goa.goaconfig import GAEConfiguration |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
31 |
from cubicweb.entities.authobjs import CWUser |
0 | 32 |
|
33 |
||
34 |
class EditControllerTC(GAEBasedTC): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
35 |
|
0 | 36 |
config = GAEConfiguration('toto') |
37 |
config.global_set_option('use-google-auth', False) |
|
38 |
config.global_set_option('schema-type', 'yams') |
|
39 |
config.global_set_option('included-cubes', ()) |
|
571 | 40 |
config.global_set_option('included-yams-cubes', ('blog',)) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
41 |
|
0 | 42 |
MODEL_CLASSES = () |
43 |
from cubicweb.web.views import editcontroller |
|
44 |
from cubicweb.entities import lib |
|
45 |
LOAD_APP_MODULES = (editcontroller, lib) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
46 |
|
0 | 47 |
def setUp(self): |
48 |
GAEBasedTC.setUp(self) |
|
49 |
self.req = self.request() |
|
50 |
self.ctrl = self.get_ctrl(self.req) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
51 |
|
0 | 52 |
def get_ctrl(self, req): |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
53 |
return self.vreg.select('controllers', 'edit', req=req, appli=self) |
0 | 54 |
|
55 |
def publish(self, req): |
|
56 |
assert req is self.ctrl.req |
|
57 |
try: |
|
58 |
result = self.ctrl.publish() |
|
59 |
req.cnx.commit() |
|
60 |
except Redirect: |
|
61 |
req.cnx.commit() |
|
62 |
raise |
|
63 |
except: |
|
64 |
req.cnx.rollback() |
|
65 |
raise |
|
66 |
return result |
|
67 |
||
68 |
def expect_redirect_publish(self, req=None): |
|
69 |
if req is not None: |
|
70 |
self.ctrl = self.get_ctrl(req) |
|
71 |
else: |
|
72 |
req = self.req |
|
73 |
try: |
|
74 |
res = self.publish(req) |
|
75 |
except Redirect, ex: |
|
76 |
try: |
|
77 |
path, params = ex.location.split('?', 1) |
|
78 |
except: |
|
79 |
path, params = ex.location, "" |
|
80 |
req._url = path |
|
81 |
cleanup = lambda p: (p[0], unquote(p[1])) |
|
82 |
params = dict(cleanup(p.split('=', 1)) for p in params.split('&') if p) |
|
83 |
return req.relative_path(False), params # path.rsplit('/', 1)[-1], params |
|
84 |
else: |
|
85 |
self.fail('expected a Redirect exception') |
|
86 |
||
87 |
def test_noparam_edit(self): |
|
88 |
"""check behaviour of this controller without any form parameter""" |
|
89 |
self.req.form = {} |
|
90 |
self.assertRaises(ValidationError, self.publish, self.req) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
91 |
|
0 | 92 |
def test_validation_unique(self): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
93 |
"""test creation of two linked entities""" |
0 | 94 |
user = self.user |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
95 |
self.req.form = {'eid': 'X', '__type:X': 'CWUser', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
96 |
'login:X': self.user.login, 'edits-login:X': u'', |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
97 |
'upassword:X': u'toto', 'upassword-confirm:X': u'toto', 'edits-upassword:X': u'', |
0 | 98 |
} |
99 |
self.assertRaises(ValidationError, self.publish, self.req) |
|
100 |
||
101 |
||
102 |
def test_user_editing_itself(self): |
|
103 |
"""checking that a manager user can edit itself""" |
|
104 |
self.skip('missing actual gae support, retry latter') |
|
105 |
user = self.user |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
106 |
basegroups = [str(eid) for eid, in self.req.execute('CWGroup G WHERE X in_group G, X eid %(x)s', {'x': user.eid})] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
107 |
groupeids = [eid for eid, in self.req.execute('CWGroup G WHERE G name in ("managers", "users")')] |
0 | 108 |
groups = [str(eid) for eid in groupeids] |
109 |
stateeid = [eid for eid, in self.req.execute('State S WHERE S name "activated"')][0] |
|
110 |
self.req.form = { |
|
111 |
'eid': user.eid, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
112 |
'__type:'+user.eid: 'CWUser', |
0 | 113 |
'login:'+user.eid: unicode(user.login), |
114 |
'firstname:'+user.eid: u'Th\xe9nault', |
|
115 |
'surname:'+user.eid: u'Sylvain', |
|
116 |
'in_group:'+user.eid: groups, |
|
117 |
'in_state:'+user.eid: stateeid, |
|
118 |
# |
|
119 |
'edits-login:'+user.eid: unicode(user.login), |
|
120 |
'edits-firstname:'+user.eid: u'', |
|
121 |
'edits-surname:'+user.eid: u'', |
|
122 |
'edits-in_group:'+user.eid: basegroups, |
|
123 |
'edits-in_state:'+user.eid: stateeid, |
|
124 |
} |
|
125 |
path, params = self.expect_redirect_publish() |
|
126 |
e = self.req.execute('Any X WHERE X eid %(x)s', {'x': user.eid}, 'x').get_entity(0, 0) |
|
127 |
self.assertEquals(e.firstname, u'Th\xe9nault') |
|
128 |
self.assertEquals(e.surname, u'Sylvain') |
|
129 |
self.assertEquals(e.login, user.login) |
|
130 |
self.assertEquals([g.eid for g in e.in_group], groupeids) |
|
131 |
self.assertEquals(e.in_state[0].eid, stateeid) |
|
132 |
||
133 |
def test_user_can_change_its_password(self): |
|
134 |
user = self.create_user('user') |
|
135 |
cnx = self.login('user') |
|
136 |
req = self.request() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
137 |
#self.assertEquals(self.ctrl.schema['CWUser']._groups['read'], |
0 | 138 |
# ('managers', 'users')) |
139 |
req.form = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
140 |
'eid': user.eid, '__type:'+user.eid: 'CWUser', |
0 | 141 |
'__maineid' : str(user.eid), |
142 |
'upassword:'+user.eid: 'tournicoton', |
|
143 |
'upassword-confirm:'+user.eid: 'tournicoton', |
|
144 |
'edits-upassword:'+user.eid: '', |
|
145 |
} |
|
146 |
path, params = self.expect_redirect_publish(req) |
|
147 |
cnx.commit() # commit to check we don't get late validation error for instance |
|
148 |
self.assertEquals(path, 'euser/user') |
|
149 |
self.failIf('vid' in params) |
|
150 |
||
151 |
def test_user_editing_itself_no_relation(self): |
|
152 |
"""checking we can edit an entity without specifying some required |
|
153 |
relations (meaning no changes) |
|
154 |
""" |
|
155 |
user = self.user |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
156 |
groupeids = [eid for eid, in self.req.execute('CWGroup G WHERE X in_group G, X eid %(x)s', {'x': user.eid})] |
0 | 157 |
self.req.form = { |
158 |
'eid': user.eid, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
159 |
'__type:'+user.eid: 'CWUser', |
0 | 160 |
'login:'+user.eid: unicode(user.login), |
161 |
'firstname:'+user.eid: u'Th\xe9nault', |
|
162 |
'surname:'+user.eid: u'Sylvain', |
|
163 |
# |
|
164 |
'edits-login:'+user.eid: unicode(user.login), |
|
165 |
'edits-firstname:'+user.eid: u'', |
|
166 |
'edits-surname:'+user.eid: u'', |
|
167 |
} |
|
168 |
path, params = self.expect_redirect_publish() |
|
169 |
self.req.drop_entity_cache(user.eid) |
|
170 |
e = self.req.execute('Any X WHERE X eid %(x)s', {'x': user.eid}, 'x').get_entity(0, 0) |
|
171 |
self.assertEquals(e.login, user.login) |
|
172 |
self.assertEquals(e.firstname, u'Th\xe9nault') |
|
173 |
self.assertEquals(e.surname, u'Sylvain') |
|
174 |
self.assertUnorderedIterableEquals([g.eid for g in e.in_group], groupeids) |
|
175 |
#stateeids = [eid for eid, in self.req.execute('State S WHERE S name "activated"')] |
|
176 |
#self.assertEquals([s.eid for s in e.in_state], stateeids) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
177 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
178 |
|
0 | 179 |
def test_create_multiple_linked(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
180 |
gueid = self.req.execute('CWGroup G WHERE G name "users"')[0][0] |
0 | 181 |
self.req.form = {'eid': ['X', 'Y'], |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
182 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
183 |
'__type:X': 'CWUser', |
0 | 184 |
'__maineid' : 'X', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
185 |
'login:X': u'adim', 'edits-login:X': u'', |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
186 |
'upassword:X': u'toto', 'upassword-confirm:X': u'toto', 'edits-upassword:X': u'', |
0 | 187 |
'surname:X': u'Di Mascio', 'edits-surname:X': '', |
188 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
189 |
'in_group:X': gueid, 'edits-in_group:X': INTERNAL_FIELD_VALUE, |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
190 |
|
0 | 191 |
'__type:Y': 'EmailAddress', |
192 |
'address:Y': u'dima@logilab.fr', 'edits-address:Y': '', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
193 |
'use_email:X': 'Y', 'edits-use_email:X': INTERNAL_FIELD_VALUE, |
0 | 194 |
} |
195 |
path, params = self.expect_redirect_publish() |
|
196 |
# should be redirected on the created person |
|
197 |
self.assertEquals(path, 'euser/adim') |
|
198 |
e = self.req.execute('Any P WHERE P surname "Di Mascio"').get_entity(0, 0) |
|
199 |
self.assertEquals(e.surname, 'Di Mascio') |
|
200 |
email = e.use_email[0] |
|
201 |
self.assertEquals(email.address, 'dima@logilab.fr') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
202 |
|
0 | 203 |
def test_edit_multiple_linked(self): |
204 |
peid = self.create_user('adim').eid |
|
205 |
self.req.form = {'eid': [peid, 'Y'], |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
206 |
'__type:%s'%peid: 'CWUser', |
0 | 207 |
'surname:%s'%peid: u'Di Masci', 'edits-surname:%s'%peid: '', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
208 |
|
0 | 209 |
'__type:Y': 'EmailAddress', |
210 |
'address:Y': u'dima@logilab.fr', 'edits-address:Y': '', |
|
211 |
'use_email:%s'%peid: 'Y', 'edits-use_email:%s'%peid: INTERNAL_FIELD_VALUE, |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
212 |
|
0 | 213 |
'__redirectrql': 'Any X WHERE X eid %s'%peid, |
214 |
} |
|
215 |
path, params = self.expect_redirect_publish() |
|
216 |
# should be redirected on the created person |
|
217 |
eid = params['rql'].split()[-1] |
|
218 |
e = self.req.execute('Any X WHERE X eid %(x)s', {'x': eid}, 'x').get_entity(0, 0) |
|
219 |
self.assertEquals(e.surname, 'Di Masci') |
|
220 |
email = e.use_email[0] |
|
221 |
self.assertEquals(email.address, 'dima@logilab.fr') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
222 |
|
0 | 223 |
emaileid = email.eid |
224 |
self.req.form = {'eid': [peid, emaileid], |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
225 |
'__type:%s'%peid: 'CWUser', |
0 | 226 |
'surname:%s'%peid: u'Di Masci', 'edits-surname:%s'%peid: 'Di Masci', |
227 |
'__type:%s'%emaileid: 'EmailAddress', |
|
228 |
'address:%s'%emaileid: u'adim@logilab.fr', 'edits-address:%s'%emaileid: 'dima@logilab.fr', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
229 |
'use_email:%s'%peid: emaileid, 'edits-use_email:%s'%peid: emaileid, |
0 | 230 |
'__redirectrql': 'Any X WHERE X eid %s'%peid, |
231 |
} |
|
232 |
path, params = self.expect_redirect_publish() |
|
233 |
# should be redirected on the created person |
|
234 |
eid = params['rql'].split()[-1] |
|
235 |
# XXX this should not be necessary, it isn't with regular cubicweb |
|
236 |
self.req._eid_cache = {} |
|
237 |
e = self.req.execute('Any X WHERE X eid %(x)s', {'x': eid}, 'x').get_entity(0, 0) |
|
238 |
self.assertEquals(e.surname, 'Di Masci') |
|
239 |
email = e.use_email[0] |
|
240 |
self.assertEquals(email.address, 'adim@logilab.fr') |
|
241 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
242 |
|
0 | 243 |
def test_password_confirm(self): |
244 |
"""test creation of two linked entities |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
245 |
""" |
0 | 246 |
user = self.user |
247 |
self.req.form = {'__cloned_eid:X': user.eid, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
248 |
'eid': 'X', '__type:X': 'CWUser', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
249 |
'login:X': u'toto', 'edits-login:X': u'', |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
250 |
'upassword:X': u'toto', 'edits-upassword:X': u'', |
0 | 251 |
} |
252 |
self.assertRaises(ValidationError, self.publish, self.req) |
|
253 |
self.req.form = {'__cloned_eid:X': user.eid, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
254 |
'eid': 'X', '__type:X': 'CWUser', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
255 |
'login:X': u'toto', 'edits-login:X': u'', |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
256 |
'upassword:X': u'toto', 'upassword-confirm:X': u'tutu', 'edits-upassword:X': u'', |
0 | 257 |
} |
258 |
self.assertRaises(ValidationError, self.publish, self.req) |
|
259 |
||
260 |
||
261 |
def test_req_pending_insert(self): |
|
262 |
"""make sure req's pending insertions are taken into account""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
263 |
tmpgroup = self.add_entity('CWGroup', name=u"test") |
0 | 264 |
user = self.user |
265 |
self.req.set_session_data('pending_insert', set([(user.eid, 'in_group', tmpgroup.eid)])) |
|
266 |
path, params = self.expect_redirect_publish() |
|
267 |
usergroups = [gname for gname, in |
|
268 |
self.req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
269 |
self.assertUnorderedIterableEquals(usergroups, ['managers', 'users', 'test']) |
|
270 |
self.assertEquals(self.req.get_pending_inserts(), []) |
|
271 |
||
272 |
||
273 |
def test_req_pending_delete(self): |
|
274 |
"""make sure req's pending deletions are taken into account""" |
|
275 |
user = self.user |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
276 |
groupeid = self.req.execute('INSERT CWGroup G: G name "test", U in_group G WHERE U eid %(x)s', |
0 | 277 |
{'x': user.eid})[0][0] |
278 |
usergroups = [gname for gname, in |
|
279 |
self.req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
280 |
# just make sure everything was set correctly |
|
281 |
self.assertUnorderedIterableEquals(usergroups, ['managers', 'users', 'test']) |
|
282 |
# now try to delete the relation |
|
283 |
self.req.set_session_data('pending_delete', set([(user.eid, 'in_group', groupeid)])) |
|
284 |
path, params = self.expect_redirect_publish() |
|
285 |
usergroups = [gname for gname, in |
|
286 |
self.req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
287 |
self.assertUnorderedIterableEquals(usergroups, ['managers', 'users']) |
|
288 |
#self.assertUnorderedIterableEquals(usergroups, ['managers']) |
|
289 |
self.assertEquals(self.req.get_pending_deletes(), []) |
|
290 |
||
291 |
def test_custom_attribute_handler(self): |
|
292 |
def custom_login_edit(self, formparams, value, relations): |
|
293 |
formparams['login'] = value.upper() |
|
294 |
relations.append('X login %(login)s') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
295 |
CWUser.custom_login_edit = custom_login_edit |
0 | 296 |
try: |
297 |
user = self.user |
|
298 |
eid = repr(user.eid) |
|
299 |
self.req.form = { |
|
300 |
'eid': eid, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
301 |
'__type:'+eid: 'CWUser', |
0 | 302 |
'login:'+eid: u'foo', |
303 |
'edits-login:'+eid: unicode(user.login), |
|
304 |
} |
|
305 |
path, params = self.expect_redirect_publish() |
|
306 |
rset = self.req.execute('Any L WHERE X eid %(x)s, X login L', {'x': user.eid}, 'x') |
|
307 |
self.assertEquals(rset[0][0], 'FOO') |
|
308 |
finally: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
309 |
del CWUser.custom_login_edit |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
310 |
|
0 | 311 |
def test_redirect_apply_button(self): |
312 |
redirectrql = rql_for_eid(4012) # whatever |
|
313 |
self.req.form = { |
|
314 |
'eid': 'A', '__type:A': 'BlogEntry', |
|
315 |
'__maineid' : 'A', |
|
316 |
'content:A': u'"13:03:43"', 'edits-content:A': '', |
|
317 |
'title:A': u'huuu', 'edits-title:A': '', |
|
318 |
'__redirectrql': redirectrql, |
|
319 |
'__redirectvid': 'primary', |
|
320 |
'__redirectparams': 'toto=tutu&tata=titi', |
|
321 |
'__form_id': 'edition', |
|
322 |
'__action_apply': '', |
|
323 |
} |
|
324 |
path, params = self.expect_redirect_publish() |
|
325 |
self.failUnless(path.startswith('blogentry/')) |
|
326 |
eid = path.split('/')[1] |
|
327 |
self.assertEquals(params['vid'], 'edition') |
|
328 |
self.assertNotEquals(eid, '4012') |
|
329 |
self.assertEquals(params['__redirectrql'], redirectrql) |
|
330 |
self.assertEquals(params['__redirectvid'], 'primary') |
|
331 |
self.assertEquals(params['__redirectparams'], 'toto=tutu&tata=titi') |
|
332 |
||
333 |
def test_redirect_ok_button(self): |
|
334 |
redirectrql = rql_for_eid(4012) # whatever |
|
335 |
self.req.form = { |
|
336 |
'eid': 'A', '__type:A': 'BlogEntry', |
|
337 |
'__maineid' : 'A', |
|
338 |
'content:A': u'"13:03:43"', 'edits-content:A': '', |
|
339 |
'title:A': u'huuu', 'edits-title:A': '', |
|
340 |
'__redirectrql': redirectrql, |
|
341 |
'__redirectvid': 'primary', |
|
342 |
'__redirectparams': 'toto=tutu&tata=titi', |
|
343 |
'__form_id': 'edition', |
|
344 |
} |
|
345 |
path, params = self.expect_redirect_publish() |
|
346 |
self.assertEquals(path, 'view') |
|
347 |
self.assertEquals(params['rql'], redirectrql) |
|
348 |
self.assertEquals(params['vid'], 'primary') |
|
349 |
self.assertEquals(params['tata'], 'titi') |
|
350 |
self.assertEquals(params['toto'], 'tutu') |
|
351 |
||
352 |
def test_redirect_delete_button(self): |
|
353 |
eid = self.add_entity('BlogEntry', title=u'hop', content=u'hop').eid |
|
354 |
self.req.form = {'eid': str(eid), '__type:%s'%eid: 'BlogEntry', |
|
355 |
'__action_delete': ''} |
|
356 |
path, params = self.expect_redirect_publish() |
|
357 |
self.assertEquals(path, 'blogentry') |
|
358 |
self.assertEquals(params, {u'__message': u'entity deleted'}) |
|
359 |
eid = self.add_entity('EmailAddress', address=u'hop@logilab.fr').eid |
|
360 |
self.req.execute('SET X use_email E WHERE E eid %(e)s, X eid %(x)s', |
|
361 |
{'x': self.user.eid, 'e': eid}, 'x') |
|
362 |
self.commit() |
|
363 |
self.req.form = {'eid': str(eid), '__type:%s'%eid: 'EmailAddress', |
|
364 |
'__action_delete': ''} |
|
365 |
path, params = self.expect_redirect_publish() |
|
366 |
self.assertEquals(unquote(path), 'euser/'+self.user.login) |
|
367 |
self.assertEquals(params, {u'__message': u'entity deleted'}) |
|
368 |
eid1 = self.add_entity('BlogEntry', title=u'hop', content=u'hop').eid |
|
369 |
eid2 = self.add_entity('EmailAddress', address=u'hop@logilab.fr').eid |
|
370 |
self.req.form = {'eid': [str(eid1), str(eid2)], |
|
371 |
'__type:%s'%eid1: 'BlogEntry', |
|
372 |
'__type:%s'%eid2: 'EmailAddress', |
|
373 |
'__action_delete': ''} |
|
374 |
path, params = self.expect_redirect_publish() |
|
375 |
self.assertEquals(path, 'view') |
|
376 |
self.assertEquals(params, {u'__message': u'entities deleted'}) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
377 |
|
0 | 378 |
|
379 |
def test_nonregr_multiple_empty_email_addr(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
380 |
gueid = self.req.execute('CWGroup G WHERE G name "users"')[0][0] |
0 | 381 |
self.req.form = {'eid': ['X', 'Y'], |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
382 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
383 |
'__type:X': 'CWUser', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
384 |
'login:X': u'adim', 'edits-login:X': u'', |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
385 |
'upassword:X': u'toto', 'upassword-confirm:X': u'toto', 'edits-upassword:X': u'', |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
386 |
'in_group:X': gueid, 'edits-in_group:X': INTERNAL_FIELD_VALUE, |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
387 |
|
0 | 388 |
'__type:Y': 'EmailAddress', |
389 |
'address:Y': u'', 'edits-address:Y': '', |
|
390 |
'alias:Y': u'', 'edits-alias:Y': '', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
391 |
'use_email:X': 'Y', 'edits-use_email:X': INTERNAL_FIELD_VALUE, |
0 | 392 |
} |
393 |
self.assertRaises(ValidationError, self.publish, self.req) |
|
394 |
||
395 |
||
396 |
def test_nonregr_rollback_on_validation_error(self): |
|
397 |
self.skip('lax fix me') |
|
398 |
p = self.create_user("doe") |
|
399 |
# do not try to skip 'primary_email' for this test |
|
400 |
old_skips = p.__class__.skip_copy_for |
|
401 |
p.__class__.skip_copy_for = () |
|
402 |
try: |
|
403 |
e = self.add_entity('EmailAddress', address=u'doe@doe.com') |
|
404 |
self.req.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s', |
|
405 |
{'p' : p.eid, 'e' : e.eid}) |
|
406 |
self.req.form = {'__cloned_eid:X': p.eid, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
407 |
'eid': 'X', '__type:X': 'CWUser', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
408 |
'login': u'dodo', 'edits-login': u'dodo', |
0 | 409 |
'surname:X': u'Boom', 'edits-surname:X': u'', |
410 |
'__errorurl' : "whatever but required", |
|
411 |
} |
|
412 |
# try to emulate what really happens in the web application |
|
413 |
# 1/ validate form => EditController.publish raises a ValidationError |
|
414 |
# which fires a Redirect |
|
415 |
# 2/ When re-publishing the copy form, the publisher implicitly commits |
|
416 |
try: |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
417 |
self.app.publish('edit', self.req) |
0 | 418 |
except Redirect: |
419 |
self.req.form['rql'] = 'Any X WHERE X eid %s' % p.eid |
|
420 |
self.req.form['vid'] = 'copy' |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
421 |
self.app.publish('view', self.req) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
571
diff
changeset
|
422 |
rset = self.req.execute('CWUser P WHERE P surname "Boom"') |
0 | 423 |
self.assertEquals(len(rset), 0) |
424 |
finally: |
|
425 |
p.__class__.skip_copy_for = old_skips |
|
426 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
427 |
|
0 | 428 |
if __name__ == '__main__': |
429 |
from logilab.common.testlib import unittest_main |
|
430 |
unittest_main() |