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