[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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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>'})
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user