Remove mmg & firetext from test_send_to_providers

This commit is contained in:
Ryan Ahearn
2022-12-20 10:36:58 -05:00
parent 041cd08097
commit b4a05d6ae7

View File

@@ -6,9 +6,11 @@ from unittest.mock import ANY
import pytest
from flask import current_app
# from notifications_utils.recipients import validate_and_format_phone_number
from requests import HTTPError
import app
# from app import firetext_client, mmg_client, notification_provider_clients
from app import aws_sns_client, notification_provider_clients
from app.dao import notifications_dao
from app.dao.provider_details_dao import get_provider_details_by_identifier
from app.delivery import send_to_providers
@@ -25,16 +27,16 @@ from app.models import (
Notification,
)
from app.serialised_models import SerialisedService
from tests.app.db import ( # create_service,; create_service_with_defined_sms_sender,; create_template,
from tests.app.db import (
create_email_branding,
create_notification,
create_reply_to_email,
create_service,
create_service_sms_sender,
create_service_with_defined_sms_sender,
create_template,
)
# from notifications_utils.recipients import validate_and_format_phone_number
# from requests import HTTPError
def setup_function(_function):
# pytest will run this function before each test. It makes sure the
@@ -42,21 +44,21 @@ def setup_function(_function):
send_to_providers.provider_cache.clear()
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
@pytest.mark.skip(reason="Reenable when we have more than 1 SMS provider")
def test_provider_to_use_should_return_random_provider(mocker, notify_db_session):
mmg = get_provider_details_by_identifier('mmg')
firetext = get_provider_details_by_identifier('firetext')
mmg.priority = 25
firetext.priority = 75
mock_choices = mocker.patch('app.delivery.send_to_providers.random.choices', return_value=[mmg])
sns = get_provider_details_by_identifier('sns')
other = get_provider_details_by_identifier('other')
sns.priority = 60
other.priority = 40
mock_choices = mocker.patch('app.delivery.send_to_providers.random.choices', return_value=[sns])
ret = send_to_providers.provider_to_use('sms', international=False)
ret = send_to_providers.provider_to_use('sms', international=True)
mock_choices.assert_called_once_with([mmg, firetext], weights=[25, 75])
assert ret.name == 'mmg'
mock_choices.assert_called_once_with([sns, other], weights=[60, 40])
assert ret.name == 'sns'
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
@pytest.mark.skip(reason="Reenable when we have more than 1 SMS provider")
def test_provider_to_use_should_cache_repeated_calls(mocker, notify_db_session):
mock_choices = mocker.patch(
'app.delivery.send_to_providers.random.choices',
@@ -72,85 +74,78 @@ def test_provider_to_use_should_cache_repeated_calls(mocker, notify_db_session):
assert len(mock_choices.call_args_list) == 1
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
@pytest.mark.parametrize('international_provider_priority', (
# Since theres only one international provider it should always
# be used, no matter what its priority is set to
0, 50, 100,
))
def test_provider_to_use_should_only_return_mmg_for_international(
def test_provider_to_use_should_only_return_sns_for_international(
mocker,
notify_db_session,
international_provider_priority,
):
mmg = get_provider_details_by_identifier('mmg')
mmg.priority = international_provider_priority
mock_choices = mocker.patch('app.delivery.send_to_providers.random.choices', return_value=[mmg])
sns = get_provider_details_by_identifier('sns')
sns.priority = international_provider_priority
ret = send_to_providers.provider_to_use('sms', international=True)
mock_choices.assert_called_once_with([mmg], weights=[100])
assert ret.name == 'mmg'
assert ret.name == 'sns'
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
@pytest.mark.skip(reason="Reenable when we have more than 1 SMS provider")
def test_provider_to_use_should_only_return_active_providers(mocker, restore_provider_details):
mmg = get_provider_details_by_identifier('mmg')
firetext = get_provider_details_by_identifier('firetext')
mmg.active = False
mock_choices = mocker.patch('app.delivery.send_to_providers.random.choices', return_value=[firetext])
sns = get_provider_details_by_identifier('sns')
other = get_provider_details_by_identifier('other')
sns.active = False
other.active = True
ret = send_to_providers.provider_to_use('sms')
mock_choices.assert_called_once_with([firetext], weights=[100])
assert ret.name == 'firetext'
assert ret.name == 'other'
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_provider_to_use_raises_if_no_active_providers(mocker, restore_provider_details):
mmg = get_provider_details_by_identifier('mmg')
mmg.active = False
sns = get_provider_details_by_identifier('sns')
sns.active = False
with pytest.raises(Exception):
send_to_providers.provider_to_use('sms', international=True)
send_to_providers.provider_to_use('sms')
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
# sample_sms_template_with_html,
# mocker
# ):
# db_notification = create_notification(template=sample_sms_template_with_html,
# to_field="+447234123123", personalisation={"name": "Jo"},
# status='created',
# reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender(),
# normalised_to="447234123123"
# )
def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
sample_sms_template_with_html,
mocker
):
db_notification = create_notification(template=sample_sms_template_with_html,
to_field="5558675309", personalisation={"name": "Jo"},
status='created',
reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender(),
normalised_to="5558675309"
)
# mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.aws_sns_client.send_sms')
# send_to_providers.send_sms_to_provider(
# db_notification
# )
send_to_providers.send_sms_to_provider(
db_notification
)
# mmg_client.send_sms.assert_called_once_with(
# to="447234123123",
# content="Sample service: Hello Jo\nHere is <em>some HTML</em> & entities",
# reference=str(db_notification.id),
# sender=current_app.config['FROM_NUMBER'],
# international=False
# )
aws_sns_client.send_sms.assert_called_once_with(
to="5558675309",
content="Sample service: Hello Jo\nHere is <em>some HTML</em> & entities",
reference=str(db_notification.id),
sender=current_app.config['FROM_NUMBER'],
international=False
)
# notification = Notification.query.filter_by(id=db_notification.id).one()
notification = Notification.query.filter_by(id=db_notification.id).one()
# assert notification.status == 'sending'
# assert notification.sent_at <= datetime.utcnow()
# assert notification.sent_by == 'mmg'
# assert notification.billable_units == 1
# assert notification.personalisation == {"name": "Jo"}
assert notification.status == 'sent'
assert notification.sent_at <= datetime.utcnow()
assert notification.sent_by == 'sns'
assert notification.billable_units == 1
assert notification.personalisation == {"name": "Jo"}
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_should_send_personalised_template_to_correct_email_provider_and_persist(
sample_email_template_with_html,
mocker
@@ -169,7 +164,7 @@ def test_should_send_personalised_template_to_correct_email_provider_and_persist
)
app.aws_ses_client.send_email.assert_called_once_with(
'"Sample service" <sample.service@test.notify.com>',
'"Sample service" <sample.service@notify.sandbox.10x.gsa.gov>',
'jo.smith@example.com',
'Jo <em>some HTML</em>',
body='Hello Jo\nThis is an email from GOV.\u200bUK with <em>some HTML</em>\n',
@@ -187,7 +182,6 @@ def test_should_send_personalised_template_to_correct_email_provider_and_persist
assert notification.personalisation == {"name": "Jo"}
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_should_not_send_email_message_when_service_is_inactive_notifcation_is_in_tech_failure(
sample_service, sample_notification, mocker
):
@@ -201,12 +195,10 @@ def test_should_not_send_email_message_when_service_is_inactive_notifcation_is_i
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
@pytest.mark.parametrize("client_send", ["app.mmg_client.send_sms", "app.firetext_client.send_sms"])
def test_should_not_send_sms_message_when_service_is_inactive_notification_is_in_tech_failure(
sample_service, sample_notification, mocker, client_send):
sample_service, sample_notification, mocker):
sample_service.active = False
send_mock = mocker.patch(client_send, return_value='reference')
send_mock = mocker.patch("app.aws_sns_client.send_sms", return_value='reference')
with pytest.raises(NotificationTechnicalFailureException) as e:
send_to_providers.send_sms_to_provider(sample_notification)
@@ -215,153 +207,148 @@ def test_should_not_send_sms_message_when_service_is_inactive_notification_is_in
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# def test_send_sms_should_use_template_version_from_notification_not_latest(
# sample_template,
# mocker):
# db_notification = create_notification(template=sample_template, to_field='+447234123123', status='created',
# reply_to_text=sample_template.service.get_default_sms_sender(),
# normalised_to='447234123123')
def test_send_sms_should_use_template_version_from_notification_not_latest(
sample_template,
mocker):
db_notification = create_notification(template=sample_template, to_field='5558675309', status='created',
reply_to_text=sample_template.service.get_default_sms_sender(),
normalised_to='5558675309')
# mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.aws_sns_client.send_sms')
# version_on_notification = sample_template.version
# expected_template_id = sample_template.id
version_on_notification = sample_template.version
expected_template_id = sample_template.id
# # Change the template
# from app.dao.templates_dao import (
# dao_get_template_by_id,
# dao_update_template,
# )
# sample_template.content = sample_template.content + " another version of the template"
# dao_update_template(sample_template)
# t = dao_get_template_by_id(sample_template.id)
# assert t.version > version_on_notification
# Change the template
from app.dao.templates_dao import (
dao_get_template_by_id,
dao_update_template,
)
sample_template.content = sample_template.content + " another version of the template"
dao_update_template(sample_template)
t = dao_get_template_by_id(sample_template.id)
assert t.version > version_on_notification
# send_to_providers.send_sms_to_provider(
# db_notification
# )
send_to_providers.send_sms_to_provider(
db_notification
)
# mmg_client.send_sms.assert_called_once_with(
# to=validate_and_format_phone_number("+447234123123"),
# content="Sample service: This is a template:\nwith a newline",
# reference=str(db_notification.id),
# sender=current_app.config['FROM_NUMBER'],
# international=False
# )
aws_sns_client.send_sms.assert_called_once_with(
to="5558675309",
content="Sample service: This is a template:\nwith a newline",
reference=str(db_notification.id),
sender=current_app.config['FROM_NUMBER'],
international=False
)
# t = dao_get_template_by_id(expected_template_id)
t = dao_get_template_by_id(expected_template_id)
# persisted_notification = notifications_dao.get_notification_by_id(db_notification.id)
# assert persisted_notification.to == db_notification.to
# assert persisted_notification.template_id == expected_template_id
# assert persisted_notification.template_version == version_on_notification
# assert persisted_notification.template_version != t.version
# assert persisted_notification.status == 'sending'
# assert not persisted_notification.personalisation
persisted_notification = notifications_dao.get_notification_by_id(db_notification.id)
assert persisted_notification.to == db_notification.to
assert persisted_notification.template_id == expected_template_id
assert persisted_notification.template_version == version_on_notification
assert persisted_notification.template_version != t.version
assert persisted_notification.status == 'sent'
assert not persisted_notification.personalisation
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# @pytest.mark.parametrize('research_mode,key_type', [
# (True, KEY_TYPE_NORMAL),
# (False, KEY_TYPE_TEST)
# ])
# def test_should_call_send_sms_response_task_if_research_mode(
# notify_db_session, sample_service, sample_notification, mocker, research_mode, key_type
# ):
# mocker.patch('app.mmg_client.send_sms')
# mocker.patch('app.delivery.send_to_providers.send_sms_response')
@pytest.mark.parametrize('research_mode,key_type', [
(True, KEY_TYPE_NORMAL),
(False, KEY_TYPE_TEST)
])
def test_should_call_send_sms_response_task_if_research_mode(
notify_db_session, sample_service, sample_notification, mocker, research_mode, key_type
):
mocker.patch('app.aws_sns_client.send_sms')
mocker.patch('app.delivery.send_to_providers.send_sms_response')
# if research_mode:
# sample_service.research_mode = True
# notify_db_session.add(sample_service)
# notify_db_session.commit()
if research_mode:
sample_service.research_mode = True
notify_db_session.add(sample_service)
notify_db_session.commit()
# sample_notification.key_type = key_type
sample_notification.key_type = key_type
# send_to_providers.send_sms_to_provider(
# sample_notification
# )
# assert not mmg_client.send_sms.called
send_to_providers.send_sms_to_provider(
sample_notification
)
assert not aws_sns_client.send_sms.called
# app.delivery.send_to_providers.send_sms_response.assert_called_once_with(
# 'mmg', str(sample_notification.id), sample_notification.to
# )
app.delivery.send_to_providers.send_sms_response.assert_called_once_with(
'sns', str(sample_notification.id), sample_notification.to
)
# persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
# assert persisted_notification.to == sample_notification.to
# assert persisted_notification.template_id == sample_notification.template_id
# assert persisted_notification.status == 'sending'
# assert persisted_notification.sent_at <= datetime.utcnow()
# assert persisted_notification.sent_by == 'mmg'
# assert not persisted_notification.personalisation
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
assert persisted_notification.to == sample_notification.to
assert persisted_notification.template_id == sample_notification.template_id
assert persisted_notification.status == 'sent'
assert persisted_notification.sent_at <= datetime.utcnow()
assert persisted_notification.sent_by == 'sns'
assert not persisted_notification.personalisation
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# def test_should_have_sending_status_if_fake_callback_function_fails(sample_notification, mocker):
# mocker.patch('app.delivery.send_to_providers.send_sms_response', side_effect=HTTPError)
@pytest.mark.skip(reason="Needs updating when we get SMS delivery receipts done")
def test_should_have_sending_status_if_fake_callback_function_fails(sample_notification, mocker):
mocker.patch('app.delivery.send_to_providers.send_sms_response', side_effect=HTTPError)
# sample_notification.key_type = KEY_TYPE_TEST
sample_notification.key_type = KEY_TYPE_TEST
# with pytest.raises(HTTPError):
# send_to_providers.send_sms_to_provider(
# sample_notification
# )
# assert sample_notification.status == 'sending'
# assert sample_notification.sent_by == 'mmg'
with pytest.raises(HTTPError):
send_to_providers.send_sms_to_provider(
sample_notification
)
assert sample_notification.status == 'sending'
assert sample_notification.sent_by == 'sns'
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# def test_should_not_send_to_provider_when_status_is_not_created(
# sample_template,
# mocker
# ):
# notification = create_notification(template=sample_template, status='sending')
# mocker.patch('app.mmg_client.send_sms')
# response_mock = mocker.patch('app.delivery.send_to_providers.send_sms_response')
def test_should_not_send_to_provider_when_status_is_not_created(
sample_template,
mocker
):
notification = create_notification(template=sample_template, status='sending')
mocker.patch('app.aws_sns_client.send_sms')
response_mock = mocker.patch('app.delivery.send_to_providers.send_sms_response')
# send_to_providers.send_sms_to_provider(
# notification
# )
send_to_providers.send_sms_to_provider(
notification
)
# app.mmg_client.send_sms.assert_not_called()
# response_mock.assert_not_called()
app.aws_sns_client.send_sms.assert_not_called()
response_mock.assert_not_called()
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
# # é, o, and u are in GSM.
# # ī, grapes, tabs, zero width space and ellipsis are not
# # ó isn't in GSM, but it is in the welsh alphabet so will still be sent
# msg = "a é ī o u 🍇 foo\tbar\u200bbaz((misc))…"
# placeholder = '∆∆∆abc'
# gsm_message = "?ódz Housing Service: a é i o u ? foo barbaz???abc..."
# service = create_service(service_name='Łódź Housing Service')
# template = create_template(service, content=msg)
# db_notification = create_notification(
# template=template,
# personalisation={'misc': placeholder}
# )
def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
# é, o, and u are in GSM.
# ī, grapes, tabs, zero width space and ellipsis are not
# ó isn't in GSM, but it is in the welsh alphabet so will still be sent
msg = "a é ī o u 🍇 foo\tbar\u200bbaz((misc))…"
placeholder = '∆∆∆abc'
gsm_message = "?ódz Housing Service: a é i o u ? foo barbaz???abc..."
service = create_service(service_name='Łódź Housing Service')
template = create_template(service, content=msg)
db_notification = create_notification(
template=template,
personalisation={'misc': placeholder}
)
# mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.aws_sns_client.send_sms')
# send_to_providers.send_sms_to_provider(db_notification)
send_to_providers.send_sms_to_provider(db_notification)
# mmg_client.send_sms.assert_called_once_with(
# to=ANY,
# content=gsm_message,
# reference=ANY,
# sender=ANY,
# international=False
# )
aws_sns_client.send_sms.assert_called_once_with(
to=ANY,
content=gsm_message,
reference=ANY,
sender=ANY,
international=False
)
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_send_sms_should_use_service_sms_sender(
sample_service,
sample_template,
mocker):
mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.aws_sns_client.send_sms')
sms_sender = create_service_sms_sender(service=sample_service, sms_sender='123456', is_default=False)
db_notification = create_notification(template=sample_template, reply_to_text=sms_sender.sms_sender)
@@ -371,7 +358,7 @@ def test_send_sms_should_use_service_sms_sender(
db_notification,
)
app.mmg_client.send_sms.assert_called_once_with(
app.aws_sns_client.send_sms.assert_called_once_with(
to=ANY,
content=ANY,
reference=ANY,
@@ -380,7 +367,6 @@ def test_send_sms_should_use_service_sms_sender(
)
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
@pytest.mark.parametrize('research_mode,key_type', [
(True, KEY_TYPE_NORMAL),
(False, KEY_TYPE_TEST)
@@ -421,7 +407,6 @@ def test_send_email_to_provider_should_call_research_mode_task_response_task_if_
assert persisted_notification.billable_units == 0
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_send_email_to_provider_should_not_send_to_provider_when_status_is_not_created(
sample_email_template,
mocker
@@ -437,7 +422,6 @@ def test_send_email_to_provider_should_not_send_to_provider_when_status_is_not_c
app.delivery.send_to_providers.send_email_response.assert_not_called()
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_send_email_should_use_service_reply_to_email(
sample_service,
sample_email_template,
@@ -461,7 +445,6 @@ def test_send_email_should_use_service_reply_to_email(
)
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_get_html_email_renderer_should_return_for_normal_service(sample_service):
options = send_to_providers.get_html_email_options(sample_service)
assert options['govuk_banner'] is True
@@ -512,7 +495,6 @@ def test_get_html_email_renderer_with_branding_details_and_render_govuk_banner_o
assert options == {'govuk_banner': True, 'brand_banner': False}
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_get_html_email_renderer_prepends_logo_path(notify_api):
Service = namedtuple('Service', ['email_branding'])
EmailBranding = namedtuple('EmailBranding', ['brand_type', 'colour', 'name', 'logo', 'text'])
@@ -593,22 +575,21 @@ def test_should_not_update_notification_if_research_mode_on_exception(
assert update_mock.called
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# @pytest.mark.parametrize("starting_status, expected_status", [
# ("delivered", "delivered"),
# ("created", "sending"),
# ("technical-failure", "technical-failure"),
# ])
# def test_update_notification_to_sending_does_not_update_status_from_a_final_status(
# sample_service, notify_db_session, starting_status, expected_status
# ):
# template = create_template(sample_service)
# notification = create_notification(template=template, status=starting_status)
# send_to_providers.update_notification_to_sending(
# notification,
# notification_provider_clients.get_client_by_name_and_type("mmg", "sms")
# )
# assert notification.status == expected_status
@pytest.mark.parametrize("starting_status, expected_status", [
("delivered", "delivered"),
("created", "sent"),
("technical-failure", "technical-failure"),
])
def test_update_notification_to_sending_does_not_update_status_from_a_final_status(
sample_service, notify_db_session, starting_status, expected_status
):
template = create_template(sample_service)
notification = create_notification(template=template, status=starting_status)
send_to_providers.update_notification_to_sending(
notification,
notification_provider_clients.get_client_by_name_and_type("sns", "sms")
)
assert notification.status == expected_status
def __update_notification(notification_to_update, research_mode, expected_status):
@@ -616,14 +597,13 @@ def __update_notification(notification_to_update, research_mode, expected_status
notification_to_update.status = expected_status
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
@pytest.mark.parametrize('research_mode,key_type, billable_units, expected_status', [
(True, KEY_TYPE_NORMAL, 0, 'delivered'),
(False, KEY_TYPE_NORMAL, 1, 'sending'),
(False, KEY_TYPE_NORMAL, 1, 'sent'),
(False, KEY_TYPE_TEST, 0, 'sending'),
(True, KEY_TYPE_TEST, 0, 'sending'),
(True, KEY_TYPE_TEAM, 0, 'delivered'),
(False, KEY_TYPE_TEAM, 1, 'sending')
(False, KEY_TYPE_TEAM, 1, 'sent')
])
def test_should_update_billable_units_and_status_according_to_research_mode_and_key_type(
sample_template,
@@ -634,7 +614,7 @@ def test_should_update_billable_units_and_status_according_to_research_mode_and_
expected_status
):
notification = create_notification(template=sample_template, billable_units=0, status='created', key_type=key_type)
mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.aws_sns_client.send_sms')
mocker.patch('app.delivery.send_to_providers.send_sms_response',
side_effect=__update_notification(notification, research_mode, expected_status))
@@ -648,12 +628,11 @@ def test_should_update_billable_units_and_status_according_to_research_mode_and_
assert notification.status == expected_status
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_should_set_notification_billable_units_and_reduces_provider_priority_if_sending_to_provider_fails(
sample_notification,
mocker,
):
mocker.patch('app.mmg_client.send_sms', side_effect=Exception())
mocker.patch('app.aws_sns_client.send_sms', side_effect=Exception())
mock_reduce = mocker.patch('app.delivery.send_to_providers.dao_reduce_sms_provider_priority')
sample_notification.billable_units = 0
@@ -663,119 +642,73 @@ def test_should_set_notification_billable_units_and_reduces_provider_priority_if
send_to_providers.send_sms_to_provider(sample_notification)
assert sample_notification.billable_units == 1
mock_reduce.assert_called_once_with('mmg', time_threshold=timedelta(minutes=1))
mock_reduce.assert_called_once_with('sns', time_threshold=timedelta(minutes=1))
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# def test_should_send_sms_to_international_providers(
# sample_template,
# sample_user,
# mocker
# ):
# mocker.patch('app.mmg_client.send_sms')
# mocker.patch('app.firetext_client.send_sms')
def test_should_send_sms_to_international_providers(
sample_template,
sample_user,
mocker
):
mocker.patch('app.aws_sns_client.send_sms')
# # set firetext to active
# get_provider_details_by_identifier('firetext').priority = 100
# get_provider_details_by_identifier('mmg').priority = 0
notification_international = create_notification(
template=sample_template,
to_field="+6011-17224412",
personalisation={"name": "Jo"},
status='created',
international=True,
reply_to_text=sample_template.service.get_default_sms_sender(),
normalised_to='601117224412'
)
# notification_international = create_notification(
# template=sample_template,
# to_field="+6011-17224412",
# personalisation={"name": "Jo"},
# status='created',
# international=True,
# reply_to_text=sample_template.service.get_default_sms_sender(),
# normalised_to='601117224412'
# )
send_to_providers.send_sms_to_provider(
notification_international
)
# send_to_providers.send_sms_to_provider(
# notification_international
# )
aws_sns_client.send_sms.assert_called_once_with(
to="601117224412",
content=ANY,
reference=str(notification_international.id),
sender=current_app.config['FROM_NUMBER'],
international=True
)
# mmg_client.send_sms.assert_called_once_with(
# to="601117224412",
# content=ANY,
# reference=str(notification_international.id),
# sender=current_app.config['FROM_NUMBER'],
# international=True
# )
# assert notification_international.status == 'sent'
# assert notification_international.sent_by == 'mmg'
assert notification_international.status == 'sent'
assert notification_international.sent_by == 'sns'
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# def test_should_send_non_international_sms_to_default_provider(
# sample_template,
# sample_user,
# mocker
# ):
# mocker.patch('app.mmg_client.send_sms')
# mocker.patch('app.firetext_client.send_sms')
@pytest.mark.parametrize('sms_sender, expected_sender, prefix_sms, expected_content', [
('foo', 'foo', False, 'bar'),
('foo', 'foo', True, 'Sample service: bar'),
# if 40604 is actually in DB then treat that as if entered manually
('40604', '40604', False, 'bar'),
# 'testing' is the FROM_NUMBER during unit tests
('testing', 'testing', True, 'Sample service: bar'),
('testing', 'testing', False, 'bar'),
])
def test_should_handle_sms_sender_and_prefix_message(
mocker,
sms_sender,
prefix_sms,
expected_sender,
expected_content,
notify_db_session
):
mocker.patch('app.aws_sns_client.send_sms')
service = create_service_with_defined_sms_sender(sms_sender_value=sms_sender, prefix_sms=prefix_sms)
template = create_template(service, content='bar')
notification = create_notification(template, reply_to_text=sms_sender)
# # set firetext to active
# get_provider_details_by_identifier('firetext').priority = 100
# get_provider_details_by_identifier('mmg').priority = 0
send_to_providers.send_sms_to_provider(notification)
# notification_uk = create_notification(
# template=sample_template,
# to_field="+447234123999",
# personalisation={"name": "Jo"},
# status='created',
# international=False,
# reply_to_text=sample_template.service.get_default_sms_sender(),
# normalised_to="447234123999"
# )
# send_to_providers.send_sms_to_provider(
# notification_uk
# )
# firetext_client.send_sms.assert_called_once_with(
# to="447234123999",
# content=ANY,
# reference=str(notification_uk.id),
# sender=current_app.config['FROM_NUMBER'],
# international=False
# )
# assert notification_uk.status == 'sending'
# assert notification_uk.sent_by == 'firetext'
# @pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
# @pytest.mark.parametrize('sms_sender, expected_sender, prefix_sms, expected_content', [
# ('foo', 'foo', False, 'bar'),
# ('foo', 'foo', True, 'Sample service: bar'),
# # if 40604 is actually in DB then treat that as if entered manually
# ('40604', '40604', False, 'bar'),
# # 'testing' is the FROM_NUMBER during unit tests
# ('testing', 'testing', True, 'Sample service: bar'),
# ('testing', 'testing', False, 'bar'),
# ])
# def test_should_handle_sms_sender_and_prefix_message(
# mocker,
# sms_sender,
# prefix_sms,
# expected_sender,
# expected_content,
# notify_db_session
# ):
# mocker.patch('app.mmg_client.send_sms')
# service = create_service_with_defined_sms_sender(sms_sender_value=sms_sender, prefix_sms=prefix_sms)
# template = create_template(service, content='bar')
# notification = create_notification(template, reply_to_text=sms_sender)
# send_to_providers.send_sms_to_provider(notification)
# mmg_client.send_sms.assert_called_once_with(
# content=expected_content,
# sender=expected_sender,
# to=ANY,
# reference=ANY,
# international=False
# )
aws_sns_client.send_sms.assert_called_once_with(
content=expected_content,
sender=expected_sender,
to=ANY,
reference=ANY,
international=False
)
def test_send_email_to_provider_uses_reply_to_from_notification(
@@ -799,14 +732,13 @@ def test_send_email_to_provider_uses_reply_to_from_notification(
)
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_send_sms_to_provider_should_use_normalised_to(
mocker, client, sample_template
):
send_mock = mocker.patch('app.mmg_client.send_sms')
send_mock = mocker.patch('app.aws_sns_client.send_sms')
notification = create_notification(template=sample_template,
to_field='+447700900855',
normalised_to='447700900855')
to_field='+15558675309',
normalised_to='5558675309')
send_to_providers.send_sms_to_provider(notification)
send_mock.assert_called_once_with(to=notification.normalised_to,
content=ANY,
@@ -832,7 +764,6 @@ def test_send_email_to_provider_should_user_normalised_to(
reply_to_address=notification.reply_to_text)
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
def test_send_sms_to_provider_should_return_template_if_found_in_redis(
mocker, client, sample_template
):
@@ -854,7 +785,7 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
'app.dao.services_dao.dao_fetch_service_by_id'
)
send_mock = mocker.patch('app.mmg_client.send_sms')
send_mock = mocker.patch('app.aws_sns_client.send_sms')
notification = create_notification(template=sample_template,
to_field='+447700900855',
normalised_to='447700900855')