[REF] test_mail: update test discuss / invite / ir actions / odoobot 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 tests to new tools / asserts / helpers / classes defined in mail
and test_mail. 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);
In this commit we update: test_discuss, test_invite, test_ir_actions and
test_odoobot.
LINKS
Task ID 2068986
PR #38070
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mail.tests.common import BaseFunctionalTest, TestRecipients, MockEmails
|
||||
from odoo.addons.test_mail.tests.common import TestMailCommon, TestRecipients
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestChatterTweaks(BaseFunctionalTest, TestRecipients):
|
||||
class TestChatterTweaks(TestMailCommon, TestRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -90,7 +90,7 @@ class TestChatterTweaks(BaseFunctionalTest, TestRecipients):
|
||||
self.assertTrue(record.name)
|
||||
|
||||
|
||||
class TestDiscuss(BaseFunctionalTest, TestRecipients, MockEmails):
|
||||
class TestDiscuss(TestMailCommon, TestRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -98,11 +98,13 @@ class TestDiscuss(BaseFunctionalTest, TestRecipients, MockEmails):
|
||||
cls.test_record = cls.env['mail.test.simple'].with_context(cls._test_context).create({'name': 'Test', 'email_from': 'ignasse@example.com'})
|
||||
|
||||
def test_set_message_done_user(self):
|
||||
with self.assertNotifications(partner_employee=(0, '', '')):
|
||||
with self.assertSinglePostNotifications([{'partner': self.partner_employee, 'type': 'inbox'}], message_info={'content': 'Test'}):
|
||||
message = self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.user_employee.partner_id.id])
|
||||
message.with_user(self.user_employee).set_message_done()
|
||||
message.with_user(self.user_employee).set_message_done()
|
||||
self.assertMailNotifications(message, [{'notif': [{'partner': self.partner_employee, 'type': 'inbox', 'is_read': True}]}])
|
||||
# TDE TODO: it seems bus notifications could be checked
|
||||
|
||||
def test_set_star(self):
|
||||
msg = self.test_record.with_user(self.user_admin).message_post(body='My Body', subject='1')
|
||||
|
||||
@@ -1,11 +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.addons.test_mail.tests.common import TestMailCommon
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestInvite(common.BaseFunctionalTest, common.MockEmails):
|
||||
class TestInvite(TestMailCommon):
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_invite_email(self):
|
||||
@@ -20,11 +20,14 @@ class TestInvite(common.BaseFunctionalTest, common.MockEmails):
|
||||
}).with_user(self.user_employee).create({
|
||||
'partner_ids': [(4, test_partner.id), (4, self.user_admin.partner_id.id)],
|
||||
'send_mail': True})
|
||||
mail_invite.add_followers()
|
||||
with self.mock_mail_gateway():
|
||||
mail_invite.add_followers()
|
||||
|
||||
# check added followers and that emails were sent
|
||||
self.assertEqual(test_record.message_partner_ids,
|
||||
test_partner | self.user_admin.partner_id)
|
||||
self.assertEqual(test_record.message_follower_ids.mapped('channel_id'),
|
||||
self.env['mail.channel'])
|
||||
self.assertSentEmail(self.partner_employee, [test_partner])
|
||||
self.assertSentEmail(self.partner_employee, [self.partner_admin])
|
||||
self.assertEqual(len(self._mails), 2)
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.base.tests.test_ir_actions import TestServerActionsBase
|
||||
from odoo.addons.test_mail.tests.common import BaseFunctionalTest
|
||||
from odoo.addons.test_mail.tests.common import TestMailCommon
|
||||
|
||||
|
||||
class TestServerActionsEmail(BaseFunctionalTest, TestServerActionsBase):
|
||||
class TestServerActionsEmail(TestMailCommon, TestServerActionsBase):
|
||||
|
||||
def test_action_email(self):
|
||||
email_template = self._create_template('res.partner', {'partner_to': '%s' % self.test_partner.id})
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo.addons.test_mail.tests.common import BaseFunctionalTest, MockEmails, TestRecipients
|
||||
from odoo.tools import mute_logger
|
||||
from odoo.addons.test_mail.tests.common import TestMailCommon, TestRecipients
|
||||
from odoo.tests import tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
@tagged("odoobot")
|
||||
class TestOdoobot(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
class TestOdoobot(TestMailCommon, TestRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
Reference in New Issue
Block a user