We adapted a test in mail in commit be21041f9aa385f2b9ce1b242379bf147c54b158. Basically, the test only contained mso comments and no regular comment. While the python code teats them the same, they are not semantically equivalent as mso comments actually do have side effects in outlook. The adaptation is to add a regular comment to the test data so that both comment types are properly covered by the test, even though the result is technically the same regardless. This is the only change from this commit that was not yet present in 15.2. closes odoo/odoo#84786 X-original-commit: 9275b0119ee6bb2e9a4ee5bef66b00e8c2456d3d Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
75 lines
2.8 KiB
Python
75 lines
2.8 KiB
Python
# -*- 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;"> </i>
|
|
<![endif]-->
|
|
A link for you! <!-- my favorite example -->
|
|
<!--[if mso]>
|
|
<i style="letter-spacing: 25px; mso-font-width: -100%;"> </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(self.body_html,
|
|
values[self.partner_employee.id]['body_html'],
|
|
'We must preserve (mso) comments in email html')
|
|
|
|
@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(self.body_html,
|
|
values[self.partner_employee.id]['body_html'],
|
|
'We must preserve (mso) comments in email html')
|