From de6e980f59d6ddc13d7ea19a78b9ee5454e428d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 18 Dec 2019 13:57:38 +0000 Subject: [PATCH] [IMP] mail: slightly improve tool to call mail gateway in tests We now also support formatting a return path when emulating incoming emails. Purpose is to integrate some more tests in a near future about incoming emails, notably in CRM. This commit is a preliminary cleaning coming from task 2088565 about CRM onchange to compute methods update. LINKS Task ID 2088565 Community PR #42344 Enterprise PR odoo/enterprise#7403 --- addons/mail/tests/common.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/mail/tests/common.py b/addons/mail/tests/common.py index ece4cd2a4d1..5d445ffe374 100644 --- a/addons/mail/tests/common.py +++ b/addons/mail/tests/common.py @@ -102,17 +102,21 @@ class MockEmail(common.BaseCase): cls.mailer_daemon_email = formataddr(('MAILER-DAEMON', '%s@%s' % (cls.alias_bounce, cls.alias_domain))) def format(self, template, to='groups@example.com, other@gmail.com', subject='Frogs', - extra='', email_from='Sylvie Lelitre ', - cc='', msg_id='<1198923581.41972151344608186760.JavaMail@agrolait.com>'): - return template.format(to=to, subject=subject, cc=cc, extra=extra, email_from=email_from, msg_id=msg_id) + email_from='Sylvie Lelitre ', return_path='', cc='', + extra='', msg_id='<1198923581.41972151344608186760.JavaMail@agrolait.com>'): + return template.format( + subject=subject, to=to, cc=cc, + email_from=email_from, return_path=return_path, + extra=extra, msg_id=msg_id) - def format_and_process(self, template, email_from, to, subject='Frogs', extra='', cc='', msg_id=False, + def format_and_process(self, template, email_from, to, subject='Frogs', cc='', + return_path='', extra='', msg_id=False, model=None, target_model='mail.test.gateway', target_field='name'): self.assertFalse(self.env[target_model].search([(target_field, '=', subject)])) if not msg_id: msg_id = "<%.7f-test@iron.sky>" % (time.time()) - mail = self.format(template, to=to, subject=subject, cc=cc, extra=extra, email_from=email_from, msg_id=msg_id) + mail = self.format(template, to=to, subject=subject, cc=cc, return_path=return_path, extra=extra, email_from=email_from, msg_id=msg_id) self.env['mail.thread'].with_context(mail_channel_noautofollow=True).message_process(model, mail) return self.env[target_model].search([(target_field, '=', subject)])