[FIX] mail: fix assertMailNotifications when called in batch

Bug
===
When we called assertMailNotifications in batch, with different
notification status, it might raise an error when it shouldn't.

The reason for that is we check that no mail at all are created, for
the entire batch instead of filtering on the related partner.

`assertNoMail` should only check if no mail are created for the partner
it receive in arguments.

Task-2782150

closes odoo/odoo#89965

X-original-commit: 91be8b1eb2c3592029987524942ae2864988a7d3
Related: odoo/enterprise#26718
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
std-odoo
2022-04-28 12:40:40 +02:00
parent 7bdb8cc784
commit 044e253ac2
+25 -4
View File
@@ -428,11 +428,32 @@ class MockEmail(common.BaseCase, MockSmtplibCase):
else:
raise AssertionError('mail.mail exists for message %s / recipients %s but should not exist' % (mail_message, recipients.ids))
finally:
self.assertNotSentEmail()
self.assertNotSentEmail(recipients)
def assertNotSentEmail(self):
""" Check no email was generated during gateway mock. """
self.assertEqual(len(self._mails), 0)
def assertNotSentEmail(self, recipients=None):
"""Check no email was generated during gateway mock.
:param recipients:
List of partner for which we will check that no email have been sent
Or list of email address
If None, we will check that no email at all have been sent
"""
if recipients is None:
mails = self._mails
else:
all_emails = [
email_to.email if isinstance(email_to, self.env['res.partner'].__class__)
else email_to
for email_to in recipients
]
mails = [
mail
for mail in self._mails
if any(email in all_emails for email in mail['email_to'])
]
self.assertEqual(len(mails), 0)
def assertSentEmail(self, author, recipients, **values):
""" Tool method to ease the check of send emails.