From 3ca98b127110c077feb732abc2240bc47da50521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 14 Jun 2022 13:37:12 +0000 Subject: [PATCH] [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 --- addons/mail/tests/common.py | 29 +++++++++++++++++++++++++++ addons/test_mail/tests/common.py | 34 ++++---------------------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/addons/mail/tests/common.py b/addons/mail/tests/common.py index c1e1f705649..71375b88dbe 100644 --- a/addons/mail/tests/common.py +++ b/addons/mail/tests/common.py @@ -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 diff --git a/addons/test_mail/tests/common.py b/addons/test_mail/tests/common.py index 88759108d48..e928cbb3203 100644 --- a/addons/test_mail/tests/common.py +++ b/addons/test_mail/tests/common.py @@ -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, })