[IMP] (test_)mail: move some tools directly to mail test class

TestMail holds a tool to create test records in batch, notably with inline
partner creation. Allow its usage in some sub modules and tests depending
directly from the base mail test class. This allows notably usage of this
tool in performance tests (see enterprise PR).

Also explicitly set some test data to ease sub tests writing.

Prepares Task-2150462 (Mass Mailing: Unsubscribe flow improvement)

Part-of: odoo/odoo#94660
This commit is contained in:
Thibault Delavallée
2022-06-27 16:25:54 +02:00
parent 8cbac0506c
commit 3ca98b1271
2 changed files with 33 additions and 30 deletions
+29
View File
@@ -991,6 +991,35 @@ class MailCommon(common.TransactionCase, MailCase):
cls.partner_portal = cls.user_portal.partner_id
return cls.user_portal
@classmethod
def _create_records_for_batch(cls, model, count, additional_values=None):
additional_values = additional_values or {}
records = cls.env[model]
partners = cls.env['res.partner']
country_id = cls.env.ref('base.be').id
base_values = [
{'name': 'Test_%s' % idx,
**additional_values,
} for idx in range(count)
]
if 'customer_id' in cls.env[model]:
partners = cls.env['res.partner'].with_context(**cls._test_context).create([{
'name': 'Partner_%s' % idx,
'email': '_test_partner_%s@example.com' % idx,
'country_id': country_id,
'mobile': '047500%02d%02d' % (idx, idx)
} for idx in range(count)])
for values, partner in zip(base_values, partners):
values['customer_id'] = partner.id
records = cls.env[model].with_context(**cls._test_context).create(base_values)
cls.records = cls._reset_mail_context(records)
cls.partners = partners
return cls.records, cls.partners
@classmethod
def _activate_multi_company(cls):
""" Create another company, add it to admin and create an user that
+4 -30
View File
@@ -6,36 +6,8 @@ from odoo.tests.common import TransactionCase
class TestMailCommon(MailCommon):
""" Main entry point for functional tests. """
@classmethod
def _create_records_for_batch(cls, model, count, additional_values=None):
additional_values = additional_values or {}
records = cls.env[model]
partners = cls.env['res.partner']
country_id = cls.env.ref('base.be').id
base_values = [
{'name': 'Test_%s' % idx,
**additional_values,
} for idx in range(count)
]
if 'customer_id' in cls.env[model]:
partners = cls.env['res.partner'].with_context(**cls._test_context).create([{
'name': 'Partner_%s' % idx,
'email': '_test_partner_%s@example.com' % idx,
'country_id': country_id,
'mobile': '047500%02d%02d' % (idx, idx)
} for idx in range(count)])
for values, partner in zip(base_values, partners):
values['customer_id'] = partner.id
records = cls.env[model].with_context(**cls._test_context).create(base_values)
cls.records = cls._reset_mail_context(records)
cls.partners = partners
return cls.records, cls.partners
""" Main entry point for functional tests. Kept to ease backward
compatibility. """
class TestRecipients(TransactionCase):
@@ -54,10 +26,12 @@ class TestRecipients(TransactionCase):
'email': 'valid.lelitre@agrolait.com',
'country_id': cls.env.ref('base.be').id,
'mobile': '0456001122',
'phone': False,
})
cls.partner_2 = Partner.create({
'name': 'Valid Poilvache',
'email': 'valid.other@gmail.com',
'country_id': cls.env.ref('base.be').id,
'mobile': '+32 456 22 11 00',
'phone': False,
})