mirror of
https://github.com/bringout/oca-ocb-mail.git
synced 2026-04-21 03:21:59 +02:00
19.0 vanilla
This commit is contained in:
parent
5df8c07b59
commit
daa394e8b0
2114 changed files with 564841 additions and 299642 deletions
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
from . import test_mail_thread_phone
|
||||
from . import test_phone_blacklist
|
||||
from . import test_phone_format
|
||||
from . import test_sms_composer
|
||||
from . import test_sms_controller
|
||||
from . import test_sms_management
|
||||
from . import test_sms_mixin
|
||||
from . import test_sms_performance
|
||||
|
|
|
|||
|
|
@ -2,13 +2,7 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.phone_validation.tools import phone_validation
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.test_mail.tests.common import TestMailCommon, TestRecipients
|
||||
|
||||
|
||||
class TestSMSCommon(SMSCommon, TestMailCommon):
|
||||
""" Main entry point for functional tests. Kept to ease backward
|
||||
compatibility and updating common. """
|
||||
from odoo.addons.test_mail.tests.common import TestRecipients
|
||||
|
||||
|
||||
class TestSMSRecipients(TestRecipients):
|
||||
|
|
@ -17,6 +11,6 @@ class TestSMSRecipients(TestRecipients):
|
|||
def setUpClass(cls):
|
||||
super(TestSMSRecipients, cls).setUpClass()
|
||||
cls.partner_numbers = [
|
||||
phone_validation.phone_format(partner.mobile, partner.country_id.code, partner.country_id.phone_code, force_format='E164')
|
||||
phone_validation.phone_format(partner.phone, partner.country_id.code, partner.country_id.phone_code, force_format='E164')
|
||||
for partner in (cls.partner_1 | cls.partner_2)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
|
||||
from odoo.tests import tagged, users
|
||||
|
||||
|
||||
@tagged('mail_thread')
|
||||
class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
||||
class TestSMSActionsCommon(SMSCommon, TestSMSRecipients):
|
||||
""" Test mail.thread.phone mixin, its tools and API """
|
||||
|
||||
@classmethod
|
||||
|
|
@ -30,20 +31,43 @@ class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
|||
'phone_nbr': False,
|
||||
'mobile_nbr': False,
|
||||
},
|
||||
# duplicated of 0606
|
||||
{
|
||||
'phone_nbr': '0475110606',
|
||||
'mobile_nbr': False,
|
||||
}, {
|
||||
'phone_nbr': False,
|
||||
'mobile_nbr': '0475110606',
|
||||
}
|
||||
])
|
||||
cls.void_record = cls.test_phone_records[-3]
|
||||
cls.dupes = cls.test_phone_records[-2:]
|
||||
|
||||
def test_initial_data(self):
|
||||
""" Test initial data for this class, allowing to be sure of I/O of tests. """
|
||||
self.assertEqual(
|
||||
self.test_phone_records.mapped('mobile_nbr'),
|
||||
['0475000000', '0475000101', '0475000202', '0475000303', '0475000404',
|
||||
'+32475000505', '0032475000606',
|
||||
False, False,
|
||||
[
|
||||
False, False, False, False, False,
|
||||
'+32475000505', '0032475000606', False, False,
|
||||
False, '0475110606',
|
||||
]
|
||||
)
|
||||
self.assertEqual(
|
||||
self.test_phone_records.mapped('phone_nbr'),
|
||||
[False] * 5 + ['+32475110505', '0032475110606', '0032475110707', False]
|
||||
[
|
||||
'0475000000', '0475000101', '0475000202', '0475000303',
|
||||
'0475000404', '+32475110505', '0032475110606', '0032475110707',
|
||||
False, '0475110606', False,
|
||||
]
|
||||
)
|
||||
self.assertEqual(
|
||||
self.test_phone_records.mapped('phone_sanitized'),
|
||||
[
|
||||
'+32475000000', '+32475000101', '+32475000202', '+32475000303',
|
||||
'+32475000404', '+32475110505', '+32475110606', '+32475110707',
|
||||
False, '+32475110606', '+32475110606',
|
||||
],
|
||||
)
|
||||
|
||||
@users('employee')
|
||||
|
|
@ -54,19 +78,19 @@ class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
|||
for test_values in [False, '', ' ']:
|
||||
# test is not set -> both fields should be not set
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '=', test_values)])
|
||||
self.assertEqual(results, test_phone_records[-1],
|
||||
self.assertEqual(results, self.void_record,
|
||||
'Search on phone_mobile_search: = False: record with two void values')
|
||||
# test is set -> at least one field should be set
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '!=', test_values)])
|
||||
self.assertEqual(results, test_phone_records[:-1],
|
||||
self.assertEqual(results, test_phone_records - self.void_record,
|
||||
'Search on phone_mobile_search: != False: record at least one value set')
|
||||
|
||||
# test Truthy -> is set / is not set
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '=', True)])
|
||||
self.assertEqual(results, test_phone_records[:-1],
|
||||
self.assertEqual(results, test_phone_records - self.void_record,
|
||||
'Search on phone_mobile_search: = True: record at least one value set')
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '!=', True)])
|
||||
self.assertEqual(results, test_phone_records[-1],
|
||||
self.assertEqual(results, self.void_record,
|
||||
'Search on phone_mobile_search: != True: record with two void values')
|
||||
|
||||
@users('employee')
|
||||
|
|
@ -74,15 +98,22 @@ class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
|||
""" Test searching by phone/mobile with direct search """
|
||||
test_phone_records = self.test_phone_records.with_env(self.env)
|
||||
|
||||
# test "=" search
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '=', '0475')])
|
||||
self.assertFalse(results, 'Search on phone_mobile_search: = should return only matching results')
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '=', '0475000000')])
|
||||
self.assertEqual(results, test_phone_records[0])
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '=', '0032475110606')])
|
||||
self.assertEqual(results, test_phone_records[6])
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '=', '+32475110606')])
|
||||
self.assertEqual(results, test_phone_records[6])
|
||||
for user_country in (self.env.ref("base.be"), self.env.ref("base.us")):
|
||||
self.env.user.sudo().country_id = user_country.id
|
||||
# test "=" search
|
||||
for source, expected in [
|
||||
('0475', self.env['mail.test.sms.bl']), # incomplete -> no results on "="
|
||||
# complete national number
|
||||
('0475000000', test_phone_records[0]),
|
||||
# various international numbers
|
||||
# ('32475110606', test_phone_records[6]), # currently not supported, returns nothing
|
||||
('0032475110606', test_phone_records[6]),
|
||||
('+32475110606', test_phone_records[6]),
|
||||
('+32 475 11 06 06', test_phone_records[6]),
|
||||
]:
|
||||
with self.subTest(source=source):
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', '=', source)])
|
||||
self.assertEqual(results, expected)
|
||||
|
||||
@users('employee')
|
||||
def test_search_phone_mobile_search_ilike(self):
|
||||
|
|
@ -90,21 +121,22 @@ class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
|||
test_phone_records = self.test_phone_records.with_env(self.env)
|
||||
|
||||
# test ilike search
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', 'ilike', '0475')])
|
||||
self.assertEqual(results, test_phone_records[:5])
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', 'ilike', '101')])
|
||||
self.assertEqual(results, test_phone_records[1])
|
||||
for source, ilike_expected, notilike_expected in [
|
||||
(
|
||||
'0475', test_phone_records[:5] + self.dupes,
|
||||
test_phone_records - test_phone_records[:5] - self.dupes
|
||||
),
|
||||
('101', test_phone_records[1], test_phone_records - test_phone_records[1]),
|
||||
# not ilike is not the inverse with formatting but hey, that's not easy to do
|
||||
('+32475', test_phone_records[5:8], test_phone_records),
|
||||
('0032475', test_phone_records[5:8], test_phone_records),
|
||||
]:
|
||||
# test ilike search
|
||||
with self.subTest(source=source, operator="ilike"):
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', 'ilike', source)])
|
||||
self.assertEqual(results, ilike_expected)
|
||||
|
||||
# test search using +32/0032
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', 'ilike', '+32475')])
|
||||
self.assertEqual(results, test_phone_records[5:8],
|
||||
'Search on phone_mobile_search: +32/0032 likeliness')
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', 'ilike', '0032475')])
|
||||
self.assertEqual(results, test_phone_records[5:8],
|
||||
'Search on phone_mobile_search: +32/0032 likeliness')
|
||||
|
||||
# test inverse ilike search
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', 'not ilike', '0475')])
|
||||
self.assertEqual(results, test_phone_records - test_phone_records[:5])
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', 'not ilike', '101')])
|
||||
self.assertEqual(results, test_phone_records - test_phone_records[1])
|
||||
# test inverse ilike search: should be the complement
|
||||
with self.subTest(source=source, operator="not ilike"):
|
||||
results = self.env['mail.test.sms.bl'].search([('phone_mobile_search', 'not ilike', source)])
|
||||
self.assertEqual(results, notilike_expected)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
|
||||
|
||||
|
||||
class TestPhoneBlacklist(TestSMSCommon, TestSMSRecipients):
|
||||
class TestPhoneBlacklist(SMSCommon, TestSMSRecipients):
|
||||
""" Test phone blacklist management """
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
from odoo.tests import tagged
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
@tagged('phone_validation')
|
||||
class TestPhoneFormat(TransactionCase):
|
||||
|
||||
def test_phone_format_country_guess(self):
|
||||
# based on partner country
|
||||
partners = self.env['res.partner'].create([
|
||||
{'name': 'Alex Bell', 'country_id': self.env.ref('base.us').id},
|
||||
{'name': 'Elie Grey', 'country_id': self.env.ref('base.uk').id},
|
||||
])
|
||||
test_record = self.env['mail.test.sms'].create({
|
||||
'country_id': False,
|
||||
'name': 'Record for Context',
|
||||
'customer_id': False,
|
||||
})
|
||||
base_partner_vals = [
|
||||
{'country_id': self.env.ref('base.us').id},
|
||||
{'country_id': self.env.ref('base.uk').id},
|
||||
]
|
||||
base_record_vals = {
|
||||
'country_id': False,
|
||||
'customer_id': False,
|
||||
'guest_ids': False,
|
||||
}
|
||||
partner_vals_all = [({}, {}), ({}, {}), ({'country_id': False}, {}), ({}, {'country_id': False}), ({}, {})]
|
||||
record_vals_all = [
|
||||
{'customer_id': partners[0].id}, {'guest_ids': partners}, {'guest_ids': partners},
|
||||
{'country_id': partners[1].country_id.id, 'customer_id': partners[1].id},
|
||||
{'country_id': partners[1].country_id.id},
|
||||
]
|
||||
input_numbers = ['251 842 8701', '251 842 8701', '078 9216 4126', '078 9216 4126', '+32499000000']
|
||||
expected_numbers = ['+12518428701', '+12518428701', '+447892164126', '+447892164126', '+32499000000']
|
||||
test_names = ['customer country', 'first guest country', 'second guest country', 'record country', 'existing prefix']
|
||||
|
||||
for partner_vals, record_vals, input_number, expected_number, test_name in zip(partner_vals_all, record_vals_all, input_numbers, expected_numbers, test_names):
|
||||
for partner, base_vals, vals in zip(partners, base_partner_vals, partner_vals):
|
||||
partner.write(base_vals | vals)
|
||||
test_record.write(base_record_vals | record_vals)
|
||||
with self.subTest(test_name=test_name):
|
||||
self.assertEqual(
|
||||
test_record._phone_format(
|
||||
number=input_number,
|
||||
), expected_number)
|
||||
|
||||
def test_phone_format_perf(self):
|
||||
PARTNER_COUNT = 100
|
||||
|
||||
countries = self.env['res.country'].create([{
|
||||
'name': f'Test Country {n}',
|
||||
'code': str(n),
|
||||
} for n in range(20)])
|
||||
|
||||
country_partners = self.env['res.partner'].create([
|
||||
{'name': f'{countries[_id % len(countries)].name} partner', 'country_id': countries[_id % len(countries)].id}
|
||||
for _id in range(PARTNER_COUNT)
|
||||
])
|
||||
|
||||
nocountry_partners = self.env['res.partner'].create([
|
||||
{'name': 'Countryless Man', 'country_id': False}
|
||||
for _ in range(PARTNER_COUNT)
|
||||
])
|
||||
|
||||
test_records = self.env['mail.test.sms'].create([{
|
||||
'country_id': False,
|
||||
'name': 'Phone Format Test Record',
|
||||
'customer_id': nocountry_p.id,
|
||||
'guest_ids': country_p.ids,
|
||||
} for nocountry_p, country_p in zip(nocountry_partners, country_partners)])
|
||||
|
||||
test_records.invalidate_recordset()
|
||||
(country_partners + nocountry_partners).invalidate_recordset()
|
||||
countries.invalidate_recordset()
|
||||
# 1 query per country + 4
|
||||
with self.assertQueryCount(24):
|
||||
for record in test_records:
|
||||
record._phone_format(
|
||||
number='078 9216 4126',
|
||||
raise_exception=False,
|
||||
)
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
|
||||
from odoo.tests import tagged
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.sms_twilio.tests.common import MockSmsTwilioApi
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
|
||||
from odoo.tests import Form, tagged, users
|
||||
|
||||
|
||||
@tagged('sms_composer')
|
||||
class TestSMSComposerComment(TestSMSCommon, TestSMSRecipients):
|
||||
@tagged('post_install', '-at_install', 'sms_composer')
|
||||
class TestSMSComposerComment(SMSCommon, TestSMSRecipients):
|
||||
""" TODO LIST
|
||||
|
||||
* add test for default_res_model / default_res_id and stuff like that;
|
||||
|
|
@ -44,12 +46,11 @@ class TestSMSComposerComment(TestSMSCommon, TestSMSRecipients):
|
|||
'numbers': ','.join(self.random_numbers),
|
||||
})
|
||||
|
||||
with self.mockSMSGateway():
|
||||
with self.mockSMSGateway(sms_allow_unlink=True):
|
||||
composer._action_send_sms()
|
||||
|
||||
# use sms.api directly, does not create sms.sms
|
||||
self.assertNoSMS()
|
||||
self.assertSMSIapSent(self.random_numbers_san, self._test_body)
|
||||
for number in self.random_numbers_san:
|
||||
self.assertSMS(self.env['res.partner'], number, 'pending', content=self._test_body, fields_values={'to_delete': True})
|
||||
|
||||
def test_composer_comment_default(self):
|
||||
with self.with_user('employee'):
|
||||
|
|
@ -64,33 +65,37 @@ class TestSMSComposerComment(TestSMSCommon, TestSMSRecipients):
|
|||
|
||||
self.assertSMSNotification([{'partner': self.test_record.customer_id, 'number': self.test_numbers_san[1]}], self._test_body, messages)
|
||||
|
||||
def test_composer_comment_field_1(self):
|
||||
with self.with_user('employee'):
|
||||
composer = self.env['sms.composer'].with_context(
|
||||
active_model='mail.test.sms', active_id=self.test_record.id,
|
||||
).create({
|
||||
'body': self._test_body,
|
||||
'number_field_name': 'mobile_nbr',
|
||||
})
|
||||
@users('employee')
|
||||
def test_composer_comment_field(self):
|
||||
"""Check that setting a field correctly uses it, even if invalid."""
|
||||
record_values_all = [
|
||||
{'mobile_nbr': self.test_numbers[0], 'phone_nbr': self.test_numbers[1]},
|
||||
{'mobile_nbr': self.test_numbers[0], 'phone_nbr': self.test_numbers[1]},
|
||||
{'mobile_nbr': 'invalid_phone_nbr', 'phone_nbr': self.test_numbers[1]},
|
||||
]
|
||||
phone_fields = ['mobile_nbr', 'phone_nbr', 'mobile_nbr']
|
||||
expected_form_numbers = ['+32456010203', '+32456040506', 'invalid_phone_nbr']
|
||||
expected_sent_numbers = ['+32456010203', '+32456040506', '+32456001122']
|
||||
|
||||
for record_values, phone_field, expected_form_number, expected_sent_number in zip(
|
||||
record_values_all, phone_fields, expected_form_numbers, expected_sent_numbers,
|
||||
):
|
||||
with self.subTest(phone_field=phone_field, record_number=record_values[phone_field]):
|
||||
self.test_record.write(record_values)
|
||||
composer_form = Form(self.env['sms.composer'].with_context(
|
||||
active_model='mail.test.sms', active_id=self.test_record.id,
|
||||
default_number_field_name=phone_field, default_body=self._test_body
|
||||
))
|
||||
self.assertEqual(composer_form.recipient_single_number_itf, expected_form_number)
|
||||
|
||||
with self.mockSMSGateway():
|
||||
messages = composer._action_send_sms()
|
||||
messages = composer_form.save()._action_send_sms()
|
||||
|
||||
self.assertSMSNotification([{'partner': self.test_record.customer_id, 'number': self.test_numbers_san[0]}], self._test_body, messages)
|
||||
|
||||
def test_composer_comment_field_2(self):
|
||||
with self.with_user('employee'):
|
||||
composer = self.env['sms.composer'].with_context(
|
||||
active_model='mail.test.sms', active_id=self.test_record.id,
|
||||
).create({
|
||||
'body': self._test_body,
|
||||
'number_field_name': 'phone_nbr',
|
||||
})
|
||||
|
||||
with self.mockSMSGateway():
|
||||
messages = composer._action_send_sms()
|
||||
|
||||
self.assertSMSNotification([{'partner': self.test_record.customer_id, 'number': self.test_numbers_san[1]}], self._test_body, messages)
|
||||
self.assertSMSNotification([{
|
||||
'partner': self.test_record.customer_id,
|
||||
'number': expected_sent_number,
|
||||
'state': 'pending',
|
||||
}], self._test_body, messages)
|
||||
|
||||
def test_composer_comment_field_w_numbers(self):
|
||||
with self.with_user('employee'):
|
||||
|
|
@ -171,16 +176,21 @@ class TestSMSComposerComment(TestSMSCommon, TestSMSRecipients):
|
|||
|
||||
def test_composer_nofield_w_customer(self):
|
||||
""" Test SMS composer without number field, the number on partner must be used instead"""
|
||||
test_record = self.env['mail.test.sms.partner'].create({
|
||||
'name': 'Test',
|
||||
'customer_id': self.partner_1.id,
|
||||
})
|
||||
|
||||
with self.with_user('employee'):
|
||||
composer = self.env['sms.composer'].with_context(
|
||||
default_res_model='mail.test.sms', default_res_id=self.test_record.id,
|
||||
default_res_model=test_record._name, default_res_id=test_record.id,
|
||||
).create({
|
||||
'body': self._test_body,
|
||||
})
|
||||
|
||||
self.assertFalse(composer.number_field_name)
|
||||
self.assertTrue(composer.recipient_single_valid)
|
||||
self.assertEqual(composer.recipient_single_number, self.test_numbers_san[1])
|
||||
self.assertEqual(composer.recipient_single_number_itf, self.test_numbers_san[1])
|
||||
self.assertEqual(composer.recipient_single_number, self.partner_numbers[0])
|
||||
self.assertEqual(composer.recipient_single_number_itf, self.partner_numbers[0])
|
||||
|
||||
def test_composer_internals(self):
|
||||
with self.with_user('employee'):
|
||||
|
|
@ -226,7 +236,7 @@ class TestSMSComposerComment(TestSMSCommon, TestSMSRecipients):
|
|||
'phone_nbr': False,
|
||||
'mobile_nbr': False,
|
||||
})
|
||||
default_field_name = self.env['mail.test.sms']._sms_get_number_fields()[0]
|
||||
default_field_name = self.env['mail.test.sms']._phone_get_number_fields()[0]
|
||||
|
||||
with self.with_user('employee'):
|
||||
composer = self.env['sms.composer'].with_context(
|
||||
|
|
@ -260,12 +270,11 @@ class TestSMSComposerComment(TestSMSCommon, TestSMSRecipients):
|
|||
'numbers': ','.join(self.random_numbers),
|
||||
})
|
||||
|
||||
with self.mockSMSGateway():
|
||||
with self.mockSMSGateway(sms_allow_unlink=True):
|
||||
composer._action_send_sms()
|
||||
|
||||
# use sms.api directly, does not create sms.sms
|
||||
self.assertNoSMS()
|
||||
self.assertSMSIapSent(self.random_numbers_san, self._test_body)
|
||||
for number in self.random_numbers_san:
|
||||
self.assertSMS(self.env['res.partner'], number, 'pending', content=self._test_body, fields_values={'to_delete': True})
|
||||
|
||||
def test_composer_sending_with_no_number_field(self):
|
||||
test_record = self.env['mail.test.sms.partner'].create({'name': 'Test'})
|
||||
|
|
@ -286,7 +295,8 @@ class TestSMSComposerComment(TestSMSCommon, TestSMSRecipients):
|
|||
|
||||
|
||||
@tagged('sms_composer')
|
||||
class TestSMSComposerBatch(TestSMSCommon):
|
||||
class TestSMSComposerBatch(SMSCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestSMSComposerBatch, cls).setUpClass()
|
||||
|
|
@ -336,8 +346,42 @@ class TestSMSComposerBatch(TestSMSCommon):
|
|||
)
|
||||
|
||||
|
||||
@tagged('sms_composer', 'twilio')
|
||||
class TestSMSComposerBatchTwilio(SMSCommon, MockSmsTwilioApi):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls._test_body = 'Hello {{ object.name }} zizisse an SMS.'
|
||||
|
||||
cls._create_records_for_batch('mail.test.sms', 3)
|
||||
cls.sms_template = cls._create_sms_template('mail.test.sms')
|
||||
|
||||
cls._setup_sms_twilio(cls.user_admin.company_id)
|
||||
|
||||
@users('employee')
|
||||
def test_composer_batch_res_ids_twilio(self):
|
||||
composer = self.env['sms.composer'].with_context(
|
||||
default_composition_mode='comment',
|
||||
default_res_model='mail.test.sms',
|
||||
default_res_ids=repr(self.records.ids),
|
||||
).create({
|
||||
'body': self._test_body,
|
||||
})
|
||||
|
||||
with self.mock_sms_twilio_gateway():
|
||||
messages = composer._action_send_sms()
|
||||
|
||||
for record, message in zip(self.records, messages):
|
||||
self.assertSMSNotification(
|
||||
[{'partner': record.customer_id}],
|
||||
'Hello %s zizisse an SMS.' % record.name,
|
||||
message
|
||||
)
|
||||
|
||||
|
||||
@tagged('sms_composer')
|
||||
class TestSMSComposerMass(TestSMSCommon):
|
||||
class TestSMSComposerMass(SMSCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
@ -381,7 +425,7 @@ class TestSMSComposerMass(TestSMSCommon):
|
|||
).create({
|
||||
'body': self._test_body,
|
||||
'mass_keep_log': False,
|
||||
'mass_use_blacklist': True,
|
||||
'use_exclusion_list': True,
|
||||
})
|
||||
|
||||
with self.mockSMSGateway():
|
||||
|
|
@ -413,7 +457,7 @@ class TestSMSComposerMass(TestSMSCommon):
|
|||
).create({
|
||||
'body': self._test_body,
|
||||
'mass_keep_log': False,
|
||||
'mass_use_blacklist': False,
|
||||
'use_exclusion_list': False,
|
||||
})
|
||||
|
||||
with self.mockSMSGateway():
|
||||
|
|
@ -433,7 +477,7 @@ class TestSMSComposerMass(TestSMSCommon):
|
|||
'active': True,
|
||||
} for p in self.partners[:5]])
|
||||
for p in self.partners[5:8]:
|
||||
p.mobile = self.partners[5].mobile
|
||||
p.phone = self.partners[5].phone
|
||||
self.assertEqual(p.phone_sanitized, self.partners[5].phone_sanitized)
|
||||
|
||||
with self.with_user('employee'):
|
||||
|
|
@ -444,7 +488,7 @@ class TestSMSComposerMass(TestSMSCommon):
|
|||
).create({
|
||||
'body': self._test_body,
|
||||
'mass_keep_log': False,
|
||||
'mass_use_blacklist': True,
|
||||
'use_exclusion_list': True,
|
||||
})
|
||||
|
||||
with self.mockSMSGateway():
|
||||
|
|
@ -589,7 +633,7 @@ class TestSMSComposerMass(TestSMSCommon):
|
|||
with self.mockSMSGateway():
|
||||
messages = composer._action_send_sms()
|
||||
|
||||
number = self.partners[2].phone_get_sanitized_number()
|
||||
number = self.partners[2]._phone_format()
|
||||
self.assertSMSNotification(
|
||||
[{'partner': test_record_2.customer_id, 'number': number}],
|
||||
"Hello %s ceci est en français." % test_record_2.display_name, messages
|
||||
|
|
@ -623,3 +667,37 @@ class TestSMSComposerMass(TestSMSCommon):
|
|||
test_record_2.customer_id, None,
|
||||
content="Hello %s ceci est en français." % test_record_2.display_name
|
||||
)
|
||||
|
||||
|
||||
@tagged('sms_composer', 'twilio')
|
||||
class TestSMSComposerMassTwilio(SMSCommon, MockSmsTwilioApi):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls._test_body = 'Hello {{ object.name }} zizisse an SMS.'
|
||||
|
||||
cls._create_records_for_batch('mail.test.sms', 10)
|
||||
cls.sms_template = cls._create_sms_template('mail.test.sms')
|
||||
|
||||
cls._setup_sms_twilio(cls.user_admin.company_id)
|
||||
|
||||
@users('employee')
|
||||
def test_composer_mass_active_ids_twilio(self):
|
||||
composer = self.env['sms.composer'].with_context(
|
||||
default_composition_mode='mass',
|
||||
default_res_model='mail.test.sms',
|
||||
active_ids=self.records.ids,
|
||||
).create({
|
||||
'body': self._test_body,
|
||||
'mass_keep_log': False,
|
||||
})
|
||||
|
||||
with self.mock_sms_twilio_gateway():
|
||||
composer.action_send_sms()
|
||||
|
||||
for partner, record in zip(self.partners, self.records):
|
||||
self.assertSMSOutgoing(
|
||||
partner, None,
|
||||
content='Hello %s zizisse an SMS.' % record.name
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,98 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import Command
|
||||
from odoo.addons.test_mail_sms.tests.test_sms_management import TestSMSActionsCommon
|
||||
from odoo.tests.common import JsonRpcException
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestSmsController(TestSMSActionsCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.sms_processing, cls.sms_sent = cls.env['sms.sms'].create([
|
||||
{
|
||||
'body': 'A test about pending state',
|
||||
'number': '10',
|
||||
'mail_message_id': cls.msg.id,
|
||||
'uuid': '8db55b6a9ec6443ca1d69af3ab500e27',
|
||||
'state': 'process',
|
||||
}, {
|
||||
'mail_message_id': cls.msg.id,
|
||||
'body': 'A test about sent state',
|
||||
'number': '20',
|
||||
'uuid': '8505e6f439d4472690c7955de9b210a4',
|
||||
'state': 'sent',
|
||||
},
|
||||
])
|
||||
cls.notification_processing, cls.notification_pending = cls.env['mail.notification'].create([
|
||||
{
|
||||
'mail_message_id': cls.msg.id,
|
||||
'notification_type': 'sms',
|
||||
'notification_status': 'process',
|
||||
'sms_id_int': cls.sms_processing.id,
|
||||
'sms_tracker_ids': [Command.create({'sms_uuid': cls.sms_processing.uuid})],
|
||||
}, {
|
||||
'mail_message_id': cls.msg.id,
|
||||
'notification_type': 'sms',
|
||||
'notification_status': 'pending',
|
||||
'sms_id_int': cls.sms_sent.id,
|
||||
'sms_tracker_ids': [Command.create({'sms_uuid': cls.sms_sent.uuid})],
|
||||
},
|
||||
])
|
||||
cls.sms_sent.unlink() # as it would normally be.
|
||||
|
||||
@mute_logger("odoo.addons.base.models.ir_http")
|
||||
def test_webhook_update_notification_from_processing_to_pending(self):
|
||||
self.assertTrue(self.sms_processing)
|
||||
statuses = [{'sms_status': 'sent', 'uuids': [self.sms_processing.uuid]}]
|
||||
self.assertEqual(self._make_webhook_jsonrpc_request(statuses), 'OK')
|
||||
self.assertTrue(self.sms_processing.to_delete)
|
||||
self.assertEqual(self.notification_processing.notification_status, 'pending')
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_http')
|
||||
def test_webhook_update_notification_from_pending_to_bounced(self):
|
||||
statuses = [{'sms_status': 'invalid_destination', 'uuids': [self.notification_pending.sms_tracker_ids.sms_uuid]}]
|
||||
self.assertEqual(self._make_webhook_jsonrpc_request(statuses), 'OK')
|
||||
self.assertEqual(self.notification_pending.notification_status, 'bounce')
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_http')
|
||||
def test_webhook_update_notification_from_pending_to_delivered(self):
|
||||
statuses = [{'sms_status': 'delivered', 'uuids': [self.notification_pending.sms_tracker_ids.sms_uuid]}]
|
||||
self.assertEqual(self._make_webhook_jsonrpc_request(statuses), 'OK')
|
||||
self.assertEqual(self.notification_pending.notification_status, 'sent')
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_http')
|
||||
def test_webhook_update_notification_from_pending_to_failed(self):
|
||||
statuses = [{'sms_status': 'not_delivered', 'uuids': [self.notification_pending.sms_tracker_ids.sms_uuid]}]
|
||||
self.assertEqual(self._make_webhook_jsonrpc_request(statuses), 'OK')
|
||||
self.assertEqual(self.notification_pending.notification_status, 'exception')
|
||||
self.assertEqual(self.notification_pending.failure_type, 'sms_not_delivered')
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_http')
|
||||
def test_webhook_update_notification_multiple_statuses(self):
|
||||
statuses = [
|
||||
{'sms_status': 'sent', 'uuids': [self.notification_processing.sms_tracker_ids.sms_uuid]},
|
||||
{'sms_status': 'delivered', 'uuids': [self.notification_pending.sms_tracker_ids.sms_uuid]}
|
||||
]
|
||||
self.assertEqual(self._make_webhook_jsonrpc_request(statuses), 'OK')
|
||||
self.assertTrue(self.sms_processing.to_delete)
|
||||
self.assertEqual(self.notification_processing.notification_status, 'pending')
|
||||
self.assertEqual(self.notification_pending.notification_status, 'sent')
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_http', 'odoo.addons.sms.controllers.main', 'odoo.http')
|
||||
def test_webhook_update_raises_with_wrong_event_data(self):
|
||||
statuses = [{'sms_status': 'delivered', 'uuids': ['not a uuid']}]
|
||||
with self.assertRaises(JsonRpcException):
|
||||
self._make_webhook_jsonrpc_request(statuses)
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_http')
|
||||
def test_webhook_update_succeeds_with_non_existent_uuids(self):
|
||||
statuses = [{'sms_status': 'delivered', 'uuids': ['00000000000000000000000000000000']}]
|
||||
self.assertEqual(self._make_webhook_jsonrpc_request(statuses), 'OK')
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_http')
|
||||
def test_webhook_update_succeeds_with_unknown_status(self):
|
||||
statuses = [{'sms_status': 'something_new', 'uuids': [self.notification_pending.sms_tracker_ids.sms_uuid]}]
|
||||
self.assertEqual(self._make_webhook_jsonrpc_request(statuses), 'OK')
|
||||
self.assertEqual(self.notification_pending.notification_status, 'exception')
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
|
||||
from odoo.tests import tagged
|
||||
from odoo import Command
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
|
||||
from odoo.tests import tagged, users
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
||||
class TestSMSActionsCommon(SMSCommon, TestSMSRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
@ -21,7 +23,8 @@ class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
|||
'body': 'TEST BODY',
|
||||
'failure_type': 'sms_number_format',
|
||||
'mail_message_id': cls.msg.id,
|
||||
'number': cls.partner_1.mobile,
|
||||
'uuid': 'e91d874e-d55f-4cf6-9d08-38ff912c6efd',
|
||||
'number': cls.partner_1.phone,
|
||||
'partner_id': cls.partner_1.id,
|
||||
'state': 'error',
|
||||
})
|
||||
|
|
@ -29,8 +32,9 @@ class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
|||
'author_id': cls.msg.author_id.id,
|
||||
'mail_message_id': cls.msg.id,
|
||||
'res_partner_id': cls.partner_1.id,
|
||||
'sms_id': cls.sms_p1.id,
|
||||
'sms_number': cls.partner_1.mobile,
|
||||
'sms_id_int': cls.sms_p1.id,
|
||||
'sms_number': cls.partner_1.phone,
|
||||
'sms_tracker_ids': [Command.create({'sms_uuid': cls.sms_p1.uuid})],
|
||||
'notification_type': 'sms',
|
||||
'notification_status': 'exception',
|
||||
'failure_type': 'sms_number_format',
|
||||
|
|
@ -39,16 +43,18 @@ class TestSMSActionsCommon(TestSMSCommon, TestSMSRecipients):
|
|||
'body': 'TEST BODY',
|
||||
'failure_type': 'sms_credit',
|
||||
'mail_message_id': cls.msg.id,
|
||||
'number': cls.partner_2.mobile,
|
||||
'number': cls.partner_2.phone,
|
||||
'partner_id': cls.partner_2.id,
|
||||
'state': 'error',
|
||||
'uuid': 'bab41209-7b14-48c1-ae21-c45ceed7e728',
|
||||
})
|
||||
cls.notif_p2 = cls.env['mail.notification'].create({
|
||||
'author_id': cls.msg.author_id.id,
|
||||
'mail_message_id': cls.msg.id,
|
||||
'res_partner_id': cls.partner_2.id,
|
||||
'sms_id': cls.sms_p2.id,
|
||||
'sms_number': cls.partner_2.mobile,
|
||||
'sms_id_int': cls.sms_p2.id,
|
||||
'sms_number': cls.partner_2.phone,
|
||||
'sms_tracker_ids': [Command.create({'sms_uuid': cls.sms_p2.uuid})],
|
||||
'notification_type': 'sms',
|
||||
'notification_status': 'exception',
|
||||
'failure_type': 'sms_credit',
|
||||
|
|
@ -88,7 +94,6 @@ class TestSMSActions(TestSMSActionsCommon):
|
|||
{'partner': self.partner_2, 'number': self.notif_p2.sms_number, 'state': 'canceled', 'failure_type': 'sms_credit'}
|
||||
], 'TEST BODY', self.msg, check_sms=False) # do not check new sms as they already exist
|
||||
|
||||
|
||||
def test_sms_set_error(self):
|
||||
self._reset_bus()
|
||||
(self.sms_p1 + self.sms_p2).with_context(sms_skip_msg_notification=True).action_set_canceled()
|
||||
|
|
@ -106,9 +111,10 @@ class TestSMSActions(TestSMSActionsCommon):
|
|||
{'partner': self.partner_2, 'number': self.notif_p2.sms_number, 'state': 'exception', 'failure_type': 'sms_server'}
|
||||
], 'TEST BODY', self.msg, check_sms=False) # do not check new sms as they already exist
|
||||
|
||||
@users('admin')
|
||||
def test_sms_set_outgoing(self):
|
||||
self._reset_bus()
|
||||
(self.sms_p1 + self.sms_p2).action_set_outgoing()
|
||||
(self.sms_p1 + self.sms_p2).with_user(self.env.user).action_set_outgoing()
|
||||
self.assertEqual(self.sms_p1.state, 'outgoing')
|
||||
self.assertEqual(self.sms_p2.state, 'outgoing')
|
||||
|
||||
|
|
@ -117,83 +123,3 @@ class TestSMSActions(TestSMSActionsCommon):
|
|||
{'partner': self.partner_1, 'number': self.notif_p1.sms_number, 'state': 'ready'},
|
||||
{'partner': self.partner_2, 'number': self.notif_p2.sms_number, 'state': 'ready'}
|
||||
], 'TEST BODY', self.msg, check_sms=False) # do not check new sms as they already exist
|
||||
|
||||
|
||||
@tagged('sms_management')
|
||||
class TestSMSWizards(TestSMSActionsCommon):
|
||||
|
||||
@mute_logger('odoo.addons.sms.models.sms_sms')
|
||||
def test_sms_resend(self):
|
||||
self._reset_bus()
|
||||
|
||||
with self.with_user('employee'):
|
||||
wizard = self.env['sms.resend'].with_context(default_mail_message_id=self.msg.id).create({})
|
||||
wizard.write({'recipient_ids': [(1, r.id, {'resend': True}) for r in wizard.recipient_ids]})
|
||||
with self.mockSMSGateway():
|
||||
wizard.action_resend()
|
||||
|
||||
self.assertSMSNotification([
|
||||
{'partner': self.partner_1, 'state': 'sent'},
|
||||
{'partner': self.partner_2, 'state': 'sent'}
|
||||
], 'TEST BODY', self.msg, check_sms=True)
|
||||
self.assertMessageBusNotifications(self.msg)
|
||||
|
||||
@mute_logger('odoo.addons.sms.models.sms_sms')
|
||||
def test_sms_resend_update_number(self):
|
||||
self._reset_bus()
|
||||
|
||||
with self.with_user('employee'):
|
||||
wizard = self.env['sms.resend'].with_context(default_mail_message_id=self.msg.id).create({})
|
||||
wizard.write({'recipient_ids': [(1, r.id, {'resend': True, 'sms_number': self.random_numbers[idx]}) for idx, r in enumerate(wizard.recipient_ids.sorted())]})
|
||||
with self.mockSMSGateway():
|
||||
wizard.action_resend()
|
||||
|
||||
self.assertSMSNotification([
|
||||
{'partner': self.partner_1, 'state': 'sent', 'number': self.random_numbers_san[0]},
|
||||
{'partner': self.partner_2, 'state': 'sent', 'number': self.random_numbers_san[1]}
|
||||
], 'TEST BODY', self.msg, check_sms=True)
|
||||
self.assertMessageBusNotifications(self.msg)
|
||||
|
||||
def test_sms_resend_cancel(self):
|
||||
self._reset_bus()
|
||||
|
||||
with self.with_user('employee'):
|
||||
wizard = self.env['sms.resend'].with_context(default_mail_message_id=self.msg.id).create({})
|
||||
with self.mockSMSGateway():
|
||||
wizard.action_cancel()
|
||||
|
||||
self.assertSMSNotification([
|
||||
{'partner': self.partner_1, 'state': 'canceled', 'number': self.notif_p1.sms_number, 'failure_type': 'sms_number_format'},
|
||||
{'partner': self.partner_2, 'state': 'canceled', 'number': self.notif_p2.sms_number, 'failure_type': 'sms_credit'}
|
||||
], 'TEST BODY', self.msg, check_sms=False)
|
||||
self.assertMessageBusNotifications(self.msg)
|
||||
|
||||
@mute_logger('odoo.addons.sms.models.sms_sms')
|
||||
def test_sms_resend_internals(self):
|
||||
self._reset_bus()
|
||||
self.assertSMSNotification([
|
||||
{'partner': self.partner_1, 'state': 'exception', 'number': self.notif_p1.sms_number, 'failure_type': 'sms_number_format'},
|
||||
{'partner': self.partner_2, 'state': 'exception', 'number': self.notif_p2.sms_number, 'failure_type': 'sms_credit'}
|
||||
], 'TEST BODY', self.msg, check_sms=False)
|
||||
|
||||
with self.with_user('employee'):
|
||||
wizard = self.env['sms.resend'].with_context(default_mail_message_id=self.msg.id).create({})
|
||||
self.assertTrue(wizard.has_insufficient_credit)
|
||||
self.assertEqual(set(wizard.mapped('recipient_ids.partner_name')), set((self.partner_1 | self.partner_2).mapped('display_name')))
|
||||
wizard.write({'recipient_ids': [(1, r.id, {'resend': True}) for r in wizard.recipient_ids]})
|
||||
with self.mockSMSGateway():
|
||||
wizard.action_resend()
|
||||
|
||||
@mute_logger('odoo.addons.sms.models.sms_sms')
|
||||
def test_sms_resend_w_cancel(self):
|
||||
self._reset_bus()
|
||||
|
||||
with self.with_user('employee'):
|
||||
wizard = self.env['sms.resend'].with_context(default_mail_message_id=self.msg.id).create({})
|
||||
wizard.write({'recipient_ids': [(1, r.id, {'resend': True if r.partner_id == self.partner_1 else False}) for r in wizard.recipient_ids]})
|
||||
with self.mockSMSGateway():
|
||||
wizard.action_resend()
|
||||
|
||||
self.assertSMSNotification([{'partner': self.partner_1, 'state': 'sent'}], 'TEST BODY', self.msg, check_sms=True)
|
||||
self.assertSMSNotification([{'partner': self.partner_2, 'state': 'canceled', 'number': self.notif_p2.sms_number, 'failure_type': 'sms_credit'}], 'TEST BODY', self.msg, check_sms=False)
|
||||
self.assertMessageBusNotifications(self.msg)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
|
||||
from odoo.tests import Form, tagged
|
||||
|
||||
|
||||
@tagged('sms_composer')
|
||||
class TestSMSNoThread(TestSMSCommon, TestSMSRecipients):
|
||||
class TestSMSNoThread(SMSCommon, TestSMSRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
@ -44,7 +45,7 @@ class TestSMSNoThread(TestSMSCommon, TestSMSRecipients):
|
|||
self.assertEqual(composer.recipient_single_number, '+32456001122')
|
||||
self.assertEqual(composer.recipient_single_number_itf, '+32456001122')
|
||||
self.assertTrue(composer.recipient_single_valid)
|
||||
self.assertEqual(composer.number_field_name, 'mobile')
|
||||
self.assertEqual(composer.number_field_name, 'phone')
|
||||
self.assertFalse(composer.numbers)
|
||||
self.assertFalse(composer.sanitized_numbers)
|
||||
|
||||
|
|
@ -91,14 +92,16 @@ class TestSMSNoThread(TestSMSCommon, TestSMSRecipients):
|
|||
self.assertTrue(composer.comment_single_recipient)
|
||||
self.assertEqual(composer.composition_mode, 'comment')
|
||||
if ctx.get('default_number_field_name') == 'mobile':
|
||||
stored_number = '' # invalid field + single recipient -> no number
|
||||
self.assertEqual(composer.recipient_valid_count, 0)
|
||||
self.assertEqual(composer.recipient_invalid_count, 1)
|
||||
else:
|
||||
stored_number = '+32455135790'
|
||||
self.assertEqual(composer.recipient_valid_count, 1)
|
||||
self.assertEqual(composer.recipient_invalid_count, 0)
|
||||
self.assertEqual(composer.recipient_single_description, self.user_admin.name)
|
||||
self.assertEqual(composer.recipient_single_number, '+32455135790')
|
||||
self.assertEqual(composer.recipient_single_number_itf, '+32455135790')
|
||||
self.assertEqual(composer.recipient_single_number_itf, stored_number)
|
||||
self.assertTrue(composer.recipient_single_valid)
|
||||
self.assertEqual(composer.number_field_name, ctx.get('default_number_field_name', 'phone'))
|
||||
self.assertFalse(composer.numbers)
|
||||
|
|
@ -106,3 +109,6 @@ class TestSMSNoThread(TestSMSCommon, TestSMSRecipients):
|
|||
|
||||
with self.mockSMSGateway():
|
||||
composer._action_send_sms()
|
||||
|
||||
# even if the stored number is correct, fall back on the computed number
|
||||
self.assertSMS(self.env['res.partner'], '+32455135790', 'pending')
|
||||
|
|
|
|||
|
|
@ -11,21 +11,22 @@ from odoo.tools import mute_logger
|
|||
@tagged('mail_performance', 'post_install', '-at_install')
|
||||
class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSMSPerformance, self).setUp()
|
||||
|
||||
self.test_record = self.env['mail.test.sms'].with_context(self._test_context).create({
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.test_record = cls.env['mail.test.sms'].with_context(cls._test_context).create({
|
||||
'name': 'Test',
|
||||
'customer_id': self.customer.id,
|
||||
'customer_id': cls.customer.id,
|
||||
'phone_nbr': '0456999999',
|
||||
})
|
||||
|
||||
# prepare recipients to test for more realistic workload
|
||||
self.partners = self.env['res.partner'].with_context(self._test_context).create([
|
||||
{'name': 'Test %s' % x,
|
||||
'email': 'test%s@example.com' % x,
|
||||
'mobile': '0456%s%s0000' % (x, x),
|
||||
'country_id': self.env.ref('base.be').id,
|
||||
cls.partners = cls.env['res.partner'].with_context(cls._test_context).create([
|
||||
{
|
||||
'country_id': cls.env.ref('base.be').id,
|
||||
'email': 'test%s@example.com' % x,
|
||||
'phone': '0456%s%s0000' % (x, x),
|
||||
'name': 'Test %s' % x,
|
||||
} for x in range(0, 10)
|
||||
])
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
|
|||
def test_message_sms_record_1_partner(self):
|
||||
record = self.test_record.with_user(self.env.user)
|
||||
pids = self.customer.ids
|
||||
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=26):
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=32): # tms: 32
|
||||
messages = record._message_sms(
|
||||
body='Performance Test',
|
||||
partner_ids=pids,
|
||||
|
|
@ -50,7 +51,7 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
|
|||
def test_message_sms_record_10_partners(self):
|
||||
record = self.test_record.with_user(self.env.user)
|
||||
pids = self.partners.ids
|
||||
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=26):
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=32): # tms: 32
|
||||
messages = record._message_sms(
|
||||
body='Performance Test',
|
||||
partner_ids=pids,
|
||||
|
|
@ -64,43 +65,44 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
|
|||
@warmup
|
||||
def test_message_sms_record_default(self):
|
||||
record = self.test_record.with_user(self.env.user)
|
||||
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=28):
|
||||
with self.subTest("QueryCount"), self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=33): # tms: 33
|
||||
messages = record._message_sms(
|
||||
body='Performance Test',
|
||||
)
|
||||
|
||||
self.assertEqual(record.message_ids[0].body, '<p>Performance Test</p>')
|
||||
self.assertSMSNotification([{'partner': self.customer}], 'Performance Test', messages, sent_unlink=True)
|
||||
self.assertSMSNotification([{'number': '+32456999999', 'partner': self.customer}], 'Performance Test', messages, sent_unlink=True)
|
||||
|
||||
|
||||
@tagged('mail_performance', 'post_install', '-at_install')
|
||||
class TestSMSMassPerformance(BaseMailPerformance, sms_common.MockSMS):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSMSMassPerformance, self).setUp()
|
||||
be_country_id = self.env.ref('base.be').id
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
be_country_id = cls.env.ref('base.be').id
|
||||
|
||||
self._test_body = 'MASS SMS'
|
||||
cls._test_body = 'MASS SMS'
|
||||
|
||||
records = self.env['mail.test.sms']
|
||||
partners = self.env['res.partner']
|
||||
records = cls.env['mail.test.sms']
|
||||
partners = cls.env['res.partner']
|
||||
for x in range(50):
|
||||
partners += self.env['res.partner'].with_context(**self._test_context).create({
|
||||
partners += cls.env['res.partner'].with_context(**cls._test_context).create({
|
||||
'name': 'Partner_%s' % (x),
|
||||
'email': '_test_partner_%s@example.com' % (x),
|
||||
'country_id': be_country_id,
|
||||
'mobile': '047500%02d%02d' % (x, x)
|
||||
'phone': '047500%02d%02d' % (x, x)
|
||||
})
|
||||
records += self.env['mail.test.sms'].with_context(**self._test_context).create({
|
||||
records += cls.env['mail.test.sms'].with_context(**cls._test_context).create({
|
||||
'name': 'Test_%s' % (x),
|
||||
'customer_id': partners[x].id,
|
||||
})
|
||||
self.partners = partners
|
||||
self.records = records
|
||||
cls.partners = partners
|
||||
cls.records = records
|
||||
|
||||
self.sms_template = self.env['sms.template'].create({
|
||||
cls.sms_template = cls.env['sms.template'].create({
|
||||
'name': 'Test Template',
|
||||
'model_id': self.env['ir.model']._get('mail.test.sms').id,
|
||||
'model_id': cls.env['ir.model']._get('mail.test.sms').id,
|
||||
'body': 'Dear {{ object.display_name }} this is an SMS.',
|
||||
})
|
||||
|
||||
|
|
@ -117,7 +119,7 @@ class TestSMSMassPerformance(BaseMailPerformance, sms_common.MockSMS):
|
|||
'mass_keep_log': False,
|
||||
})
|
||||
|
||||
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=56):
|
||||
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=60):
|
||||
composer.action_send_sms()
|
||||
|
||||
@mute_logger('odoo.addons.sms.models.sms_sms')
|
||||
|
|
@ -133,5 +135,5 @@ class TestSMSMassPerformance(BaseMailPerformance, sms_common.MockSMS):
|
|||
'mass_keep_log': True,
|
||||
})
|
||||
|
||||
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=58):
|
||||
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=64):
|
||||
composer.action_send_sms()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from odoo.addons.base.tests.test_ir_cron import CronMixinCase
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
|
||||
from odoo.tests import tagged
|
||||
|
||||
|
||||
class TestSMSPost(TestSMSCommon, TestSMSRecipients):
|
||||
@tagged('sms_post')
|
||||
class TestSMSPost(SMSCommon, TestSMSRecipients, CronMixinCase):
|
||||
""" TODO
|
||||
|
||||
* add tests for new mail.message and mail.thread fields;
|
||||
|
|
@ -32,18 +38,6 @@ class TestSMSPost(TestSMSCommon, TestSMSRecipients):
|
|||
self.assertEqual(messages.subtype_id, self.env.ref('mail.mt_note'))
|
||||
self.assertSMSNotification([{'partner': self.partner_1}], '<p>Mega SMS<br/>Top moumoutte</p>', messages)
|
||||
|
||||
def test_message_sms_internals_resend_existingd(self):
|
||||
with self.with_user('employee'), self.mockSMSGateway(sim_error='wrong_number_format'):
|
||||
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
|
||||
messages = test_record._message_sms(self._test_body, partner_ids=self.partner_1.ids)
|
||||
|
||||
self.assertSMSNotification([{'partner': self.partner_1, 'state': 'exception', 'failure_type': 'sms_number_format'}], self._test_body, messages)
|
||||
|
||||
with self.with_user('employee'), self.mockSMSGateway():
|
||||
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
|
||||
test_record._notify_thread_by_sms(messages, [{'id': self.partner_1.id, 'notif': 'sms'}], resend_existing=True)
|
||||
self.assertSMSNotification([{'partner': self.partner_1}], self._test_body, messages)
|
||||
|
||||
def test_message_sms_internals_sms_numbers(self):
|
||||
with self.with_user('employee'), self.mockSMSGateway():
|
||||
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
|
||||
|
|
@ -57,14 +51,14 @@ class TestSMSPost(TestSMSCommon, TestSMSRecipients):
|
|||
In that case sms shall NOT be sent twice."""
|
||||
with self.with_user('employee'), self.mockSMSGateway():
|
||||
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
|
||||
additional_number_same_as_partner_number = self.partner_1.mobile
|
||||
additional_number_same_as_partner_number = self.partner_1.phone
|
||||
subtype_id = self.env['ir.model.data']._xmlid_to_res_id('mail.mt_note')
|
||||
test_record._message_sms(
|
||||
body=self._test_body,
|
||||
partner_ids=self.partner_1.ids,
|
||||
subtype_id=subtype_id,
|
||||
sms_numbers=[additional_number_same_as_partner_number],
|
||||
number_field='mobile'
|
||||
number_field='phone'
|
||||
)
|
||||
self.assertEqual(len(self._new_sms.filtered(lambda s: s.number == self.partner_numbers[0])), 1,
|
||||
"There should be one message sent if additional number is the same as partner number")
|
||||
|
|
@ -99,7 +93,7 @@ class TestSMSPost(TestSMSCommon, TestSMSRecipients):
|
|||
self.assertSMSNotification([{'partner': self.partner_1}, {'partner': self.partner_2}], self._test_body, messages)
|
||||
|
||||
def test_message_sms_model_partner_fallback(self):
|
||||
self.partner_1.write({'mobile': False, 'phone': self.random_numbers[0]})
|
||||
self.partner_1.write({'phone': self.random_numbers[0]})
|
||||
|
||||
with self.mockSMSGateway():
|
||||
messages = self.partner_1._message_sms(self._test_body)
|
||||
|
|
@ -226,6 +220,44 @@ class TestSMSPost(TestSMSCommon, TestSMSRecipients):
|
|||
|
||||
self.assertSMSNotification([{'partner': self.partner_1}, {'number': self.random_numbers_san[0]}], self._test_body, messages)
|
||||
|
||||
def test_message_sms_schedule(self):
|
||||
""" Test delaying notifications through scheduled_date usage """
|
||||
cron_id = self.env.ref('mail.ir_cron_send_scheduled_message').id
|
||||
now = datetime.utcnow().replace(second=0, microsecond=0)
|
||||
scheduled_datetime = now + timedelta(days=5)
|
||||
|
||||
with self.mock_datetime_and_now(now), \
|
||||
self.with_user('employee'), \
|
||||
self.capture_triggers(cron_id) as capt, \
|
||||
self.mockSMSGateway():
|
||||
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
|
||||
messages = test_record._message_sms(
|
||||
'Testing Scheduled Notifications',
|
||||
partner_ids=self.partner_1.ids,
|
||||
scheduled_date=scheduled_datetime,
|
||||
)
|
||||
|
||||
self.assertEqual(capt.records.call_at, scheduled_datetime,
|
||||
msg='Should have created a cron trigger for the scheduled sending')
|
||||
self.assertFalse(self._new_sms)
|
||||
self.assertFalse(self._sms)
|
||||
|
||||
schedules = self.env['mail.message.schedule'].sudo().search([('mail_message_id', '=', messages.id)])
|
||||
self.assertEqual(len(schedules), 1, msg='Should have scheduled the message')
|
||||
self.assertEqual(schedules.scheduled_datetime, scheduled_datetime)
|
||||
|
||||
# trigger cron now -> should not sent as in future
|
||||
with self.mock_datetime_and_now(now):
|
||||
self.env['mail.message.schedule'].sudo()._send_notifications_cron()
|
||||
self.assertTrue(schedules.exists(), msg='Should not have sent the message')
|
||||
|
||||
# Send the scheduled message from the cron at right date
|
||||
with self.mock_datetime_and_now(now + timedelta(days=5)), self.mockSMSGateway():
|
||||
self.env['mail.message.schedule'].sudo()._send_notifications_cron()
|
||||
self.assertFalse(schedules.exists(), msg='Should have sent the message')
|
||||
# check notifications have been sent
|
||||
self.assertSMSNotification([{'partner': self.partner_1}], 'Testing Scheduled Notifications', messages)
|
||||
|
||||
def test_message_sms_with_template(self):
|
||||
sms_template = self.env['sms.template'].create({
|
||||
'name': 'Test Template',
|
||||
|
|
@ -269,7 +301,8 @@ class TestSMSPost(TestSMSCommon, TestSMSRecipients):
|
|||
self.assertSMSNotification([{'partner': self.partner_1, 'number': self.test_numbers_san[1]}], 'Dear %s this is an SMS.' % self.test_record.display_name, messages)
|
||||
|
||||
|
||||
class TestSMSPostException(TestSMSCommon, TestSMSRecipients):
|
||||
@tagged('sms_post')
|
||||
class TestSMSPostException(SMSCommon, TestSMSRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
@ -290,7 +323,7 @@ class TestSMSPostException(TestSMSCommon, TestSMSRecipients):
|
|||
'name': 'Ernestine Loubine',
|
||||
'email': 'ernestine.loubine@agrolait.com',
|
||||
'country_id': cls.env.ref('base.be').id,
|
||||
'mobile': '0475556644',
|
||||
'phone': '0475556644',
|
||||
})
|
||||
|
||||
def test_message_sms_w_numbers_invalid(self):
|
||||
|
|
@ -304,7 +337,6 @@ class TestSMSPostException(TestSMSCommon, TestSMSRecipients):
|
|||
|
||||
def test_message_sms_w_partners_nocountry(self):
|
||||
self.test_record.customer_id.write({
|
||||
'mobile': self.random_numbers[0],
|
||||
'phone': self.random_numbers[1],
|
||||
'country_id': False,
|
||||
})
|
||||
|
|
@ -317,7 +349,6 @@ class TestSMSPostException(TestSMSCommon, TestSMSRecipients):
|
|||
def test_message_sms_w_partners_falsy(self):
|
||||
# TDE FIXME: currently sent to IAP
|
||||
self.test_record.customer_id.write({
|
||||
'mobile': 'youpie',
|
||||
'phone': 'youpla',
|
||||
})
|
||||
with self.with_user('employee'), self.mockSMSGateway():
|
||||
|
|
@ -346,14 +377,14 @@ class TestSMSPostException(TestSMSCommon, TestSMSRecipients):
|
|||
], self._test_body, messages)
|
||||
|
||||
def test_message_sms_crash_credit_single(self):
|
||||
with self.with_user('employee'), self.mockSMSGateway(nbr_t_error={self.partner_2.phone_get_sanitized_number(): 'credit'}):
|
||||
with self.with_user('employee'), self.mockSMSGateway(nbr_t_error={self.partner_2._phone_format(): 'credit'}):
|
||||
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
|
||||
messages = test_record._message_sms(self._test_body, partner_ids=(self.partner_1 | self.partner_2 | self.partner_3).ids)
|
||||
|
||||
self.assertSMSNotification([
|
||||
{'partner': self.partner_1, 'state': 'sent'},
|
||||
{'partner': self.partner_1, 'state': 'pending'},
|
||||
{'partner': self.partner_2, 'state': 'exception', 'failure_type': 'sms_credit'},
|
||||
{'partner': self.partner_3, 'state': 'sent'},
|
||||
{'partner': self.partner_3, 'state': 'pending'},
|
||||
], self._test_body, messages)
|
||||
|
||||
def test_message_sms_crash_server_crash(self):
|
||||
|
|
@ -378,14 +409,14 @@ class TestSMSPostException(TestSMSCommon, TestSMSRecipients):
|
|||
], self._test_body, messages)
|
||||
|
||||
def test_message_sms_crash_unregistered_single(self):
|
||||
with self.with_user('employee'), self.mockSMSGateway(nbr_t_error={self.partner_2.phone_get_sanitized_number(): 'unregistered'}):
|
||||
with self.with_user('employee'), self.mockSMSGateway(nbr_t_error={self.partner_2._phone_format(): 'unregistered'}):
|
||||
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
|
||||
messages = test_record._message_sms(self._test_body, partner_ids=(self.partner_1 | self.partner_2 | self.partner_3).ids)
|
||||
|
||||
self.assertSMSNotification([
|
||||
{'partner': self.partner_1, 'state': 'sent'},
|
||||
{'partner': self.partner_1, 'state': 'pending'},
|
||||
{'partner': self.partner_2, 'state': 'exception', 'failure_type': 'sms_acc'},
|
||||
{'partner': self.partner_3, 'state': 'sent'},
|
||||
{'partner': self.partner_3, 'state': 'pending'},
|
||||
], self._test_body, messages)
|
||||
|
||||
def test_message_sms_crash_wrong_number(self):
|
||||
|
|
@ -399,18 +430,18 @@ class TestSMSPostException(TestSMSCommon, TestSMSRecipients):
|
|||
], self._test_body, messages)
|
||||
|
||||
def test_message_sms_crash_wrong_number_single(self):
|
||||
with self.with_user('employee'), self.mockSMSGateway(nbr_t_error={self.partner_2.phone_get_sanitized_number(): 'wrong_number_format'}):
|
||||
with self.with_user('employee'), self.mockSMSGateway(nbr_t_error={self.partner_2._phone_format(): 'wrong_number_format'}):
|
||||
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
|
||||
messages = test_record._message_sms(self._test_body, partner_ids=(self.partner_1 | self.partner_2 | self.partner_3).ids)
|
||||
|
||||
self.assertSMSNotification([
|
||||
{'partner': self.partner_1, 'state': 'sent'},
|
||||
{'partner': self.partner_1, 'state': 'pending'},
|
||||
{'partner': self.partner_2, 'state': 'exception', 'failure_type': 'sms_number_format'},
|
||||
{'partner': self.partner_3, 'state': 'sent'},
|
||||
{'partner': self.partner_3, 'state': 'pending'},
|
||||
], self._test_body, messages)
|
||||
|
||||
|
||||
class TestSMSApi(TestSMSCommon):
|
||||
class TestSMSApi(SMSCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
|
||||
from odoo.tests import tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
@tagged('ir_actions')
|
||||
class TestServerAction(TestSMSCommon, TestSMSRecipients):
|
||||
class TestServerAction(SMSCommon, TestSMSRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
@ -29,7 +30,7 @@ class TestServerAction(TestSMSCommon, TestSMSRecipients):
|
|||
'state': 'sms',
|
||||
'sms_method': 'sms',
|
||||
'sms_template_id': cls.sms_template.id,
|
||||
'groups_id': cls.env.ref('base.group_user'),
|
||||
'group_ids': cls.env.ref('base.group_user'),
|
||||
})
|
||||
|
||||
def test_action_sms(self):
|
||||
|
|
|
|||
|
|
@ -7,16 +7,16 @@ from unittest.mock import DEFAULT
|
|||
from odoo import exceptions
|
||||
from odoo.addons.link_tracker.tests.common import MockLinkTracker
|
||||
from odoo.addons.sms.models.sms_sms import SmsSms as SmsModel
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.tests import tagged
|
||||
|
||||
|
||||
@tagged('link_tracker')
|
||||
class TestSMSPost(TestSMSCommon, MockLinkTracker):
|
||||
class TestSMSPost(SMSCommon, MockLinkTracker):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestSMSPost, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
cls._test_body = 'VOID CONTENT'
|
||||
|
||||
cls.sms_all = cls.env['sms.sms']
|
||||
|
|
@ -46,7 +46,7 @@ class TestSMSPost(TestSMSCommon, MockLinkTracker):
|
|||
def test_sms_send_delete_all(self):
|
||||
with self.mockSMSGateway(sms_allow_unlink=True, sim_error='jsonrpc_exception'):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send(unlink_failed=True, unlink_sent=True, raise_exception=False)
|
||||
self.assertFalse(len(self.sms_all.exists()))
|
||||
self.assertFalse(len(self.sms_all.exists().filtered(lambda s: not s.to_delete)))
|
||||
|
||||
def test_sms_send_delete_default(self):
|
||||
""" Test default send behavior: keep failed SMS, remove sent. """
|
||||
|
|
@ -55,51 +55,61 @@ class TestSMSPost(TestSMSCommon, MockLinkTracker):
|
|||
'+32456000022': 'credit',
|
||||
'+32456000033': 'server_error',
|
||||
'+32456000044': 'unregistered',
|
||||
}):
|
||||
}):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send(raise_exception=False)
|
||||
remaining = self.sms_all.exists()
|
||||
remaining = self.sms_all.exists().filtered(lambda s: not s.to_delete)
|
||||
self.assertEqual(len(remaining), 4)
|
||||
self.assertTrue(all(sms.state == 'error') for sms in remaining)
|
||||
self.assertEqual(set(remaining.mapped('state')), {'error'})
|
||||
|
||||
def test_sms_send_delete_failed(self):
|
||||
with self.mockSMSGateway(sms_allow_unlink=True, nbr_t_error={
|
||||
'+32456000011': 'wrong_number_format',
|
||||
'+32456000022': 'wrong_number_format',
|
||||
}):
|
||||
}):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send(unlink_failed=True, unlink_sent=False, raise_exception=False)
|
||||
remaining = self.sms_all.exists()
|
||||
remaining = self.sms_all.exists().filtered(lambda s: not s.to_delete)
|
||||
self.assertEqual(len(remaining), 8)
|
||||
self.assertTrue(all(sms.state == 'sent') for sms in remaining)
|
||||
self.assertEqual(set(remaining.mapped('state')), {'pending'})
|
||||
|
||||
def test_sms_send_delete_none(self):
|
||||
with self.mockSMSGateway(sms_allow_unlink=True, nbr_t_error={
|
||||
'+32456000011': 'wrong_number_format',
|
||||
'+32456000022': 'wrong_number_format',
|
||||
}):
|
||||
}):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send(unlink_failed=False, unlink_sent=False, raise_exception=False)
|
||||
self.assertEqual(len(self.sms_all.exists()), 10)
|
||||
success_sms = self.sms_all[:1] + self.sms_all[3:]
|
||||
error_sms = self.sms_all[1:3]
|
||||
self.assertTrue(all(sms.state == 'sent') for sms in success_sms)
|
||||
self.assertTrue(all(sms.state == 'error') for sms in error_sms)
|
||||
self.assertEqual(set(success_sms.mapped('state')), {'pending'})
|
||||
self.assertEqual(set(error_sms.mapped('state')), {'error'})
|
||||
|
||||
def test_sms_send_delete_sent(self):
|
||||
with self.mockSMSGateway(sms_allow_unlink=True, nbr_t_error={
|
||||
'+32456000011': 'wrong_number_format',
|
||||
'+32456000022': 'wrong_number_format',
|
||||
}):
|
||||
}):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send(unlink_failed=False, unlink_sent=True, raise_exception=False)
|
||||
remaining = self.sms_all.exists()
|
||||
remaining = self.sms_all.exists().filtered(lambda s: not s.to_delete)
|
||||
self.assertEqual(len(remaining), 2)
|
||||
self.assertTrue(all(sms.state == 'error') for sms in remaining)
|
||||
self.assertEqual(set(remaining.mapped('state')), {'error'})
|
||||
|
||||
def test_sms_send_raise(self):
|
||||
with self.assertRaises(exceptions.AccessError):
|
||||
with self.mockSMSGateway(sim_error='jsonrpc_exception'):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send(raise_exception=True)
|
||||
self.assertEqual(set(self.sms_all.mapped('state')), set(['outgoing']))
|
||||
self.assertEqual(set(self.sms_all.mapped('state')), {'outgoing'})
|
||||
|
||||
def test_sms_send_raise_catch(self):
|
||||
with self.mockSMSGateway(sim_error='jsonrpc_exception'):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send(raise_exception=False)
|
||||
self.assertEqual(set(self.sms_all.mapped('state')), set(['error']))
|
||||
self.assertEqual(set(self.sms_all.mapped('state')), {'error'})
|
||||
|
||||
def test_sms_send_to_process(self):
|
||||
with self.mockSMSGateway(moderated=True):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send(raise_exception=False)
|
||||
self.assertEqual(set(self.sms_all.mapped('state')), {'process'})
|
||||
|
||||
def test_sms_send_to_unknown_error(self):
|
||||
with self.mockSMSGateway(sim_error='something_new'):
|
||||
self.env['sms.sms'].browse(self.sms_all.ids).send()
|
||||
self.assertEqual(set(self.sms_all.mapped('state')), {'error'})
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
|
||||
from odoo.addons.sms.tests.common import SMSCommon
|
||||
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
|
||||
|
||||
|
||||
class TestSmsTemplate(TestSMSCommon, TestSMSRecipients):
|
||||
class TestSmsTemplate(SMSCommon, TestSMSRecipients):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
@ -60,7 +61,7 @@ class TestSmsTemplate(TestSMSCommon, TestSMSRecipients):
|
|||
self.assertTrue(False)
|
||||
|
||||
tpl_to_rids = self.sms_template._classify_per_lang((self.test_record | test_record_2).ids)
|
||||
for lang, (tpl, rids) in tpl_to_rids.items():
|
||||
for lang, (_tpl, rids) in tpl_to_rids.items():
|
||||
# TDE FIXME: False or en_US ?
|
||||
if lang == 'en_US':
|
||||
self.assertEqual(rids, self.test_record.ids)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue