From 044e253ac24001d968b366dd9e21d5d4e6ab67e1 Mon Sep 17 00:00:00 2001 From: std-odoo Date: Wed, 27 Apr 2022 06:36:42 +0000 Subject: [PATCH] [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) --- addons/mail/tests/common.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/addons/mail/tests/common.py b/addons/mail/tests/common.py index 6b659bcaca1..6e6172b3835 100644 --- a/addons/mail/tests/common.py +++ b/addons/mail/tests/common.py @@ -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.