Files
odoo_source/addons/test_mass_mailing/tests/common.py
T
Thibault Delavallée 7946b42ef5 [IMP] link_tracker, (test_)mass_mailing: improve test tools and clean existing tests
URPOSE

Prepare code cleaning and optimization in mail, mass_mailing and SMS by
cleaning models for readability and code complexity and footprint reduction.

SPECIFICATIONS

Add tool methods and asserts for link tracker tests.

Add tool methods and assets for mass mailing tests, notably about mailing
traces and their link with emails.

Merge existing and duplicated tests and rewrite them a bit.

Rename and improve test_mass_mailing models.

LINKS

Prepares task ID 2238597 (notification and trace models cleaning)
Task ID 1906925 (mass mailing tests cleaning)
PR #50169

Related: odoo/enterprise#10180
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-04-24 15:35:43 +00:00

54 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import datetime
import random
from odoo.addons.mass_mailing.tests.common import TestMassMailCommon
from odoo.addons.test_mail.tests.common import TestMailCommon
class TestMassMailCommon(TestMassMailCommon, TestMailCommon):
@classmethod
def setUpClass(cls):
super(TestMassMailCommon, cls).setUpClass()
cls.mailing_bl = cls.env['mailing.mailing'].create({
'name': 'SourceName',
'subject': 'MailingSubject',
'body_html': '<p>Hello ${object.name}</p>',
'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):
""" Helper to create data. Currently simple, to be improved. """
records = cls.env[model].create([{
'name': 'TestRecord_%02d' % x,
'email_from': '"TestCustomer %02d" <test.record.%02d@test.example.com>' % (x, x),
} for x in range(0, count)])
return records
@classmethod
def _create_bounce_trace(cls, record, dt=None):
if dt is None:
dt = datetime.datetime.now() - datetime.timedelta(days=1)
randomized = random.random()
if 'email_normalized' in record:
trace_email = record.email_normalized
elif 'email_from' in record:
trace_email = record.email_from
else:
trace_email = record.email
trace = cls.env['mailing.trace'].create({
'model': record._name,
'res_id': record.id,
'bounced': dt,
# TDE FIXME: improve this with a mail-enabled heuristics
'email': trace_email,
'message_id': '<%5f@gilbert.boitempomils>' % randomized,
})
return trace