Use from_id_and_service_id method from SerialisedTemplate.

Minor updates as per requested from review
This commit is contained in:
Rebecca Law
2021-02-15 12:41:50 +00:00
parent 61af203ad6
commit d67f9fcfd6
3 changed files with 51 additions and 13 deletions

View File

@@ -430,7 +430,6 @@ class Development(Config):
class Test(Development): class Test(Development):
SQLALCHEMY_ECHO = False
NOTIFY_EMAIL_DOMAIN = 'test.notify.com' NOTIFY_EMAIL_DOMAIN = 'test.notify.com'
FROM_NUMBER = 'testing' FROM_NUMBER = 'testing'
NOTIFY_ENVIRONMENT = 'test' NOTIFY_ENVIRONMENT = 'test'

View File

@@ -15,7 +15,6 @@ from app.dao.provider_details_dao import (
dao_reduce_sms_provider_priority dao_reduce_sms_provider_priority
) )
from app.celery.research_mode_tasks import send_sms_response, send_email_response from app.celery.research_mode_tasks import send_sms_response, send_email_response
from app.dao.templates_dao import dao_get_template_by_id
from app.exceptions import NotificationTechnicalFailureException from app.exceptions import NotificationTechnicalFailureException
from app.models import ( from app.models import (
SMS_TYPE, SMS_TYPE,
@@ -41,9 +40,9 @@ def send_sms_to_provider(notification):
if notification.status == 'created': if notification.status == 'created':
provider = provider_to_use(SMS_TYPE, notification.international) provider = provider_to_use(SMS_TYPE, notification.international)
template_dict = SerialisedTemplate.get_dict(template_id=notification.template_id, template_dict = SerialisedTemplate.from_id_and_service_id(template_id=notification.template_id,
service_id=service.id, service_id=service_id,
version=notification.template_version)['data'] version=notification.template_version).__dict__
template = SMSMessageTemplate( template = SMSMessageTemplate(
template_dict, template_dict,
@@ -95,9 +94,9 @@ def send_email_to_provider(notification):
if notification.status == 'created': if notification.status == 'created':
provider = provider_to_use(EMAIL_TYPE) provider = provider_to_use(EMAIL_TYPE)
template_dict = SerialisedTemplate.get_dict(template_id=notification.template_id, template_dict = SerialisedTemplate.from_id_and_service_id(template_id=notification.template_id,
service_id=service_id, service_id=service_id,
version=notification.template_version)['data'] version=notification.template_version).__dict__
html_email = HTMLEmailTemplate( html_email = HTMLEmailTemplate(
template_dict, template_dict,

View File

@@ -733,6 +733,37 @@ def test_send_email_to_provider_uses_reply_to_from_notification(
) )
def test_send_sms_to_provider_should_use_normalised_to(
mocker, client, sample_template
):
send_mock = mocker.patch('app.mmg_client.send_sms')
notification = create_notification(template=sample_template,
to_field='+447700900855',
normalised_to='447700900855')
send_to_providers.send_sms_to_provider(notification)
send_mock.assert_called_once_with(to=notification.normalised_to,
content=ANY,
reference=str(notification.id),
sender=notification.reply_to_text)
def test_send_email_to_provider_should_user_normalised_to(
mocker, client, sample_email_template
):
send_mock = mocker.patch('app.aws_ses_client.send_email', return_value='reference')
notification = create_notification(template=sample_email_template,
to_field='TEST@example.com',
normalised_to='test@example.com')
send_to_providers.send_email_to_provider(notification)
send_mock.assert_called_once_with(ANY,
notification.normalised_to,
ANY,
body=ANY,
html_body=ANY,
reply_to_address=notification.reply_to_text)
def test_send_sms_to_provider_should_return_template_if_found_in_redis( def test_send_sms_to_provider_should_return_template_if_found_in_redis(
mocker, client, sample_template mocker, client, sample_template
): ):
@@ -754,14 +785,17 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
'app.dao.services_dao.dao_fetch_service_by_id' 'app.dao.services_dao.dao_fetch_service_by_id'
) )
mocker.patch('app.mmg_client.send_sms') send_mock = mocker.patch('app.mmg_client.send_sms')
# mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
notification = create_notification(template=sample_template, notification = create_notification(template=sample_template,
to_field='+447700900855', to_field='+447700900855',
normalised_to=validate_and_format_phone_number('+447700900855')) normalised_to='447700900855')
send_to_providers.send_sms_to_provider(notification) send_to_providers.send_sms_to_provider(notification)
assert mock_get_template.called is False assert mock_get_template.called is False
assert mock_get_service.called is False assert mock_get_service.called is False
send_mock.assert_called_once_with(to=notification.normalised_to,
content=ANY,
reference=str(notification.id),
sender=notification.reply_to_text)
def test_send_email_to_provider_should_return_template_if_found_in_redis( def test_send_email_to_provider_should_return_template_if_found_in_redis(
@@ -784,11 +818,17 @@ def test_send_email_to_provider_should_return_template_if_found_in_redis(
mock_get_service = mocker.patch( mock_get_service = mocker.patch(
'app.dao.services_dao.dao_fetch_service_by_id' 'app.dao.services_dao.dao_fetch_service_by_id'
) )
mocker.patch('app.aws_ses_client.send_email', return_value='reference') send_mock = mocker.patch('app.aws_ses_client.send_email', return_value='reference')
notification = create_notification(template=sample_email_template, notification = create_notification(template=sample_email_template,
to_field='test@example.com', to_field='TEST@example.com',
normalised_to='test@example.com') normalised_to='test@example.com')
send_to_providers.send_email_to_provider(notification) send_to_providers.send_email_to_provider(notification)
assert mock_get_template.called is False assert mock_get_template.called is False
assert mock_get_service.called is False assert mock_get_service.called is False
send_mock.assert_called_once_with(ANY,
notification.normalised_to,
ANY,
body=ANY,
html_body=ANY,
reply_to_address=notification.reply_to_text)