184 values = forminfo['values'] |
184 values = forminfo['values'] |
185 self.assertEquals(values['login-subject:'+eid], '') |
185 self.assertEquals(values['login-subject:'+eid], '') |
186 self.assertEquals(values['eid'], eid) |
186 self.assertEquals(values['eid'], eid) |
187 error = forminfo['error'] |
187 error = forminfo['error'] |
188 self.assertEquals(error.entity, user.eid) |
188 self.assertEquals(error.entity, user.eid) |
189 self.assertEquals(error.errors['login-subject'], 'required attribute') |
189 self.assertEquals(error.errors['login-subject'], 'required field') |
190 |
190 |
191 |
191 |
192 def test_validation_error_dont_loose_subentity_data(self): |
192 def test_validation_error_dont_loose_subentity_data_ctrl(self): |
193 """test creation of two linked entities |
193 """test creation of two linked entities |
|
194 |
|
195 error occurs on the web controller |
194 """ |
196 """ |
195 req = self.request() |
197 req = self.request() |
196 form = {'eid': ['X', 'Y'], '__maineid': 'X', |
198 # set Y before X to ensure both entities are edited, not only X |
197 '__type:X': 'CWUser', '_cw_edited_fields:X': 'login-subject,surname-subject', |
199 req.form = {'eid': ['Y', 'X'], '__maineid': 'X', |
198 # missing required field |
200 '__type:X': 'CWUser', '_cw_edited_fields:X': 'login-subject', |
199 'login-subject:X': u'', |
201 # missing required field |
200 'surname-subject:X': u'Mr Ouaoua', |
202 'login-subject:X': u'', |
201 # but email address is set |
203 # but email address is set |
202 '__type:Y': 'EmailAddress', '_cw_edited_fields:Y': 'address-subject,alias-subject,use_email-object', |
204 '__type:Y': 'EmailAddress', '_cw_edited_fields:Y': 'address-subject', |
203 'address-subject:Y': u'bougloup@logilab.fr', |
205 'address-subject:Y': u'bougloup@logilab.fr', |
204 'alias-subject:Y': u'', |
206 'use_email-object:Y': 'X', |
205 'use_email-object:Y': 'X', |
207 # necessary to get validation error handling |
206 # necessary to get validation error handling |
208 '__errorurl': 'view?vid=edition...', |
207 '__errorurl': 'view?vid=edition...', |
209 } |
208 } |
|
209 req.form = form |
|
210 # monkey patch edited_eid to ensure both entities are edited, not only X |
|
211 req.edited_eids = lambda : ('Y', 'X') |
|
212 path, params = self.expect_redirect(lambda x: self.app_publish(x, 'edit'), req) |
210 path, params = self.expect_redirect(lambda x: self.app_publish(x, 'edit'), req) |
213 forminfo = req.get_session_data('view?vid=edition...') |
211 forminfo = req.get_session_data('view?vid=edition...') |
214 self.assertEquals(set(forminfo['eidmap']), set('XY')) |
212 self.assertEquals(set(forminfo['eidmap']), set('XY')) |
|
213 self.assertEquals(forminfo['eidmap']['X'], None) |
|
214 self.assertIsInstance(forminfo['eidmap']['Y'], int) |
|
215 self.assertEquals(forminfo['error'].entity, 'X') |
|
216 self.assertEquals(forminfo['error'].errors, |
|
217 {'login-subject': 'required field'}) |
|
218 self.assertEquals(forminfo['values'], req.form) |
|
219 |
|
220 |
|
221 def test_validation_error_dont_loose_subentity_data_repo(self): |
|
222 """test creation of two linked entities |
|
223 |
|
224 error occurs on the repository |
|
225 """ |
|
226 req = self.request() |
|
227 # set Y before X to ensure both entities are edited, not only X |
|
228 req.form = {'eid': ['Y', 'X'], '__maineid': 'X', |
|
229 '__type:X': 'CWUser', '_cw_edited_fields:X': 'login-subject,upassword-subject', |
|
230 # already existent user |
|
231 'login-subject:X': u'admin', |
|
232 'upassword-subject:X': u'admin', 'upassword-subject-confirm:X': u'admin', |
|
233 '__type:Y': 'EmailAddress', '_cw_edited_fields:Y': 'address-subject', |
|
234 'address-subject:Y': u'bougloup@logilab.fr', |
|
235 'use_email-object:Y': 'X', |
|
236 # necessary to get validation error handling |
|
237 '__errorurl': 'view?vid=edition...', |
|
238 } |
|
239 path, params = self.expect_redirect(lambda x: self.app_publish(x, 'edit'), req) |
|
240 forminfo = req.get_session_data('view?vid=edition...') |
|
241 self.assertEquals(set(forminfo['eidmap']), set('XY')) |
|
242 self.assertIsInstance(forminfo['eidmap']['X'], int) |
|
243 self.assertIsInstance(forminfo['eidmap']['Y'], int) |
215 self.assertEquals(forminfo['error'].entity, forminfo['eidmap']['X']) |
244 self.assertEquals(forminfo['error'].entity, forminfo['eidmap']['X']) |
216 self.assertEquals(forminfo['error'].errors, |
245 self.assertEquals(forminfo['error'].errors, |
217 {'login-subject': 'required attribute', |
246 {'login-subject': u'the value "admin" is already used, use another one'}) |
218 'upassword-subject': 'required attribute'}) |
247 self.assertEquals(forminfo['values'], req.form) |
219 self.assertEquals(forminfo['values'], form) |
248 |
220 |
249 |
221 def _test_cleaned(self, kwargs, injected, cleaned): |
250 def _test_cleaned(self, kwargs, injected, cleaned): |
222 req = self.request(**kwargs) |
251 req = self.request(**kwargs) |
223 page = self.app.publish('view', req) |
252 page = self.app.publish('view', req) |
224 self.failIf(injected in page, (kwargs, injected)) |
253 self.failIf(injected in page, (kwargs, injected)) |