diff options
| author | Thibault Delavallée <tde@odoo.com> | 2020-10-14 14:27:06 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-10-14 14:27:06 +0000 |
| commit | 0075cc02f9a11dcddaf9ca7d70cc1adf7596f6d3 (patch) | |
| tree | c2fa832eeeff70f78364a79febba77852a72ab10 | |
| parent | db262912eb716aed1c42be8a9d59c25bdfa400e0 (diff) | |
[IMP] test_mail: add tests about alias defaults management
Purpose of this commit is simply to add tests about alias defaults.
Code protects it against being badly formatted. However having
tests ensuring it is always a good idea to avoid regression.
Task ID-2361179
closes odoo/odoo#60010
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
| -rw-r--r-- | addons/test_mail/tests/test_mail_gateway.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/addons/test_mail/tests/test_mail_gateway.py b/addons/test_mail/tests/test_mail_gateway.py index 630ccf47ffa..8c906497176 100644 --- a/addons/test_mail/tests/test_mail_gateway.py +++ b/addons/test_mail/tests/test_mail_gateway.py @@ -105,6 +105,8 @@ class TestMailAlias(TestMailCommon): 'alias_model_id': self.env['ir.model']._get('mail.test.gateway').id, }) + with self.assertRaises(exceptions.ValidationError): + record.write({'alias_defaults': "{'custom_field': brokendict"}) def test_alias_setup(self): alias = self.env['mail.alias'].create({ @@ -113,6 +115,9 @@ class TestMailAlias(TestMailCommon): }) self.assertEqual(alias.alias_name, 'b4r+_-_r3wl-', 'Disallowed chars should be replaced by hyphens') + with self.assertRaises(exceptions.ValidationError): + alias.write({'alias_defaults': "{'custom_field': brokendict"}) + def test_alias_name_unique(self): alias_model_id = self.env['ir.model']._get('mail.test.gateway').id catchall_alias = self.env['ir.config_parameter'].sudo().get_param('mail.catchall.alias') @@ -379,6 +384,29 @@ class TestMailgateway(TestMailCommon): self.assertSentEmail('"MAILER-DAEMON" <bounce.test@test.com>', ['whatever-2a840@postmaster.twitter.com'], body_content='The following email sent to') @mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models') + def test_message_process_alias_defaults(self): + """ Test alias defaults and inner values """ + self.alias.write({ + 'alias_user_id': self.user_employee.id, + 'alias_defaults': "{'custom_field': 'defaults_custom'}" + }) + + record = self.format_and_process(MAIL_TEMPLATE, self.email_from, 'groups@test.com', subject='Specific') + self.assertEqual(len(record), 1) + res = record.get_metadata()[0].get('create_uid') or [None] + self.assertEqual(res[0], self.user_employee.id) + self.assertEqual(record.name, 'Specific') + self.assertEqual(record.custom_field, 'defaults_custom') + + self.alias.write({'alias_defaults': '""'}) + record = self.format_and_process(MAIL_TEMPLATE, self.email_from, 'groups@test.com', subject='Specific2') + self.assertEqual(len(record), 1) + res = record.get_metadata()[0].get('create_uid') or [None] + self.assertEqual(res[0], self.user_employee.id) + self.assertEqual(record.name, 'Specific2') + self.assertFalse(record.custom_field) + + @mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models') def test_message_process_alias_user_id(self): """ Test alias ownership """ self.alias.write({'alias_user_id': self.user_employee.id}) |
