[FIX] test_mass_mailing: add test for the send_mail_test action
This test ensures that when using the test sending tool of mass mailing (sms) a wrong jinja content is detected if we have any record available to evaluate it. PR odoo/odoo#55696 Task ID-2312442 X-original-commit: 183a7677616ac36ed06109e22288aacb185ac097
This commit is contained in:
committed by
Thibault Delavallée
parent
b971b417c5
commit
6bb907ed35
@@ -5,6 +5,7 @@
|
||||
from odoo.addons.phone_validation.tools import phone_validation
|
||||
from odoo.addons.test_mail_full.tests.common import TestMailFullCommon
|
||||
from odoo.tests import tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
@tagged('mass_mailing')
|
||||
@@ -147,3 +148,32 @@ class TestMassSMS(TestMailFullCommon):
|
||||
[{'partner': record.customer_id, 'number': self.records_numbers[i+5], 'content': 'Dear %s this is a mass SMS.' % record.display_name} for i, record in enumerate(self.records[5:])],
|
||||
self.mailing, self.records[5:], check_sms=True
|
||||
)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_render_mixin')
|
||||
def test_mass_sms_test_button(self):
|
||||
mailing = self.env['mailing.mailing'].create({
|
||||
'name': 'TestButton',
|
||||
'subject': 'Subject ${object.name}',
|
||||
'preview': 'Preview ${object.name}',
|
||||
'state': 'draft',
|
||||
'mailing_type': 'sms',
|
||||
'body_plaintext': 'Hello ${object.name}',
|
||||
'mailing_model_id': self.env['ir.model']._get('res.partner').id,
|
||||
})
|
||||
mailing_test = self.env['mailing.sms.test'].with_user(self.user_marketing).create({
|
||||
'numbers': '+32456001122',
|
||||
'mailing_id': mailing.id,
|
||||
})
|
||||
|
||||
with self.with_user('user_marketing'):
|
||||
with self.mockSMSGateway():
|
||||
mailing_test.action_send_sms()
|
||||
|
||||
# Test if bad jinja in the body raises an error
|
||||
mailing.write({
|
||||
'body_plaintext': 'Hello ${object.name_id.id}',
|
||||
})
|
||||
|
||||
with self.with_user('user_marketing'):
|
||||
with self.mock_mail_gateway(), self.assertRaises(Exception):
|
||||
mailing_test.action_send_sms()
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from odoo.addons.test_mass_mailing.tests.common import TestMassMailCommon
|
||||
from odoo.addons.test_mass_mailing.data.mail_test_data import MAIL_TEMPLATE
|
||||
from odoo.tests.common import users
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestMailingInternals(TestMassMailCommon):
|
||||
@@ -22,6 +23,46 @@ class TestMailingInternals(TestMassMailCommon):
|
||||
'alias_contact': 'everyone'
|
||||
})
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_render_mixin')
|
||||
def test_mailing_test_button(self):
|
||||
mailing = self.env['mailing.mailing'].create({
|
||||
'name': 'TestButton',
|
||||
'subject': 'Subject ${object.name}',
|
||||
'preview': 'Preview ${object.name}',
|
||||
'state': 'draft',
|
||||
'mailing_type': 'mail',
|
||||
'body_html': '<p>Hello ${object.name}</p>',
|
||||
'mailing_model_id': self.env['ir.model']._get('res.partner').id,
|
||||
})
|
||||
mailing_test = self.env['mailing.mailing.test'].create({
|
||||
'email_to': 'test@test.com',
|
||||
'mass_mailing_id': mailing.id,
|
||||
})
|
||||
|
||||
with self.mock_mail_gateway():
|
||||
mailing_test.send_mail_test()
|
||||
|
||||
# Test if bad jinja in the subject raises an error
|
||||
mailing.write({'subject': 'Subject ${object.name_id.id}'})
|
||||
with self.mock_mail_gateway(), self.assertRaises(Exception):
|
||||
mailing_test.send_mail_test()
|
||||
|
||||
# Test if bad jinja in the body raises an error
|
||||
mailing.write({
|
||||
'subject': 'Subject ${object.name}',
|
||||
'body_html': '<p>Hello ${object.name_id.id}</p>',
|
||||
})
|
||||
with self.mock_mail_gateway(), self.assertRaises(Exception):
|
||||
mailing_test.send_mail_test()
|
||||
|
||||
# Test if bad jinja in the preview raises an error
|
||||
mailing.write({
|
||||
'body_html': '<p>Hello ${object.name}</p>',
|
||||
'preview': 'Preview ${object.name_id.id}',
|
||||
})
|
||||
with self.mock_mail_gateway(), self.assertRaises(Exception):
|
||||
mailing_test.send_mail_test()
|
||||
|
||||
def test_mailing_trace_update(self):
|
||||
customers = self.env['res.partner']
|
||||
for x in range(0, 3):
|
||||
|
||||
Reference in New Issue
Block a user