def test_update_email_ok(self, mocked_reset_pwd, mocked_add_status_msg): data = { 'email': '*****@*****.**', } request = fake_request(form_data=data, method='POST') # get the form to edit partner1 form = self.get_form('cms.form.my.account', sudo_uid=self.user1.id, req=request, main_object=self.partner1) # # make status message machinery happy form.o_request.website = self.env['website'].browse(1) result = form._handle_email_update(self.user1, data) # email has been updated self.assertEqual(self.partner1.email, data['email']) # user login too self.assertEqual(self.user1.login, data['email']) # result is ok self.assertTrue(result) # user has been logged out self.assertTrue(form.o_request.session.test_logged_out) # password reset has been forced mocked_reset_pwd.assert_called() # and we got a nice status message msg = ('Your login username has changed to: `[email protected]`. ' 'An email has been sent to verify it. ' 'You will be asked to reset your password.') self.assertEqual(mocked_add_status_msg.call_args[0][0], msg)
def test_form_update_different_email_update_called(self): data = {'email': self.user1.email} request = fake_request(form_data=data, method='POST') form = self.get_form('cms.form.my.account', sudo_uid=self.user1.id, req=request, main_object=self.partner1) # same email, not called with mock.patch.object(type(form), '_handle_email_update') as mocked: form.form_process() mocked.assert_not_called() # change email data = {'email': '*****@*****.**'} request = fake_request(form_data=data, method='POST') form = self.get_form('cms.form.my.account', sudo_uid=self.user1.id, req=request, main_object=self.partner1) # different email, called with mock.patch.object(type(form), '_handle_email_update') as mocked: form.form_process() mocked.assert_called_with(self.user1, data)
def test_form_updates(self): data = { 'enable_1': 'on', 'enable_2': '', 'enable_3': 'on', } req = fake_request(form_data=data, method='POST') form = self.get_form('cms.notification.panel.form', req=req, main_object=self.user1) form.form_process() self.assertIn(self.subtype1, self.user1.enabled_notify_subtype_ids) self.assertIn(self.subtype2, self.user1.disabled_notify_subtype_ids) self.assertIn(self.subtype3, self.user1.enabled_notify_subtype_ids)
def test_form_update(self): self.assertEqual(self.partner1.name, 'Test User 1') data = { 'name': 'Edward Norton', } request = fake_request(form_data=data, method='POST') # get the form to edit partner1 form = self.get_form('cms.form.my.account', sudo_uid=self.user1.id, req=request, main_object=self.partner1) # submit form as user1 form.form_create_or_update() self.assertEqual(self.partner1.name, data['name'])
def test_update_email_smtp_fail(self, mocked_add_status_msg): data = { 'email': '*****@*****.**', } request = fake_request(form_data=data, method='POST') # get the form to edit partner1 form = self.get_form('cms.form.my.account', sudo_uid=self.user1.id, req=request, main_object=self.partner1) form.o_request.website = self.env['website'].browse(1) with mock.patch.object(type(form), '_logout_and_notify') as mocked: with mock.patch.object( type(form), '_handle_login_update', **{'side_effect': MailDeliveryException('err', 'val')}): form.form_process() mocked.assert_not_called()
def test_form_update_vat_validation_called(self): data = { 'vat': 'this VAT is #so_wrong', } request = fake_request(form_data=data, method='POST') # get the form to edit partner1 form = self.get_form('cms.form.my.account', sudo_uid=self.user1.id, req=request, main_object=self.partner1) with mock.patch.object(type(form), '_form_validate_vat') as mocked: # method is mocked thus is going to return a mocked object # instead of a tuple. `form_validate` will raise ValueError mocked.return_value = ('vat_not_valid', 'message') form.form_process() mocked.assert_called_with( 'this VAT is #so_wrong', # request values vat='this VAT is #so_wrong', )
def test_form_update_email_validation_called(self): data = { 'email': 'this email is #so_wrong', } request = fake_request(form_data=data, method='POST') # get the form to edit partner1 form = self.get_form('cms.form.my.account', sudo_uid=self.user1.id, req=request, main_object=self.partner1) patch_path = \ 'odoo.addons.cms_account_form.models.account_form.AccountForm' with mock.patch(patch_path + '._form_validate_email') as patched: # method is mocked thus is going to return a mocked object # instead of a tuple. `form_validate` will raise ValueError patched.return_value = ('email_not_valid', 'message') form.form_process() patched.assert_called_with( 'this email is #so_wrong', # request values email='this email is #so_wrong', )
def test_update_email_exists(self, mocked_add_status_msg): self.user_model.create({ 'name': 'Lock a new email', 'login': '******', 'email': '*****@*****.**', }) data = { 'email': '*****@*****.**', } request = fake_request(form_data=data, method='POST') # get the form to edit partner1 form = self.get_form('cms.form.my.account', sudo_uid=self.user1.id, req=request, main_object=self.partner1) # make status message machinery happy form.o_request.website = self.env['website'].browse(1) result = form._handle_email_update(self.user1, data) # no update happened self.assertFalse(result) # and we got a nice status message msg = 'Email address `[email protected]` already taken.' self.assertEqual(mocked_add_status_msg.call_args[0][0], msg)
def test_form_next_url_redirect(self): req = fake_request(query_string='redirect=/foo') form = self.get_form('cms.notification.panel.form', req=req) self.assertEqual(form.form_next_url(), '/foo')
def test_form_next_url_redirect(self): req = fake_request(query_string='redirect=/foo') form = self.get_form('cms.form.my.account', req=req) self.assertEqual(form.form_next_url(), '/foo')