diff options
Diffstat (limited to 'addons/sms/tests/common.py')
| -rw-r--r-- | addons/sms/tests/common.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/addons/sms/tests/common.py b/addons/sms/tests/common.py index e90fcf9a384..901939d15c2 100644 --- a/addons/sms/tests/common.py +++ b/addons/sms/tests/common.py @@ -4,8 +4,9 @@ from contextlib import contextmanager from unittest.mock import patch from odoo import exceptions, tools -from odoo.addons.phone_validation.tools import phone_validation from odoo.tests import common +from odoo.addons.mail.tests.common import MailCommon +from odoo.addons.phone_validation.tools import phone_validation from odoo.addons.sms.models.sms_api import SmsApi @@ -13,11 +14,11 @@ class MockSMS(common.BaseCase): def tearDown(self): super(MockSMS, self).tearDown() - self._clear_sms_sent + self._clear_sms_sent() @contextmanager def mockSMSGateway(self, sim_error=None, nbr_t_error=None): - self._sms = [] + self._clear_sms_sent() def _contact_iap(local_endpoint, params): # mock single sms sending @@ -60,6 +61,11 @@ class MockSMS(common.BaseCase): def _clear_sms_sent(self): self._sms = [] + +class SMSCase(MockSMS): + """ Main test class to use when testing SMS integrations. Contains helpers and tools related + to notification sent by SMS. """ + def assertSMSSent(self, numbers, content): """ Check sent SMS. Order is not checked. Each number should have received the same content. Useful to check batch sending. @@ -180,3 +186,33 @@ class MockSMS(common.BaseCase): self.assertEqual(message.subtype_id, self.env.ref('mail.mt_note')) self.assertEqual(message.message_type, 'sms') self.assertEqual(tools.html2plaintext(message.body).rstrip('\n'), body) + + +class SMSCommon(MailCommon, MockSMS): + + @classmethod + def setUpClass(cls): + super(SMSCommon, 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.' + }) |
