2016-09-20 17:24:28 +01:00
|
|
|
import uuid
|
2016-12-21 16:15:18 +00:00
|
|
|
from collections import namedtuple
|
2019-11-20 17:23:39 +00:00
|
|
|
from datetime import datetime, timedelta
|
2018-03-01 16:52:52 +00:00
|
|
|
from unittest.mock import ANY
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
import pytest
|
2017-05-22 15:58:19 +01:00
|
|
|
from flask import current_app
|
2017-11-27 15:24:16 +00:00
|
|
|
from notifications_utils.recipients import validate_and_format_phone_number
|
2017-10-16 15:33:21 +01:00
|
|
|
from requests import HTTPError
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
import app
|
2020-11-17 12:35:18 +00:00
|
|
|
from app import notification_provider_clients, mmg_client, firetext_client
|
2019-11-13 11:28:54 +00:00
|
|
|
from app.dao import notifications_dao
|
2019-11-11 14:47:20 +00:00
|
|
|
from app.dao.provider_details_dao import get_provider_details_by_identifier
|
2016-09-20 17:24:28 +01:00
|
|
|
from app.delivery import send_to_providers
|
2018-03-16 17:18:44 +00:00
|
|
|
from app.exceptions import NotificationTechnicalFailureException
|
2017-02-16 11:55:52 +00:00
|
|
|
from app.models import (
|
|
|
|
|
Notification,
|
2018-02-05 12:02:35 +00:00
|
|
|
EmailBranding,
|
2017-02-16 11:55:52 +00:00
|
|
|
KEY_TYPE_NORMAL,
|
|
|
|
|
KEY_TYPE_TEST,
|
|
|
|
|
KEY_TYPE_TEAM,
|
|
|
|
|
BRANDING_ORG,
|
2017-09-19 13:18:59 +01:00
|
|
|
BRANDING_BOTH,
|
2017-10-06 17:08:06 +01:00
|
|
|
BRANDING_ORG_BANNER
|
|
|
|
|
)
|
|
|
|
|
from tests.app.db import (
|
|
|
|
|
create_service,
|
|
|
|
|
create_template,
|
|
|
|
|
create_notification,
|
|
|
|
|
create_reply_to_email,
|
2017-11-07 14:26:18 +00:00
|
|
|
create_service_sms_sender,
|
|
|
|
|
create_service_with_defined_sms_sender
|
|
|
|
|
)
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
2020-12-31 09:36:55 +00:00
|
|
|
def setup_function(_function):
|
|
|
|
|
# pytest will run this function before each test. It makes sure the
|
|
|
|
|
# state of the cache is not shared between tests.
|
|
|
|
|
send_to_providers.provider_cache.clear()
|
|
|
|
|
|
|
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
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])
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
ret = send_to_providers.provider_to_use('sms', international=False)
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
mock_choices.assert_called_once_with([mmg, firetext], weights=[25, 75])
|
|
|
|
|
assert ret.get_name() == 'mmg'
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
2020-12-23 15:33:27 +00:00
|
|
|
def test_provider_to_use_should_cache_repeated_calls(mocker, notify_db_session):
|
|
|
|
|
mock_choices = mocker.patch(
|
|
|
|
|
'app.delivery.send_to_providers.random.choices',
|
|
|
|
|
wraps=send_to_providers.random.choices,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results = [
|
|
|
|
|
send_to_providers.provider_to_use('sms', international=False)
|
|
|
|
|
for _ in range(10)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
assert all(result == results[0] for result in results)
|
|
|
|
|
assert len(mock_choices.call_args_list) == 1
|
|
|
|
|
|
|
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
def test_provider_to_use_should_only_return_mmg_for_international(mocker, notify_db_session):
|
|
|
|
|
mmg = get_provider_details_by_identifier('mmg')
|
|
|
|
|
mock_choices = mocker.patch('app.delivery.send_to_providers.random.choices', return_value=[mmg])
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
ret = send_to_providers.provider_to_use('sms', international=True)
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
mock_choices.assert_called_once_with([mmg], weights=[100])
|
|
|
|
|
assert ret.get_name() == 'mmg'
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
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])
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
ret = send_to_providers.provider_to_use('sms')
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2019-11-13 11:28:54 +00:00
|
|
|
mock_choices.assert_called_once_with([firetext], weights=[0])
|
|
|
|
|
assert ret.get_name() == 'firetext'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_provider_to_use_raises_if_no_active_providers(mocker, restore_provider_details):
|
|
|
|
|
mmg = get_provider_details_by_identifier('mmg')
|
|
|
|
|
mmg.active = False
|
|
|
|
|
|
|
|
|
|
with pytest.raises(Exception):
|
|
|
|
|
send_to_providers.provider_to_use('sms', international=True)
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
|
2017-01-19 12:05:28 +00:00
|
|
|
sample_sms_template_with_html,
|
2016-09-20 17:24:28 +01:00
|
|
|
mocker
|
|
|
|
|
):
|
2017-02-16 11:55:52 +00:00
|
|
|
db_notification = create_notification(template=sample_sms_template_with_html,
|
2021-02-11 13:51:15 +00:00
|
|
|
to_field="+447234123123",
|
|
|
|
|
normalised_to=validate_and_format_phone_number("+447234123123", True),
|
|
|
|
|
personalisation={"name": "Jo"},
|
2017-11-27 15:24:16 +00:00
|
|
|
status='created',
|
|
|
|
|
reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender())
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
mocker.patch('app.mmg_client.send_sms')
|
|
|
|
|
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
2016-09-22 09:16:58 +01:00
|
|
|
db_notification
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mmg_client.send_sms.assert_called_once_with(
|
2021-02-11 13:51:15 +00:00
|
|
|
to=db_notification.normalised_to,
|
2017-01-19 12:05:28 +00:00
|
|
|
content="Sample service: Hello Jo\nHere is <em>some HTML</em> & entities",
|
2016-09-20 17:24:28 +01:00
|
|
|
reference=str(db_notification.id),
|
2017-05-22 15:58:19 +01:00
|
|
|
sender=current_app.config['FROM_NUMBER']
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
2017-05-09 18:17:55 +01:00
|
|
|
|
2016-09-20 17:24:28 +01:00
|
|
|
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"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_send_personalised_template_to_correct_email_provider_and_persist(
|
2017-01-19 12:05:28 +00:00
|
|
|
sample_email_template_with_html,
|
2016-09-20 17:24:28 +01:00
|
|
|
mocker
|
|
|
|
|
):
|
2017-02-16 11:55:52 +00:00
|
|
|
db_notification = create_notification(
|
2017-01-19 12:05:28 +00:00
|
|
|
template=sample_email_template_with_html,
|
2016-09-20 17:24:28 +01:00
|
|
|
to_field="jo.smith@example.com",
|
2021-02-11 13:51:15 +00:00
|
|
|
normalised_to="jo.smith@example.com",
|
2016-09-20 17:24:28 +01:00
|
|
|
personalisation={'name': 'Jo'}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
|
|
|
|
|
|
|
|
|
send_to_providers.send_email_to_provider(
|
2016-09-22 09:16:58 +01:00
|
|
|
db_notification
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app.aws_ses_client.send_email.assert_called_once_with(
|
|
|
|
|
'"Sample service" <sample.service@test.notify.com>',
|
|
|
|
|
'jo.smith@example.com',
|
2017-01-19 12:05:28 +00:00
|
|
|
'Jo <em>some HTML</em>',
|
2018-04-09 16:30:24 +01:00
|
|
|
body='Hello Jo\nThis is an email from GOV.\u200bUK with <em>some HTML</em>\n',
|
2016-09-20 17:24:28 +01:00
|
|
|
html_body=ANY,
|
|
|
|
|
reply_to_address=None
|
|
|
|
|
)
|
2017-05-09 18:17:55 +01:00
|
|
|
|
2016-09-20 17:24:28 +01:00
|
|
|
assert '<!DOCTYPE html' in app.aws_ses_client.send_email.call_args[1]['html_body']
|
2017-01-19 12:05:28 +00:00
|
|
|
assert '<em>some HTML</em>' in app.aws_ses_client.send_email.call_args[1]['html_body']
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
notification = Notification.query.filter_by(id=db_notification.id).one()
|
|
|
|
|
assert notification.status == 'sending'
|
|
|
|
|
assert notification.sent_at <= datetime.utcnow()
|
|
|
|
|
assert notification.sent_by == 'ses'
|
|
|
|
|
assert notification.personalisation == {"name": "Jo"}
|
|
|
|
|
|
|
|
|
|
|
2017-05-09 18:17:55 +01:00
|
|
|
def test_should_not_send_email_message_when_service_is_inactive_notifcation_is_in_tech_failure(
|
|
|
|
|
sample_service, sample_notification, mocker
|
|
|
|
|
):
|
|
|
|
|
sample_service.active = False
|
|
|
|
|
send_mock = mocker.patch("app.aws_ses_client.send_email", return_value='reference')
|
|
|
|
|
|
2018-03-16 17:18:44 +00:00
|
|
|
with pytest.raises(NotificationTechnicalFailureException) as e:
|
|
|
|
|
send_to_providers.send_email_to_provider(sample_notification)
|
2019-09-13 11:40:05 +01:00
|
|
|
assert str(sample_notification.id) in str(e.value)
|
2017-05-09 18:17:55 +01:00
|
|
|
send_mock.assert_not_called()
|
|
|
|
|
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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_notifcation_is_in_tech_failure(
|
2017-01-31 14:28:25 +00:00
|
|
|
sample_service, sample_notification, mocker, client_send):
|
2017-01-31 13:53:13 +00:00
|
|
|
sample_service.active = False
|
|
|
|
|
send_mock = mocker.patch(client_send, return_value='reference')
|
|
|
|
|
|
2018-03-16 17:18:44 +00:00
|
|
|
with pytest.raises(NotificationTechnicalFailureException) as e:
|
|
|
|
|
send_to_providers.send_sms_to_provider(sample_notification)
|
2019-09-13 11:40:05 +01:00
|
|
|
assert str(sample_notification.id) in str(e.value)
|
2017-01-31 13:53:13 +00:00
|
|
|
send_mock.assert_not_called()
|
2017-01-31 14:28:25 +00:00
|
|
|
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
|
2017-01-31 13:53:13 +00:00
|
|
|
|
|
|
|
|
|
2016-09-20 17:24:28 +01:00
|
|
|
def test_send_sms_should_use_template_version_from_notification_not_latest(
|
|
|
|
|
sample_template,
|
|
|
|
|
mocker):
|
2017-11-27 15:24:16 +00:00
|
|
|
db_notification = create_notification(template=sample_template, to_field='+447234123123', status='created',
|
2021-02-11 13:51:15 +00:00
|
|
|
normalised_to=validate_and_format_phone_number("+447234123123"),
|
2017-11-27 15:24:16 +00:00
|
|
|
reply_to_text=sample_template.service.get_default_sms_sender())
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
mocker.patch('app.mmg_client.send_sms')
|
2017-05-09 18:17:55 +01:00
|
|
|
|
2016-09-20 17:24:28 +01:00
|
|
|
version_on_notification = sample_template.version
|
|
|
|
|
|
|
|
|
|
# Change the template
|
|
|
|
|
from app.dao.templates_dao import dao_update_template, dao_get_template_by_id
|
|
|
|
|
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(
|
2016-09-22 09:16:58 +01:00
|
|
|
db_notification
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mmg_client.send_sms.assert_called_once_with(
|
2021-02-11 13:51:15 +00:00
|
|
|
to=db_notification.normalised_to,
|
2016-09-20 17:24:28 +01:00
|
|
|
content="Sample service: This is a template:\nwith a newline",
|
|
|
|
|
reference=str(db_notification.id),
|
2017-05-22 15:58:19 +01:00
|
|
|
sender=current_app.config['FROM_NUMBER']
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
persisted_notification = notifications_dao.get_notification_by_id(db_notification.id)
|
|
|
|
|
assert persisted_notification.to == db_notification.to
|
|
|
|
|
assert persisted_notification.template_id == sample_template.id
|
|
|
|
|
assert persisted_notification.template_version == version_on_notification
|
|
|
|
|
assert persisted_notification.template_version != sample_template.version
|
|
|
|
|
assert persisted_notification.status == 'sending'
|
|
|
|
|
assert not persisted_notification.personalisation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('research_mode,key_type', [
|
|
|
|
|
(True, KEY_TYPE_NORMAL),
|
|
|
|
|
(False, KEY_TYPE_TEST)
|
|
|
|
|
])
|
2017-05-09 18:17:55 +01:00
|
|
|
def test_should_call_send_sms_response_task_if_research_mode(
|
|
|
|
|
notify_db, sample_service, sample_notification, mocker, research_mode, key_type
|
|
|
|
|
):
|
2016-09-20 17:24:28 +01:00
|
|
|
mocker.patch('app.mmg_client.send_sms')
|
2017-01-24 14:24:58 +00:00
|
|
|
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
if research_mode:
|
|
|
|
|
sample_service.research_mode = True
|
|
|
|
|
notify_db.session.add(sample_service)
|
|
|
|
|
notify_db.session.commit()
|
|
|
|
|
|
|
|
|
|
sample_notification.key_type = key_type
|
|
|
|
|
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
2016-09-22 09:16:58 +01:00
|
|
|
sample_notification
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
assert not mmg_client.send_sms.called
|
2017-05-09 18:17:55 +01:00
|
|
|
|
2017-01-24 14:24:58 +00:00
|
|
|
app.delivery.send_to_providers.send_sms_response.assert_called_once_with(
|
|
|
|
|
'mmg', str(sample_notification.id), sample_notification.to
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2019-05-23 16:40:17 +01:00
|
|
|
def test_should_have_sending_status_if_fake_callback_function_fails(sample_notification, mocker):
|
2017-10-16 15:33:21 +01:00
|
|
|
mocker.patch('app.delivery.send_to_providers.send_sms_response', side_effect=HTTPError)
|
|
|
|
|
|
|
|
|
|
sample_notification.key_type = KEY_TYPE_TEST
|
|
|
|
|
|
|
|
|
|
with pytest.raises(HTTPError):
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
|
|
|
|
sample_notification
|
|
|
|
|
)
|
2019-05-23 16:40:17 +01:00
|
|
|
assert sample_notification.status == 'sending'
|
|
|
|
|
assert sample_notification.sent_by == 'mmg'
|
2017-10-16 15:33:21 +01:00
|
|
|
|
|
|
|
|
|
2017-02-16 11:55:52 +00:00
|
|
|
def test_should_not_send_to_provider_when_status_is_not_created(
|
|
|
|
|
sample_template,
|
|
|
|
|
mocker
|
|
|
|
|
):
|
|
|
|
|
notification = create_notification(template=sample_template, status='sending')
|
2016-09-20 17:24:28 +01:00
|
|
|
mocker.patch('app.mmg_client.send_sms')
|
2017-05-09 18:17:55 +01:00
|
|
|
response_mock = mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
2016-09-22 09:16:58 +01:00
|
|
|
notification
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app.mmg_client.send_sms.assert_not_called()
|
2017-05-09 18:17:55 +01:00
|
|
|
response_mock.assert_not_called()
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
2017-02-16 11:55:52 +00:00
|
|
|
def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
|
|
|
|
|
# é, o, and u are in GSM.
|
2019-11-27 16:29:30 +00:00
|
|
|
# ī, 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))…"
|
2017-02-16 11:55:52 +00:00
|
|
|
placeholder = '∆∆∆abc'
|
2019-11-27 16:29:30 +00:00
|
|
|
gsm_message = "?ódz Housing Service: a é i o u ? foo barbaz???abc..."
|
2017-02-16 11:55:52 +00:00
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2017-10-30 14:55:44 +00:00
|
|
|
def test_send_sms_should_use_service_sms_sender(
|
|
|
|
|
sample_service,
|
|
|
|
|
sample_template,
|
|
|
|
|
mocker):
|
|
|
|
|
mocker.patch('app.mmg_client.send_sms')
|
|
|
|
|
|
|
|
|
|
sms_sender = create_service_sms_sender(service=sample_service, sms_sender='123456', is_default=False)
|
2019-05-08 17:31:27 +01:00
|
|
|
db_notification = create_notification(template=sample_template, reply_to_text=sms_sender.sms_sender)
|
2017-10-30 14:55:44 +00:00
|
|
|
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
|
|
|
|
db_notification,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app.mmg_client.send_sms.assert_called_once_with(
|
|
|
|
|
to=ANY,
|
|
|
|
|
content=ANY,
|
|
|
|
|
reference=ANY,
|
|
|
|
|
sender=sms_sender.sms_sender
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2016-09-20 17:24:28 +01:00
|
|
|
@pytest.mark.parametrize('research_mode,key_type', [
|
|
|
|
|
(True, KEY_TYPE_NORMAL),
|
|
|
|
|
(False, KEY_TYPE_TEST)
|
|
|
|
|
])
|
|
|
|
|
def test_send_email_to_provider_should_call_research_mode_task_response_task_if_research_mode(
|
|
|
|
|
sample_service,
|
|
|
|
|
sample_email_template,
|
|
|
|
|
mocker,
|
|
|
|
|
research_mode,
|
|
|
|
|
key_type):
|
2017-02-16 11:55:52 +00:00
|
|
|
notification = create_notification(
|
|
|
|
|
template=sample_email_template,
|
|
|
|
|
to_field="john@smith.com",
|
2019-05-08 15:55:45 +01:00
|
|
|
key_type=key_type,
|
|
|
|
|
billable_units=0
|
2017-02-16 11:55:52 +00:00
|
|
|
)
|
|
|
|
|
sample_service.research_mode = research_mode
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
reference = uuid.uuid4()
|
|
|
|
|
mocker.patch('app.uuid.uuid4', return_value=reference)
|
|
|
|
|
mocker.patch('app.aws_ses_client.send_email')
|
2017-01-24 14:24:58 +00:00
|
|
|
mocker.patch('app.delivery.send_to_providers.send_email_response')
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
send_to_providers.send_email_to_provider(
|
2016-09-22 09:16:58 +01:00
|
|
|
notification
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
2017-05-09 18:17:55 +01:00
|
|
|
|
2016-09-20 17:24:28 +01:00
|
|
|
assert not app.aws_ses_client.send_email.called
|
2017-11-17 13:41:45 +00:00
|
|
|
app.delivery.send_to_providers.send_email_response.assert_called_once_with(str(reference), 'john@smith.com')
|
2016-09-20 17:24:28 +01:00
|
|
|
persisted_notification = Notification.query.filter_by(id=notification.id).one()
|
|
|
|
|
assert persisted_notification.to == 'john@smith.com'
|
|
|
|
|
assert persisted_notification.template_id == sample_email_template.id
|
|
|
|
|
assert persisted_notification.status == 'sending'
|
|
|
|
|
assert persisted_notification.sent_at <= datetime.utcnow()
|
|
|
|
|
assert persisted_notification.created_at <= datetime.utcnow()
|
|
|
|
|
assert persisted_notification.sent_by == 'ses'
|
|
|
|
|
assert persisted_notification.reference == str(reference)
|
2016-09-23 09:54:53 +01:00
|
|
|
assert persisted_notification.billable_units == 0
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
2017-02-16 11:55:52 +00:00
|
|
|
def test_send_email_to_provider_should_not_send_to_provider_when_status_is_not_created(
|
|
|
|
|
sample_email_template,
|
|
|
|
|
mocker
|
|
|
|
|
):
|
|
|
|
|
notification = create_notification(template=sample_email_template, status='sending')
|
2016-09-20 17:24:28 +01:00
|
|
|
mocker.patch('app.aws_ses_client.send_email')
|
2017-01-24 14:24:58 +00:00
|
|
|
mocker.patch('app.delivery.send_to_providers.send_email_response')
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
2016-09-22 09:16:58 +01:00
|
|
|
notification
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
app.aws_ses_client.send_email.assert_not_called()
|
2017-01-24 14:24:58 +00:00
|
|
|
app.delivery.send_to_providers.send_email_response.assert_not_called()
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_send_email_should_use_service_reply_to_email(
|
|
|
|
|
sample_service,
|
|
|
|
|
sample_email_template,
|
|
|
|
|
mocker):
|
|
|
|
|
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
|
|
|
|
|
2017-11-27 15:24:16 +00:00
|
|
|
db_notification = create_notification(template=sample_email_template, reply_to_text='foo@bar.com')
|
2017-09-20 10:45:35 +01:00
|
|
|
create_reply_to_email(service=sample_service, email_address='foo@bar.com')
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
send_to_providers.send_email_to_provider(
|
2016-09-22 09:16:58 +01:00
|
|
|
db_notification,
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app.aws_ses_client.send_email.assert_called_once_with(
|
|
|
|
|
ANY,
|
|
|
|
|
ANY,
|
|
|
|
|
ANY,
|
|
|
|
|
body=ANY,
|
|
|
|
|
html_body=ANY,
|
2017-11-27 15:24:16 +00:00
|
|
|
reply_to_address='foo@bar.com'
|
2016-09-20 17:24:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_html_email_renderer_should_return_for_normal_service(sample_service):
|
2016-12-09 15:56:25 +00:00
|
|
|
options = send_to_providers.get_html_email_options(sample_service)
|
2018-08-28 14:25:16 +01:00
|
|
|
assert options['govuk_banner'] is True
|
2016-12-09 15:56:25 +00:00
|
|
|
assert 'brand_colour' not in options.keys()
|
|
|
|
|
assert 'brand_logo' not in options.keys()
|
2019-06-25 16:53:07 +01:00
|
|
|
assert 'brand_text' not in options.keys()
|
2016-12-09 15:56:25 +00:00
|
|
|
assert 'brand_name' not in options.keys()
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('branding_type, govuk_banner', [
|
|
|
|
|
(BRANDING_ORG, False),
|
2017-09-19 13:18:59 +01:00
|
|
|
(BRANDING_BOTH, True),
|
|
|
|
|
(BRANDING_ORG_BANNER, False)
|
2016-09-20 17:24:28 +01:00
|
|
|
])
|
|
|
|
|
def test_get_html_email_renderer_with_branding_details(branding_type, govuk_banner, notify_db, sample_service):
|
2018-08-28 14:25:16 +01:00
|
|
|
|
|
|
|
|
email_branding = EmailBranding(
|
|
|
|
|
brand_type=branding_type,
|
|
|
|
|
colour='#000000',
|
|
|
|
|
logo='justice-league.png',
|
|
|
|
|
name='Justice League',
|
|
|
|
|
text='League of Justice',
|
|
|
|
|
)
|
2018-02-05 12:02:35 +00:00
|
|
|
sample_service.email_branding = email_branding
|
|
|
|
|
notify_db.session.add_all([sample_service, email_branding])
|
2016-09-20 17:24:28 +01:00
|
|
|
notify_db.session.commit()
|
|
|
|
|
|
2016-12-09 15:56:25 +00:00
|
|
|
options = send_to_providers.get_html_email_options(sample_service)
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2016-12-09 15:56:25 +00:00
|
|
|
assert options['govuk_banner'] == govuk_banner
|
|
|
|
|
assert options['brand_colour'] == '#000000'
|
2019-06-25 16:53:07 +01:00
|
|
|
assert options['brand_text'] == 'League of Justice'
|
|
|
|
|
assert options['brand_name'] == 'Justice League'
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2018-08-28 14:25:16 +01:00
|
|
|
if branding_type == BRANDING_ORG_BANNER:
|
2017-09-19 13:18:59 +01:00
|
|
|
assert options['brand_banner'] is True
|
|
|
|
|
else:
|
|
|
|
|
assert options['brand_banner'] is False
|
|
|
|
|
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2017-09-14 16:26:46 +01:00
|
|
|
def test_get_html_email_renderer_with_branding_details_and_render_govuk_banner_only(notify_db, sample_service):
|
2018-08-30 16:22:59 +01:00
|
|
|
sample_service.email_branding = None
|
|
|
|
|
notify_db.session.add_all([sample_service])
|
2017-09-14 16:26:46 +01:00
|
|
|
notify_db.session.commit()
|
|
|
|
|
|
|
|
|
|
options = send_to_providers.get_html_email_options(sample_service)
|
|
|
|
|
|
2017-09-19 13:18:59 +01:00
|
|
|
assert options == {'govuk_banner': True, 'brand_banner': False}
|
2017-09-14 16:26:46 +01:00
|
|
|
|
|
|
|
|
|
2016-12-21 16:15:18 +00:00
|
|
|
def test_get_html_email_renderer_prepends_logo_path(notify_api):
|
2018-08-30 15:51:39 +01:00
|
|
|
Service = namedtuple('Service', ['email_branding'])
|
2018-08-28 14:25:16 +01:00
|
|
|
EmailBranding = namedtuple('EmailBranding', ['brand_type', 'colour', 'name', 'logo', 'text'])
|
|
|
|
|
|
|
|
|
|
email_branding = EmailBranding(
|
|
|
|
|
brand_type=BRANDING_ORG,
|
|
|
|
|
colour='#000000',
|
|
|
|
|
logo='justice-league.png',
|
|
|
|
|
name='Justice League',
|
|
|
|
|
text='League of Justice',
|
|
|
|
|
)
|
|
|
|
|
service = Service(
|
|
|
|
|
email_branding=email_branding,
|
|
|
|
|
)
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2016-12-21 16:15:18 +00:00
|
|
|
renderer = send_to_providers.get_html_email_options(service)
|
2016-09-20 17:24:28 +01:00
|
|
|
|
2017-07-21 16:06:12 +01:00
|
|
|
assert renderer['brand_logo'] == 'http://static-logos.notify.tools/justice-league.png'
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
|
2018-02-05 12:02:35 +00:00
|
|
|
def test_get_html_email_renderer_handles_email_branding_without_logo(notify_api):
|
2018-08-30 15:51:39 +01:00
|
|
|
Service = namedtuple('Service', ['email_branding'])
|
2018-08-28 14:25:16 +01:00
|
|
|
EmailBranding = namedtuple('EmailBranding', ['brand_type', 'colour', 'name', 'logo', 'text'])
|
|
|
|
|
|
|
|
|
|
email_branding = EmailBranding(
|
|
|
|
|
brand_type=BRANDING_ORG_BANNER,
|
|
|
|
|
colour='#000000',
|
|
|
|
|
logo=None,
|
|
|
|
|
name='Justice League',
|
|
|
|
|
text='League of Justice',
|
|
|
|
|
)
|
|
|
|
|
service = Service(
|
|
|
|
|
email_branding=email_branding,
|
|
|
|
|
)
|
2017-09-21 13:37:57 +01:00
|
|
|
|
|
|
|
|
renderer = send_to_providers.get_html_email_options(service)
|
|
|
|
|
|
2018-08-28 14:25:16 +01:00
|
|
|
assert renderer['govuk_banner'] is False
|
|
|
|
|
assert renderer['brand_banner'] is True
|
2017-09-21 13:37:57 +01:00
|
|
|
assert renderer['brand_logo'] is None
|
2019-06-25 16:53:07 +01:00
|
|
|
assert renderer['brand_text'] == 'League of Justice'
|
2018-08-28 14:25:16 +01:00
|
|
|
assert renderer['brand_colour'] == '#000000'
|
2019-06-25 16:53:07 +01:00
|
|
|
assert renderer['brand_name'] == 'Justice League'
|
2017-09-21 13:37:57 +01:00
|
|
|
|
|
|
|
|
|
2016-12-21 16:15:18 +00:00
|
|
|
@pytest.mark.parametrize('base_url, expected_url', [
|
|
|
|
|
# don't change localhost to prevent errors when testing locally
|
2017-07-21 16:06:12 +01:00
|
|
|
('http://localhost:6012', 'http://static-logos.notify.tools/filename.png'),
|
|
|
|
|
('https://www.notifications.service.gov.uk', 'https://static-logos.notifications.service.gov.uk/filename.png'),
|
|
|
|
|
('https://notify.works', 'https://static-logos.notify.works/filename.png'),
|
|
|
|
|
('https://staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'),
|
|
|
|
|
('https://www.notify.works', 'https://static-logos.notify.works/filename.png'),
|
|
|
|
|
('https://www.staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'),
|
2016-12-21 16:15:18 +00:00
|
|
|
])
|
|
|
|
|
def test_get_logo_url_works_for_different_environments(base_url, expected_url):
|
|
|
|
|
logo_file = 'filename.png'
|
|
|
|
|
|
2017-07-21 16:06:12 +01:00
|
|
|
logo_url = send_to_providers.get_logo_url(base_url, logo_file)
|
2016-12-21 16:15:18 +00:00
|
|
|
|
|
|
|
|
assert logo_url == expected_url
|
|
|
|
|
|
|
|
|
|
|
2019-05-08 15:45:19 +01:00
|
|
|
def test_should_not_update_notification_if_research_mode_on_exception(
|
|
|
|
|
sample_service, sample_notification, mocker
|
|
|
|
|
):
|
|
|
|
|
mocker.patch('app.delivery.send_to_providers.send_sms_response', side_effect=Exception())
|
|
|
|
|
update_mock = mocker.patch('app.delivery.send_to_providers.update_notification_to_sending')
|
2016-09-20 17:24:28 +01:00
|
|
|
sample_service.research_mode = True
|
2019-05-08 15:45:19 +01:00
|
|
|
sample_notification.billable_units = 0
|
|
|
|
|
|
|
|
|
|
with pytest.raises(Exception):
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
|
|
|
|
sample_notification
|
|
|
|
|
)
|
2016-09-20 17:24:28 +01:00
|
|
|
|
|
|
|
|
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
|
|
|
|
|
assert persisted_notification.billable_units == 0
|
2019-05-23 16:40:17 +01:00
|
|
|
assert update_mock.called
|
|
|
|
|
|
2016-09-23 09:54:53 +01:00
|
|
|
|
2020-07-02 18:22:06 +01:00
|
|
|
@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)
|
2020-11-17 12:35:18 +00:00
|
|
|
send_to_providers.update_notification_to_sending(
|
|
|
|
|
notification,
|
|
|
|
|
notification_provider_clients.get_client_by_name_and_type("mmg", "sms")
|
|
|
|
|
)
|
2020-07-02 18:22:06 +01:00
|
|
|
assert notification.status == expected_status
|
|
|
|
|
|
|
|
|
|
|
2019-05-23 16:40:17 +01:00
|
|
|
def __update_notification(notification_to_update, research_mode, expected_status):
|
|
|
|
|
if research_mode or notification_to_update.key_type == KEY_TYPE_TEST:
|
|
|
|
|
notification_to_update.status = expected_status
|
2016-09-23 09:54:53 +01:00
|
|
|
|
2019-05-23 16:40:17 +01:00
|
|
|
|
|
|
|
|
@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_TEST, 0, 'sending'),
|
|
|
|
|
(True, KEY_TYPE_TEST, 0, 'sending'),
|
|
|
|
|
(True, KEY_TYPE_TEAM, 0, 'delivered'),
|
|
|
|
|
(False, KEY_TYPE_TEAM, 1, 'sending')
|
2016-09-23 09:54:53 +01:00
|
|
|
])
|
2019-05-23 16:40:17 +01:00
|
|
|
def test_should_update_billable_units_and_status_according_to_research_mode_and_key_type(
|
2019-05-08 15:45:19 +01:00
|
|
|
sample_template,
|
2017-05-09 18:17:55 +01:00
|
|
|
mocker,
|
|
|
|
|
research_mode,
|
|
|
|
|
key_type,
|
2019-05-23 16:40:17 +01:00
|
|
|
billable_units,
|
|
|
|
|
expected_status
|
2017-05-09 18:17:55 +01:00
|
|
|
):
|
2019-05-08 15:45:19 +01:00
|
|
|
notification = create_notification(template=sample_template, billable_units=0, status='created', key_type=key_type)
|
2016-09-23 09:54:53 +01:00
|
|
|
mocker.patch('app.mmg_client.send_sms')
|
2019-05-23 16:40:17 +01:00
|
|
|
mocker.patch('app.delivery.send_to_providers.send_sms_response',
|
|
|
|
|
side_effect=__update_notification(notification, research_mode, expected_status))
|
2017-05-09 18:17:55 +01:00
|
|
|
|
2016-09-23 09:54:53 +01:00
|
|
|
if research_mode:
|
2019-05-08 15:45:19 +01:00
|
|
|
sample_template.service.research_mode = True
|
2016-09-23 09:54:53 +01:00
|
|
|
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
2019-05-08 15:45:19 +01:00
|
|
|
notification
|
2016-09-23 09:54:53 +01:00
|
|
|
)
|
2019-05-08 15:45:19 +01:00
|
|
|
assert notification.billable_units == billable_units
|
2019-05-23 16:40:17 +01:00
|
|
|
assert notification.status == expected_status
|
2017-04-27 12:14:22 +01:00
|
|
|
|
|
|
|
|
|
2019-11-20 17:23:39 +00:00
|
|
|
def test_should_set_notification_billable_units_and_reduces_provider_priority_if_sending_to_provider_fails(
|
2019-05-08 10:54:01 +01:00
|
|
|
sample_notification,
|
|
|
|
|
mocker,
|
|
|
|
|
):
|
|
|
|
|
mocker.patch('app.mmg_client.send_sms', side_effect=Exception())
|
2019-11-20 17:23:39 +00:00
|
|
|
mock_reduce = mocker.patch('app.delivery.send_to_providers.dao_reduce_sms_provider_priority')
|
2019-05-08 10:54:01 +01:00
|
|
|
|
|
|
|
|
sample_notification.billable_units = 0
|
|
|
|
|
assert sample_notification.sent_by is None
|
|
|
|
|
|
|
|
|
|
with pytest.raises(Exception):
|
|
|
|
|
send_to_providers.send_sms_to_provider(sample_notification)
|
|
|
|
|
|
|
|
|
|
assert sample_notification.billable_units == 1
|
2019-11-20 17:23:39 +00:00
|
|
|
mock_reduce.assert_called_once_with('mmg', time_threshold=timedelta(minutes=1))
|
2019-05-08 10:54:01 +01:00
|
|
|
|
|
|
|
|
|
2017-04-27 12:14:22 +01:00
|
|
|
def test_should_send_sms_to_international_providers(
|
2019-11-11 14:47:20 +00:00
|
|
|
sample_template,
|
2017-04-27 12:14:22 +01:00
|
|
|
sample_user,
|
|
|
|
|
mocker
|
|
|
|
|
):
|
2019-11-11 14:47:20 +00:00
|
|
|
mocker.patch('app.mmg_client.send_sms')
|
|
|
|
|
mocker.patch('app.firetext_client.send_sms')
|
2017-04-27 12:14:22 +01:00
|
|
|
|
2019-11-11 14:47:20 +00:00
|
|
|
# set firetext to active
|
|
|
|
|
get_provider_details_by_identifier('firetext').priority = 100
|
|
|
|
|
get_provider_details_by_identifier('mmg').priority = 0
|
2017-04-27 12:14:22 +01:00
|
|
|
|
2019-11-11 14:47:20 +00:00
|
|
|
notification_uk = create_notification(
|
|
|
|
|
template=sample_template,
|
2017-04-27 12:14:22 +01:00
|
|
|
to_field="+447234123999",
|
2021-02-11 13:51:15 +00:00
|
|
|
normalised_to=validate_and_format_phone_number("+447234123999", True),
|
2017-04-27 12:14:22 +01:00
|
|
|
personalisation={"name": "Jo"},
|
|
|
|
|
status='created',
|
2017-11-27 15:24:16 +00:00
|
|
|
international=False,
|
2019-11-11 14:47:20 +00:00
|
|
|
reply_to_text=sample_template.service.get_default_sms_sender()
|
2017-11-27 15:24:16 +00:00
|
|
|
)
|
2017-04-27 12:14:22 +01:00
|
|
|
|
2019-11-11 14:47:20 +00:00
|
|
|
notification_international = create_notification(
|
|
|
|
|
template=sample_template,
|
2019-05-08 15:45:19 +01:00
|
|
|
to_field="+6011-17224412",
|
2021-02-11 13:51:15 +00:00
|
|
|
normalised_to=validate_and_format_phone_number("+6011-17224412", international=True),
|
2017-04-27 12:14:22 +01:00
|
|
|
personalisation={"name": "Jo"},
|
|
|
|
|
status='created',
|
2017-11-27 15:24:16 +00:00
|
|
|
international=True,
|
2019-11-11 14:47:20 +00:00
|
|
|
reply_to_text=sample_template.service.get_default_sms_sender()
|
2017-11-27 15:24:16 +00:00
|
|
|
)
|
2017-04-27 12:14:22 +01:00
|
|
|
send_to_providers.send_sms_to_provider(
|
2019-11-11 14:47:20 +00:00
|
|
|
notification_uk
|
2017-04-27 12:14:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
firetext_client.send_sms.assert_called_once_with(
|
2017-04-27 16:03:27 +01:00
|
|
|
to="447234123999",
|
2017-04-27 12:14:22 +01:00
|
|
|
content=ANY,
|
2019-11-11 14:47:20 +00:00
|
|
|
reference=str(notification_uk.id),
|
2017-05-22 15:58:19 +01:00
|
|
|
sender=current_app.config['FROM_NUMBER']
|
2017-04-27 12:14:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
send_to_providers.send_sms_to_provider(
|
2019-11-11 14:47:20 +00:00
|
|
|
notification_international
|
2017-04-27 12:14:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mmg_client.send_sms.assert_called_once_with(
|
2019-05-08 15:45:19 +01:00
|
|
|
to="601117224412",
|
2017-04-27 12:14:22 +01:00
|
|
|
content=ANY,
|
2019-11-11 14:47:20 +00:00
|
|
|
reference=str(notification_international.id),
|
2017-05-22 15:58:19 +01:00
|
|
|
sender=current_app.config['FROM_NUMBER']
|
2017-04-27 12:14:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert notification_uk.status == 'sending'
|
|
|
|
|
assert notification_uk.sent_by == 'firetext'
|
2019-11-11 14:47:20 +00:00
|
|
|
assert notification_international.status == 'sent'
|
|
|
|
|
assert notification_international.sent_by == 'mmg'
|
2017-04-27 13:22:17 +01:00
|
|
|
|
|
|
|
|
|
2017-11-03 15:32:18 +00:00
|
|
|
@pytest.mark.parametrize('sms_sender, expected_sender, prefix_sms, expected_content', [
|
|
|
|
|
('foo', 'foo', False, 'bar'),
|
|
|
|
|
('foo', 'foo', True, 'Sample service: bar'),
|
2017-05-22 15:58:19 +01:00
|
|
|
# if 40604 is actually in DB then treat that as if entered manually
|
2017-11-03 15:32:18 +00:00
|
|
|
('40604', '40604', False, 'bar'),
|
2017-05-22 15:58:19 +01:00
|
|
|
# 'testing' is the FROM_NUMBER during unit tests
|
2017-11-03 15:32:18 +00:00
|
|
|
('testing', 'testing', True, 'Sample service: bar'),
|
|
|
|
|
('testing', 'testing', False, 'bar'),
|
2017-05-22 15:58:19 +01:00
|
|
|
])
|
|
|
|
|
def test_should_handle_sms_sender_and_prefix_message(
|
|
|
|
|
mocker,
|
|
|
|
|
sms_sender,
|
2017-11-03 15:32:18 +00:00
|
|
|
prefix_sms,
|
2017-05-22 15:58:19 +01:00
|
|
|
expected_sender,
|
2017-10-02 15:29:13 +01:00
|
|
|
expected_content,
|
|
|
|
|
notify_db_session
|
2017-05-22 15:58:19 +01:00
|
|
|
):
|
|
|
|
|
mocker.patch('app.mmg_client.send_sms')
|
2017-11-09 11:53:29 +00:00
|
|
|
service = create_service_with_defined_sms_sender(sms_sender_value=sms_sender, prefix_sms=prefix_sms)
|
2017-09-21 16:41:10 +01:00
|
|
|
template = create_template(service, content='bar')
|
2017-11-27 15:24:16 +00:00
|
|
|
notification = create_notification(template, reply_to_text=sms_sender)
|
2017-05-22 15:58:19 +01:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
)
|
2017-08-14 19:47:09 +01:00
|
|
|
|
|
|
|
|
|
2017-11-29 16:47:23 +00:00
|
|
|
def test_send_email_to_provider_uses_reply_to_from_notification(
|
2017-10-06 16:58:32 +01:00
|
|
|
sample_email_template,
|
|
|
|
|
mocker):
|
|
|
|
|
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
|
|
|
|
|
2017-11-27 15:24:16 +00:00
|
|
|
db_notification = create_notification(template=sample_email_template, reply_to_text="test@test.com")
|
2017-10-06 16:58:32 +01:00
|
|
|
|
|
|
|
|
send_to_providers.send_email_to_provider(
|
|
|
|
|
db_notification,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app.aws_ses_client.send_email.assert_called_once_with(
|
|
|
|
|
ANY,
|
|
|
|
|
ANY,
|
|
|
|
|
ANY,
|
|
|
|
|
body=ANY,
|
|
|
|
|
html_body=ANY,
|
2017-11-29 16:47:23 +00:00
|
|
|
reply_to_address="test@test.com"
|
2017-10-06 16:58:32 +01:00
|
|
|
)
|