Skip to content

Commit

Permalink
[REF] test_mail: update test followers / template / mail mail to new …
Browse files Browse the repository at this point in the history
…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_mail_followers, test_mail_mail,
test_mail_template.

LINKS

Task ID 2068986
PR #38070
  • Loading branch information
tde-banana-odoo committed Nov 20, 2019
1 parent 46a6aed commit 25d4887
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions addons/test_mail/tests/test_mail_followers.py
Expand Up @@ -3,11 +3,11 @@

from psycopg2 import IntegrityError

from odoo.addons.test_mail.tests import common
from odoo.addons.test_mail.tests.common import TestMailCommon
from odoo.tools.misc import mute_logger


class BaseFollowersTest(common.BaseFunctionalTest):
class BaseFollowersTest(TestMailCommon):

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_followers_no_DID(self):
})


class AdvancedFollowersTest(common.BaseFunctionalTest):
class AdvancedFollowersTest(TestMailCommon):
@classmethod
def setUpClass(cls):
super(AdvancedFollowersTest, cls).setUpClass()
Expand Down
19 changes: 8 additions & 11 deletions addons/test_mail/tests/test_mail_mail.py
@@ -1,33 +1,30 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import itertools
import psycopg2

from odoo import api
from odoo.addons.base.models.ir_mail_server import MailDeliveryException
from odoo.addons.test_mail.tests import common as mail_common
from odoo.addons.test_mail.tests.common import TestMailCommon
from odoo.tests import common
from odoo.tools import mute_logger


class TestMail(mail_common.BaseFunctionalTest, mail_common.MockEmails):
class TestMailMail(TestMailCommon):

@mute_logger('odoo.addons.mail.models.mail_mail')
def test_mail_message_notify_from_mail_mail(self):
# Due ot post-commit hooks, store send emails in every step
self.email_to_list = []
# self.email_to_list = []
mail = self.env['mail.mail'].create({
'body_html': '<p>Test</p>',
'email_to': 'test@example.com',
'partner_ids': [(4, self.user_employee.partner_id.id)]
})
self.email_to_list.extend(itertools.chain.from_iterable(sent_email['email_to'] for sent_email in self._mails if sent_email.get('email_to')))
self.assertNotIn(u'Ernest Employee <e.e@example.com>', self.email_to_list)
mail.send()
self.email_to_list.extend(itertools.chain.from_iterable(sent_email['email_to'] for sent_email in self._mails if sent_email.get('email_to')))
self.assertNotIn(u'Ernest Employee <e.e@example.com>', self.email_to_list)
self.assertIn(u'test@example.com', self.email_to_list)
with self.mock_mail_gateway():
mail.send()
self.assertSentEmail(mail.env.user.partner_id, ['test@example.com'])
self.assertEqual(len(self._mails), 1)

@mute_logger('odoo.addons.mail.models.mail_mail')
def test_mail_message_values_unicode(self):
Expand All @@ -40,7 +37,7 @@ def test_mail_message_values_unicode(self):
self.assertRaises(MailDeliveryException, lambda: mail.send(raise_exception=True))


class TestMailRace(common.TransactionCase, mail_common.MockEmails):
class TestMailMailRace(common.TransactionCase):

@mute_logger('odoo.addons.mail.models.mail_mail')
def test_mail_bounce_during_send(self):
Expand Down
4 changes: 2 additions & 2 deletions addons/test_mail/tests/test_mail_template.py
Expand Up @@ -3,11 +3,11 @@

import base64

from odoo.addons.test_mail.tests.common import BaseFunctionalTest, MockEmails, TestRecipients
from odoo.addons.test_mail.tests.common import TestMailCommon, TestRecipients
from odoo.tools import mute_logger


class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients):
class TestMailTemplate(TestMailCommon, TestRecipients):

@classmethod
def setUpClass(cls):
Expand Down

0 comments on commit 25d4887

Please sign in to comment.