[ADD] mail: test for mass_mail mode sending mail with comments

This adds a test sending a mail with comments (MSO conditionals) in
mass_mail mode.

X-original-commit: 8778c10bc1856e57216785a8332b90878ff1b5ef
Part-of: odoo/odoo#80621
This commit is contained in:
Antoine Guenet
2021-12-08 09:35:03 +00:00
parent e4641a8e38
commit 0ba08b558b
2 changed files with 85 additions and 0 deletions
+1
View File
@@ -4,6 +4,7 @@
from . import test_mail_channel
from . import test_mail_channel_as_guest
from . import test_mail_channel_partner
from . import test_mail_composer
from . import test_mail_full_composer
from . import test_mail_render
from . import test_mail_template
+84
View File
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import users
from odoo.addons.mail.tests.common import MailCommon
class TestMailComposer(MailCommon):
@classmethod
def setUpClass(cls):
super(TestMailComposer, cls).setUpClass()
cls.env['ir.config_parameter'].set_param('mail.restrict.template.rendering', True)
cls.user_employee.groups_id -= cls.env.ref('mail.group_mail_template_editor')
cls.test_record = cls.env['res.partner'].with_context(cls._test_context).create({
'name': 'Test',
})
cls.body_html = """<div>
<h1>Hello sir!</h1>
<p>Here! <a href="https://www.example.com">
<!--[if mso]>
<i style="letter-spacing: 25px; mso-font-width: -100%; mso-text-raise: 30pt;">&nbsp;</i>
<![endif]-->
A link for you!
<!--[if mso]>
<i style="letter-spacing: 25px; mso-font-width: -100%;">&nbsp;</i>
<![endif]-->
</a> Make good use of it.</p>
</div>"""
cls.mail_template = cls.env['mail.template'].create({
'name': 'Test template with mso conditionals',
'subject': 'MSO FTW',
'body_html': cls.body_html,
'lang': '{{ object.lang }}',
'auto_delete': True,
'model_id': cls.env.ref('base.model_res_partner').id,
})
@users('employee')
def test_mail_mass_mode_template_with_mso(self):
mail_compose_message = self.env['mail.compose.message'].create({
'composition_mode': 'mass_mail',
'model': 'res.partner',
'template_id': self.mail_template.id,
'subject': 'MSO FTW',
})
values = mail_compose_message.get_mail_values(self.partner_employee.ids)
self.assertIn("""<div>
<h1>Hello sir!</h1>
<p>Here! <a href="https://www.example.com">
A link for you!
</a> Make good use of it.</p>
</div>""",
values[self.partner_employee.id]['body_html'],
'We must remove comments')
@users('employee')
def test_mail_mass_mode_compose_with_mso(self):
composer = self.env['mail.compose.message'].with_context({
'default_model': self.test_record._name,
'default_composition_mode': 'mass_mail',
'active_ids': [self.test_record.id],
'active_model': self.test_record._name,
'active_id': self.test_record.id
}).create({
'body': self.body_html,
'partner_ids': [(4, self.partner_employee.id)],
'composition_mode': 'mass_mail',
})
with self.mock_mail_gateway(mail_unlink_sent=True):
composer._action_send_mail()
values = composer.get_mail_values(self.partner_employee.ids)
self.assertIn("""<div>
<h1>Hello sir!</h1>
<p>Here! <a href="https://www.example.com">
A link for you!
</a> Make good use of it.</p>
</div>""",
values[self.partner_employee.id]['body_html'],
'We must remove comments')