[IMP] test_mail{..mailing/full}: backport tooling improvements
PURPOSE Purpose of this commit is to backport some improvements done in mail testing tools done in newer versions. Some of them are required for incoming tests to be added, other just to try to ease writing tests across versions. SPECIFICATIONS Partial backport of odoo/odoo@94208cb8b4 Improve finding outgoing mails and emails when batch methods (mass mailing) create similar emails, that can be distinguished notably by the subject in addition to from / to. Partial backport of odoo/odoo@c98f259736 Add a method to check MailMail, based on a given record. When having duplicates to differentiate in a given mailing, having just recipients is not sufficient as multiple emails may match a given recipients list. Checking model / res_id is another method for finding emails. Partial backport of odoo/odoo@a3e404e17e Add some information and values propagation in some custom asserts in mail test tooling. Partial backport of odoo/odoo@b915617569 Allow to return <mail.mail> records and found outgoing emails when using asserts. It eases doing checks in some specific tests e.g. checking notification layout usage in emails. Indeed this is quite low level and does not really deserves its own assert tooling methods. Partial backport of odoo/odoo@bbf4783ac6 Improve checks and asserts done when asserting content of produced mailing content (mails, traces, ...). Task-3438381 (TestMail: backport tools) Prepares Task-2612945 (Mail: Defensive email formatting) X-original-commit: 2bc28c804a92f206133c352c046dcdd4971fd4a6 Part-of: odoo/odoo#129839
This commit is contained in:
@@ -324,7 +324,7 @@ class MockEmail(common.BaseCase, MockSmtplibCase):
|
||||
|
||||
def _find_sent_email(self, email_from, emails_to, subject=None):
|
||||
""" Find an outgoing email based on from / to and optional subject when
|
||||
having conflicts.
|
||||
having a conflict.
|
||||
|
||||
:return sent_email: an outgoing email generated during the mock;
|
||||
"""
|
||||
|
||||
@@ -121,18 +121,29 @@ class MassMailCase(MailCase, MockLinkTracker):
|
||||
|
||||
# mail.mail specific values to check
|
||||
fields_values = {'mailing_id': mailing}
|
||||
if 'failure_reason' in recipient_info:
|
||||
fields_values['failure_reason'] = recipient_info['failure_reason']
|
||||
|
||||
# specific for partner: email_formatted is used
|
||||
if partner:
|
||||
if status == 'sent' and sent_unlink:
|
||||
self.assertSentEmail(author, [partner])
|
||||
else:
|
||||
self.assertMailMail(partner, state_mapping[status], author=author, content=content, fields_values=fields_values)
|
||||
self.assertMailMail(
|
||||
partner, state_mapping[status],
|
||||
author=author, content=content, fields_values=fields_values
|
||||
)
|
||||
# specific if email is False -> could have troubles finding it if several falsy traces
|
||||
elif not email and status in ('cancel', 'bounce'):
|
||||
self.assertMailMailWId(recipient_trace.mail_mail_id_int, state_mapping[status], author=author, content=content, fields_values=fields_values)
|
||||
self.assertMailMailWId(
|
||||
recipient_trace.mail_mail_id_int, state_mapping[status],
|
||||
author=author, content=content, fields_values=fields_values
|
||||
)
|
||||
else:
|
||||
self.assertMailMailWEmails([email], state_mapping[status], author=author, content=content, fields_values=fields_values)
|
||||
self.assertMailMailWEmails(
|
||||
[email], state_mapping[status],
|
||||
author=author, content=content, fields_values=fields_values
|
||||
)
|
||||
|
||||
if link_info:
|
||||
trace_mail = self._find_mail_mail_wrecord(record)
|
||||
|
||||
@@ -15,11 +15,13 @@ from odoo.addons.base.tests.test_ir_cron import CronMixinCase
|
||||
from odoo.addons.mass_mailing.tests.common import MassMailCommon
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.sql_db import Cursor
|
||||
from odoo.tests.common import users, Form
|
||||
from odoo.tests.common import users, Form, tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
BASE_64_STRING = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII='
|
||||
|
||||
|
||||
@tagged('mass_mailing')
|
||||
class TestMassMailValues(MassMailCommon):
|
||||
|
||||
@classmethod
|
||||
@@ -402,6 +404,7 @@ class TestMassMailValues(MassMailCommon):
|
||||
msg='The name must be unique')
|
||||
|
||||
|
||||
@tagged('mass_mailing')
|
||||
class TestMassMailFeatures(MassMailCommon, CronMixinCase):
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user