Files
odoo_source/addons/test_mail_full/tests/common.py
T
Thibault Delavallée fa46590ed2 [REF] test_mail_full: update module to new common
PURPOSE

Currently tools and asserts for mail tests are located inside test_mail
module. It makes difficult to re-use them in apps tests or force them to
write custom quick and dirty tools and asserts.

SPECIFICATIONS

Update this module to new tools / asserts / helpers / classes defined in mail
and test_mail.

In this commit we remove the ``BaseFunctionalTest`` and replace it by a fresh
``TestSMSCommon`` that is the combination of ``TestMailCommon`` from mail and
mass mailing with SMS mocks capabilities. That way all mocks and asserts are
available in all sub test classes.

``MassSMSBaseFunctionalTest`` is not necessary anymore as everything is
available directly with ``TestSMSCommon``.

Coming from common update, we have notably

  * ``BaseFunctionalTest`` class is replaced by the new ``TestMailCommon``
    pimped one;
  * ``assertNotifications`` is replaced by ``assertSinglePostNotifications``
    (shortcut for a simple message_post) or ``assertPostNotifications``
    (complete asserts involving several messages and notifications);
  * correctly invoke ``mock_mail_gateway`` when mocking email sending;
  * replace manual check of sent emails or ``assertEmails`` by
    ``assertSentEmails``;
  * remove custom mocks / checks and replace them by now standard mocks
    and assertions (if any);

LINKS

Task ID 2068986
PR #38070
2019-11-20 16:01:08 +00:00

67 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
from odoo.addons.phone_validation.tools import phone_validation
from odoo.addons.mass_mailing_sms.tests import common as mass_mailing_sms_common
from odoo.addons.test_mail.tests import common as test_mail_common
from odoo.addons.test_mass_mailing.tests import common as test_mass_mailing_common
class TestSMSCommon(test_mass_mailing_common.TestMailCommon, mass_mailing_sms_common.MockSMS):
@classmethod
def setUpClass(cls):
super(TestSMSCommon, cls).setUpClass()
cls.user_employee.write({'login': 'employee'})
# update country to belgium in order to test sanitization of numbers
cls.user_employee.company_id.write({'country_id': cls.env.ref('base.be').id})
# some numbers for testing
cls.random_numbers_str = '+32456998877, 0456665544'
cls.random_numbers = cls.random_numbers_str.split(', ')
cls.random_numbers_san = [phone_validation.phone_format(number, 'BE', '32', force_format='E164') for number in cls.random_numbers]
cls.test_numbers = ['+32456010203', '0456 04 05 06', '0032456070809']
cls.test_numbers_san = [phone_validation.phone_format(number, 'BE', '32', force_format='E164') for number in cls.test_numbers]
# some numbers for mass testing
cls.mass_numbers = ['04561%s2%s3%s' % (x, x, x) for x in range(0, 10)]
cls.mass_numbers_san = [phone_validation.phone_format(number, 'BE', '32', force_format='E164') for number in cls.mass_numbers]
@classmethod
def _create_sms_template(cls, model, body=False):
return cls.env['sms.template'].create({
'name': 'Test Template',
'model_id': cls.env['ir.model']._get(model).id,
'body': body if body else 'Dear ${object.display_name} this is an SMS.'
})
@classmethod
def _create_records_for_batch(cls, model, count):
records = cls.env['mail.test.sms']
partners = cls.env['res.partner']
country_id = cls.env.ref('base.be').id,
for x in range(count):
partners += cls.env['res.partner'].with_context(**cls._test_context).create({
'name': 'Partner_%s' % (x),
'email': '_test_partner_%s@example.com' % (x),
'country_id': country_id,
'mobile': '047500%02d%02d' % (x, x)
})
records += cls.env[model].with_context(**cls._test_context).create({
'name': 'Test_%s' % (x),
'customer_id': partners[x].id,
})
cls.records = cls._reset_mail_context(records)
cls.partners = partners
class TestRecipients(test_mail_common.TestRecipients):
@classmethod
def setUpClass(cls):
super(TestRecipients, cls).setUpClass()
cls.partner_numbers = [
phone_validation.phone_format(partner.mobile, partner.country_id.code, partner.country_id.phone_code, force_format='E164')
for partner in (cls.partner_1 | cls.partner_2)
]