summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2021-04-26 12:38:49 +0000
committerThibault Delavallée <tde@odoo.com>2021-04-27 09:15:43 +0000
commitd08942c3ab80a8f573d38c02e8e8a10a1ede5433 (patch)
tree067ab49c28176b19ca639d744440fdb0eda08d02
parent99f9f6372b3bd18b6dc10b2ff181920dfe90ec80 (diff)
[IMP] test_mass_mailing: add tests for replies to mailings depending on update mode
Purpose of this commit is to add tests related to answers through mail gateway when having reply-to mode of mailing set to either updating existing threads (aka replying on mailed records), either creating new threads (aka using the reply-to alias configuration). Backport of odoo/odoo@4ef24369c813ec6a6ce997369aa454d9d67a992b done in master (14.4) LINKS Task ID-2117639 COM PR odoo/odoo#40931
-rw-r--r--addons/mail/tests/common.py31
-rw-r--r--addons/test_mass_mailing/tests/test_mailing.py54
2 files changed, 82 insertions, 3 deletions
diff --git a/addons/mail/tests/common.py b/addons/mail/tests/common.py
index 4a688535886..bbd685534d6 100644
--- a/addons/mail/tests/common.py
+++ b/addons/mail/tests/common.py
@@ -128,7 +128,8 @@ class MockEmail(common.BaseCase):
""" Deprecated, remove in 14.4 """
return self.gateway_mail_reply_wrecord(template, record, use_in_reply_to=use_in_reply_to)
- def gateway_mail_reply_wrecord(self, template, record, use_in_reply_to=True):
+ def gateway_mail_reply_wrecord(self, template, record, use_in_reply_to=True,
+ target_model=None, target_field=None):
""" Simulate a reply through the mail gateway. Usage: giving a record,
find an email sent to him and use its message-ID to simulate a reply.
@@ -148,8 +149,32 @@ class MockEmail(common.BaseCase):
subject='Re: %s' % mail_mail.subject,
extra=extra,
msg_id='<123456.%s.%d@test.example.com>' % (record._name, record.id),
- target_model=record._name,
- target_field=record._rec_name,
+ target_model=target_model or record._name,
+ target_field=target_field or record._rec_name,
+ )
+
+ def gateway_mail_reply_wemail(self, template, email_to, use_in_reply_to=True,
+ target_model=None, target_field=None):
+ """ Simulate a reply through the mail gateway. Usage: giving a record,
+ find an email sent to him and use its message-ID to simulate a reply.
+
+ Some noise is added in References just to test some robustness. """
+ sent_mail = self._find_sent_mail_wemail(email_to)
+
+ if use_in_reply_to:
+ extra = 'In-Reply-To:\r\n\t%s\n' % sent_mail['message_id']
+ else:
+ disturbing_other_msg_id = '<123456.654321@another.host.com>'
+ extra = 'References:\r\n\t%s\n\r%s' % (sent_mail['message_id'], disturbing_other_msg_id)
+
+ return self.format_and_process(
+ template,
+ sent_mail['email_to'],
+ sent_mail['reply_to'],
+ subject='Re: %s' % sent_mail['subject'],
+ extra=extra,
+ target_model=target_model,
+ target_field=target_field or 'name',
)
def from_string(self, text):
diff --git a/addons/test_mass_mailing/tests/test_mailing.py b/addons/test_mass_mailing/tests/test_mailing.py
index 4179327de94..c5a90927df5 100644
--- a/addons/test_mass_mailing/tests/test_mailing.py
+++ b/addons/test_mass_mailing/tests/test_mailing.py
@@ -120,6 +120,60 @@ class TestMassMailing(TestMassMailCommon):
self.assertEqual(recipients[1].message_bounce, 1)
@users('user_marketing')
+ @mute_logger('odoo.addons.mail.models.mail_mail')
+ def test_mailing_reply_to_mode_new(self):
+ mailing = self.env['mailing.mailing'].browse(self.mailing_bl.ids)
+ recipients = self._create_mailing_test_records(model='mailing.test.blacklist', count=5)
+ self.assertEqual(len(recipients), 5)
+ initial_messages = recipients.message_ids
+ mailing.write({
+ 'mailing_domain': [('id', 'in', recipients.ids)],
+ 'keep_archives': False,
+ 'reply_to_mode': 'email',
+ 'reply_to': self.test_alias.display_name,
+ })
+
+ with self.mock_mail_gateway(mail_unlink_sent=True):
+ mailing.action_send_mail()
+
+ answer_rec = self.gateway_mail_reply_wemail(MAIL_TEMPLATE, recipients[0].email_normalized, target_model=self.test_alias.alias_model_id.model)
+ self.assertTrue(bool(answer_rec))
+ self.assertEqual(answer_rec.name, 'Re: %s' % mailing.subject)
+ self.assertEqual(
+ answer_rec.message_ids.subject, 'Re: %s' % mailing.subject,
+ 'Answer should be logged')
+ self.assertEqual(recipients.message_ids, initial_messages)
+
+ self.assertMailingStatistics(mailing, expected=5, delivered=5, sent=5, opened=1, replied=1)
+
+ @users('user_marketing')
+ @mute_logger('odoo.addons.mail.models.mail_mail')
+ def test_mailing_reply_to_mode_update(self):
+ mailing = self.env['mailing.mailing'].browse(self.mailing_bl.ids)
+ recipients = self._create_mailing_test_records(model='mailing.test.blacklist', count=5)
+ self.assertEqual(len(recipients), 5)
+ mailing.write({
+ 'mailing_domain': [('id', 'in', recipients.ids)],
+ 'keep_archives': False,
+ 'reply_to_mode': 'thread',
+ 'reply_to': self.test_alias.display_name,
+ })
+
+ with self.mock_mail_gateway(mail_unlink_sent=True):
+ mailing.action_send_mail()
+
+ answer_rec = self.gateway_mail_reply_wemail(MAIL_TEMPLATE, recipients[0].email_normalized, target_model=self.test_alias.alias_model_id.model)
+ self.assertFalse(bool(answer_rec))
+ self.assertEqual(
+ recipients[0].message_ids[1].subject, mailing.subject,
+ 'Should have keep a log (to enable thread-based answer)')
+ self.assertEqual(
+ recipients[0].message_ids[0].subject, 'Re: %s' % mailing.subject,
+ 'Answer should be logged')
+
+ self.assertMailingStatistics(mailing, expected=5, delivered=5, sent=5, opened=1, replied=1)
+
+ @users('user_marketing')
@mute_logger('odoo.addons.mail.models.mail_thread')
def test_mailing_trace_utm(self):
""" Test mailing UTMs are caught on reply"""