diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-11-08 09:43:56 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-11-20 16:01:06 +0000 |
| commit | b287504977e532fe2d178a4d62df6f9eb7a17f22 (patch) | |
| tree | 32c6274f21e0b7f08a8e5887425e8d6efd26cfd0 | |
| parent | 363bdc16c7f03ba0f323bc9afbf1878de44fa008 (diff) | |
[REF] test_mass_mailing: update module to new common
PURPOSE
Currently tools and asserts for mail tests are located inside test_mail
module. It makes difficult to re-use them in apps tests or force them to
write custom quick and dirty tools and asserts.
SPECIFICATIONS
Update this module to new tools / asserts / helpers / classes defined in mail
and test_mail.
In this commit we remove the ``MassMailingCase`` and replace it by a fresh
``TestMailCommon`` that is simply updated to hold a marketing user by default.
That way all mocks and asserts are available in all sub test classes.
Coming from common update, we have notably
* ``BaseFunctionalTest`` class is replaced by the new ``TestMailCommon``
pimped one;
* ``assertNotifications`` is replaced by ``assertSinglePostNotifications``
(shortcut for a simple message_post) or ``assertPostNotifications``
(complete asserts involving several messages and notifications);
* correctly invoke ``mock_mail_gateway`` when mocking email sending;
* replace manual check of sent emails or ``assertEmails`` by
``assertSentEmails``;
* remove custom mocks / checks and replace them by now standard mocks
and assertions (if any);
LINKS
Task ID 2068986
PR #38070
| -rw-r--r-- | addons/mass_mailing/tests/test_mass_mailing_list_merge.py | 2 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/common.py | 15 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/test_blacklist.py | 23 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/test_blacklist_mixin.py | 16 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/test_composer.py | 14 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/test_link.py | 2 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/test_mail_channel.py | 6 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/test_mass_mailing.py | 6 | ||||
| -rw-r--r-- | addons/test_mass_mailing/tests/test_performance.py | 2 |
9 files changed, 35 insertions, 51 deletions
diff --git a/addons/mass_mailing/tests/test_mass_mailing_list_merge.py b/addons/mass_mailing/tests/test_mass_mailing_list_merge.py index fe8feba73ec..e28ebfac323 100644 --- a/addons/mass_mailing/tests/test_mass_mailing_list_merge.py +++ b/addons/mass_mailing/tests/test_mass_mailing_list_merge.py @@ -4,7 +4,7 @@ from odoo.tests import common -class TestMassMailingCommon(common.TransactionCase): +class TestMailingListMerge(common.TransactionCase): def test_00_test_mass_mailing_list_merge(self): # Data set up diff --git a/addons/test_mass_mailing/tests/common.py b/addons/test_mass_mailing/tests/common.py index b0a7e3985d6..c66b92906b0 100644 --- a/addons/test_mass_mailing/tests/common.py +++ b/addons/test_mass_mailing/tests/common.py @@ -1,24 +1,17 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.addons.mail.tests.common import mail_new_test_user from odoo.addons.test_mail.tests import common -from odoo.addons.test_mail.tests.common import mail_new_test_user -from odoo.tests import tagged -@tagged('mass_mail') -class MassMailingCase(common.MockEmails, common.BaseFunctionalTest): +class TestMailCommon(common.TestMailCommon): @classmethod def setUpClass(cls): - super(MassMailingCase, cls).setUpClass() - - # be sure for some common data - cls.user_employee.write({ - 'login': 'emp', - }) + super(TestMailCommon, cls).setUpClass() cls.user_marketing = mail_new_test_user( cls.env, login='marketing', - groups='base.group_user,mass_mailing.group_mass_mailing_user', + groups='base.group_user,base.group_partner_manager,mass_mailing.group_mass_mailing_user', name='Martial Marketing', signature='--\nMartial') diff --git a/addons/test_mass_mailing/tests/test_blacklist.py b/addons/test_mass_mailing/tests/test_blacklist.py index 9b8eb202243..58c7380b38d 100644 --- a/addons/test_mass_mailing/tests/test_blacklist.py +++ b/addons/test_mass_mailing/tests/test_blacklist.py @@ -2,24 +2,23 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.tests.common import users -from odoo.addons.test_mail.tests.common import mail_new_test_user from odoo.addons.test_mass_mailing.tests import common from odoo.exceptions import AccessError -class TestBLAccessRights(common.MassMailingCase): +class TestBLAccessRights(common.TestMailCommon): - def setUp(self): - super(TestBLAccessRights, self).setUp() - self.bl_rec = self.env['mail.blacklist'].create([ + @classmethod + def setUpClass(cls): + super(TestBLAccessRights, cls).setUpClass() + cls._create_portal_user() + + cls.bl_rec = cls.env['mail.blacklist'].create([ {'email': 'Not A Stark <john.snow@example.com>'}, ]) + cls.bl_previous = cls.env['mail.blacklist'].search([]) - self.user_portal = mail_new_test_user(self.env, login='port', groups='base.group_portal') - - self.bl_previous = self.env['mail.blacklist'].search([]) - - @users('emp') + @users('employee') def test_bl_crud_employee(self): with self.assertRaises(AccessError): self.env['mail.blacklist'].create([{'email': 'Arya.Stark@example.com'}]) @@ -33,7 +32,7 @@ class TestBLAccessRights(common.MassMailingCase): with self.assertRaises(AccessError): self.bl_rec.with_user(self.env.user).unlink() - @users('port') + @users('portal_test') def test_bl_crud_portal(self): with self.assertRaises(AccessError): self.env['mail.blacklist'].create([{'email': 'Arya.Stark@example.com'}]) @@ -60,7 +59,7 @@ class TestBLAccessRights(common.MassMailingCase): self.bl_rec.with_user(self.env.user).unlink() -class TestBLConsistency(common.MassMailingCase): +class TestBLConsistency(common.TestMailCommon): _base_list = ['Arya.Stark@example.com', 'ned.stark@example.com'] def setUp(self): diff --git a/addons/test_mass_mailing/tests/test_blacklist_mixin.py b/addons/test_mass_mailing/tests/test_blacklist_mixin.py index 0e7b167f5e7..01f95496f6f 100644 --- a/addons/test_mass_mailing/tests/test_blacklist_mixin.py +++ b/addons/test_mass_mailing/tests/test_blacklist_mixin.py @@ -1,15 +1,13 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from unittest.mock import patch - -from odoo.tests.common import users from odoo.addons.test_mass_mailing.tests import common from odoo.addons.test_mass_mailing.models.mass_mail_test import MassMailTestBlacklist -from odoo.exceptions import AccessError, UserError +from odoo.exceptions import UserError +from odoo.tests.common import users -class TestBLMixin(common.MassMailingCase): +class TestBLMixin(common.TestMailCommon): @classmethod def setUpClass(cls): @@ -23,7 +21,7 @@ class TestBLMixin(common.MassMailingCase): 'active': False, }]) - @users('emp') + @users('employee') def test_bl_mixin_primary_field_consistency(self): MassMailTestBlacklist._primary_email = 'not_a_field' with self.assertRaises(UserError): @@ -36,7 +34,7 @@ class TestBLMixin(common.MassMailingCase): MassMailTestBlacklist._primary_email = 'email_from' self.env['mass.mail.test.bl'].search([('is_blacklisted', '=', False)]) - @users('emp') + @users('employee') def test_bl_mixin_is_blacklisted(self): """ Test is_blacklisted field computation """ record = self.env['mass.mail.test.bl'].create({'email_from': 'arya.stark@example.com'}) @@ -45,7 +43,7 @@ class TestBLMixin(common.MassMailingCase): record = self.env['mass.mail.test.bl'].create({'email_from': 'not.arya.stark@example.com'}) self.assertFalse(record.is_blacklisted) - @users('emp') + @users('employee') def test_bl_mixin_search_blacklisted(self): """ Test is_blacklisted field search implementation """ record1 = self.env['mass.mail.test.bl'].create({'email_from': 'arya.stark@example.com'}) @@ -63,7 +61,7 @@ class TestBLMixin(common.MassMailingCase): search_res = self.env['mass.mail.test.bl'].search([('is_blacklisted', '!=', False)]) self.assertEqual(search_res, record1) - @users('emp') + @users('employee') def test_bl_mixin_search_blacklisted_format(self): """ Test is_blacklisted field search using email parsing """ record1 = self.env['mass.mail.test.bl'].create({'email_from': 'Arya Stark <arya.stark@example.com>'}) diff --git a/addons/test_mass_mailing/tests/test_composer.py b/addons/test_mass_mailing/tests/test_composer.py index 4307bc95591..2b43e87e6d9 100644 --- a/addons/test_mass_mailing/tests/test_composer.py +++ b/addons/test_mass_mailing/tests/test_composer.py @@ -1,28 +1,22 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.addons.test_mail.tests.common import mail_new_test_user -from odoo.tests import common +from odoo.addons.test_mass_mailing.tests import common -class TestComposer(common.SavepointCase): +class TestComposer(common.TestMailCommon): def test_body_responsive(self): """ Testing mail mailing responsive mail body """ - test_user = mail_new_test_user( - self.env, login='geraldine', - groups='mass_mailing.group_mass_mailing_user,base.group_partner_manager' # TDE FIXME: check if really necessary for mass mailing - ) - test_record = self.env['res.partner'].create({'name': 'Mass Mail Partner'}) - mass_mail_record = self.env['mailing.mailing'].with_user(test_user).create({ + mass_mail_record = self.env['mailing.mailing'].with_user(self.user_marketing).create({ 'name': 'Test', 'subject': 'Test', 'state': 'draft', 'mailing_model_id': self.env.ref('base.model_res_partner').id, }) - composer = self.env['mail.compose.message'].with_user(test_user).with_context({ + composer = self.env['mail.compose.message'].with_user(self.user_marketing).with_context({ 'default_composition_mode': 'mass_mail', 'default_model': 'res.partner', 'default_res_id': test_record.id, diff --git a/addons/test_mass_mailing/tests/test_link.py b/addons/test_mass_mailing/tests/test_link.py index b081c384709..6e5efae85e3 100644 --- a/addons/test_mass_mailing/tests/test_link.py +++ b/addons/test_mass_mailing/tests/test_link.py @@ -5,7 +5,7 @@ from odoo.tests.common import users from odoo.addons.test_mass_mailing.tests import common -class TestLinkTracker(common.MassMailingCase): +class TestLinkTracker(common.TestMailCommon): def setUp(self): super(TestLinkTracker, self).setUp() diff --git a/addons/test_mass_mailing/tests/test_mail_channel.py b/addons/test_mass_mailing/tests/test_mail_channel.py index c966447ca76..b8bcd59d908 100644 --- a/addons/test_mass_mailing/tests/test_mail_channel.py +++ b/addons/test_mass_mailing/tests/test_mail_channel.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. + from odoo.addons.test_mail.tests import common from odoo.tools import formataddr -class TestChannelPartnersNotification(common.MockEmails): +class TestChannelPartnersNotification(common.TestMailCommon): def _join_channel(self, channel, partners): for partner in partners: @@ -38,7 +39,8 @@ class TestChannelPartnersNotification(common.MockEmails): self.env['ir.config_parameter'].set_param('mail.catchall.domain', 'schlouby.fr') self.test_channel.write({'email_send': True}) self._join_channel(self.test_channel, self.test_partner) - self.test_channel.message_post(body="Test", message_type='comment', subtype='mt_comment') + with self.mock_mail_gateway(): + self.test_channel.message_post(body="Test", message_type='comment', subtype='mt_comment') self.assertEqual(len(self._mails), 1, 'Number of mail incorrect. Should be equal to 1.') for email in self._mails: diff --git a/addons/test_mass_mailing/tests/test_mass_mailing.py b/addons/test_mass_mailing/tests/test_mass_mailing.py index ea6ab8d9ae6..430438e76a0 100644 --- a/addons/test_mass_mailing/tests/test_mass_mailing.py +++ b/addons/test_mass_mailing/tests/test_mass_mailing.py @@ -1,16 +1,14 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from unittest.mock import patch from werkzeug import urls -from odoo.addons.test_mass_mailing.tests.common import MassMailingCase -from odoo.addons.base.models.ir_config_parameter import IrConfigParameter +from odoo.addons.test_mass_mailing.tests.common import TestMailCommon from odoo.tests.common import TransactionCase, users from odoo.tools import mute_logger -class TestMassMail(MassMailingCase): +class TestMassMail(TestMailCommon): def setUp(self): """ In this setup we prepare 20 blacklist entries. We therefore add diff --git a/addons/test_mass_mailing/tests/test_performance.py b/addons/test_mass_mailing/tests/test_performance.py index 0c0c7b4bd34..d642d7d9e40 100644 --- a/addons/test_mass_mailing/tests/test_performance.py +++ b/addons/test_mass_mailing/tests/test_performance.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.addons.test_mail.tests.common import mail_new_test_user +from odoo.addons.mail.tests.common import mail_new_test_user from odoo.tests.common import TransactionCase, users, warmup from odoo.tests import tagged from odoo.tools import mute_logger |
