PURPOSE
Purpose is to have more tests when sending mail mailings, notably about
canceled or failed mails or sms as well as jinja and links rendering.
SPECIFICATIONS
In this commit we improve Email Marketing mailing tests. We notably
* add tests for void and invalid email and numbers. It allows to check they
correctly update their trace status;
* add tests for unsubscribe and view links embedded in mass mailing emails;
* add tests to simulate a click on links sent through mass mailing and
ensure click statistics are effectively updated;
* add tests to simulate bounce emails coming back to the mail gateway;
Default content of mailings used in test is updated to ensure jinja is
correctly rendered, including links and some corner cases. This will also
helps ensuring behavior is kept when converting to QWeb.
Various docstrings are added to helpers and custom asserts.
LINKS
Task ID-2508643
Followup of odoo/odoo#68874 (improve mail tests)
Prepares Task ID-27033 (support QWeb in templates)
Prepares Task ID-2377974 (clean trace and status management in mass mailing)
COM PR odoo/odoo#69461
ENT PR odoo/enterprise#17780
X-original-commit: 7b940ad46bde30f9bf16837f7bff5a70cd88c640
61 lines
2.7 KiB
Python
61 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.mass_mailing.tests.common import MassMailCommon
|
|
from odoo.addons.test_mail.tests.common import TestMailCommon
|
|
|
|
|
|
class TestMassMailCommon(MassMailCommon, TestMailCommon):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(TestMassMailCommon, cls).setUpClass()
|
|
|
|
# enforce last update by user_marketing to match _process_mass_mailing_queue
|
|
# taking last writer as user running a batch
|
|
cls.mailing_bl = cls.env['mailing.mailing'].with_user(cls.user_marketing).create({
|
|
'name': 'SourceName',
|
|
'subject': 'MailingSubject',
|
|
'preview': 'Hi ${object.name} :)',
|
|
'body_html': """<div><p>Hello ${object.name}</p>,
|
|
% set url = "www.odoo.com"
|
|
% set httpurl = "https://www.odoo.eu"
|
|
<span>Website0: <a id="url0" href="https://www.odoo.tz/my/${object.name}">https://www.odoo.tz/my/${object.name}</a></span>
|
|
<span>Website1: <a id="url1" href="https://www.odoo.be">https://www.odoo.be</a></span>
|
|
<span>Website2: <a id="url2" href="https://${url}">https://${url}</a></span>
|
|
<span>Website3: <a id="url3" href="${httpurl}">${httpurl}</a></span>
|
|
<span>External1: <a id="url4" href="https://www.example.com/foo/bar?baz=qux">Youpie</a></span>
|
|
<span>Internal1: <a id="url5" href="/event/dummy-event-0">Internal link</a></span>
|
|
<span>Internal2: <a id="url6" href="/view"/>View link</a></span>
|
|
<span>Email: <a id="url7" href="mailto:test@odoo.com">test@odoo.com</a></span>
|
|
<p>Stop spam ? <a id="url8" role="button" href="/unsubscribe_from_list">Ok</a></p>
|
|
</div>""",
|
|
'mailing_type': 'mail',
|
|
'mailing_model_id': cls.env['ir.model']._get('mailing.test.blacklist').id,
|
|
})
|
|
|
|
@classmethod
|
|
def _create_test_blacklist_records(cls, model='mailing.test.blacklist', count=1):
|
|
""" Deprecated, remove in 14.4 """
|
|
return cls.__create_mailing_test_records(model=model, count=count)
|
|
|
|
@classmethod
|
|
def _create_mailing_test_records(cls, model='mailing.test.blacklist', partners=None, count=1):
|
|
""" Helper to create data. Currently simple, to be improved. """
|
|
Model = cls.env[model]
|
|
email_field = 'email' if 'email' in Model else 'email_from'
|
|
partner_field = 'customer_id' if 'customer_id' in Model else 'partner_id'
|
|
|
|
vals_list = []
|
|
for x in range(0, count):
|
|
vals = {
|
|
'name': 'TestRecord_%02d' % x,
|
|
email_field: '"TestCustomer %02d" <test.record.%02d@test.example.com>' % (x, x),
|
|
}
|
|
if partners:
|
|
vals[partner_field] = partners[x % len(partners)]
|
|
|
|
vals_list.append(vals)
|
|
|
|
return cls.env[model].create(vals_list)
|