From 46a6aed1c9bfce0527569b5ab5a049887fc476c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 11 Oct 2019 15:21:21 +0000 Subject: [PATCH] [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 --- addons/test_mail/tests/test_discuss.py | 12 +++++++----- addons/test_mail/tests/test_invite.py | 9 ++++++--- addons/test_mail/tests/test_ir_actions.py | 4 ++-- addons/test_mail/tests/test_odoobot.py | 6 +++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/addons/test_mail/tests/test_discuss.py b/addons/test_mail/tests/test_discuss.py index f4fb89a209e..5667568ead0 100644 --- a/addons/test_mail/tests/test_discuss.py +++ b/addons/test_mail/tests/test_discuss.py @@ -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') diff --git a/addons/test_mail/tests/test_invite.py b/addons/test_mail/tests/test_invite.py index 841a980a517..c4e91a86173 100644 --- a/addons/test_mail/tests/test_invite.py +++ b/addons/test_mail/tests/test_invite.py @@ -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) diff --git a/addons/test_mail/tests/test_ir_actions.py b/addons/test_mail/tests/test_ir_actions.py index 52a65232985..6a547081a15 100644 --- a/addons/test_mail/tests/test_ir_actions.py +++ b/addons/test_mail/tests/test_ir_actions.py @@ -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}) diff --git a/addons/test_mail/tests/test_odoobot.py b/addons/test_mail/tests/test_odoobot.py index c8d00b31223..7766b5244dc 100644 --- a/addons/test_mail/tests/test_odoobot.py +++ b/addons/test_mail/tests/test_odoobot.py @@ -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):