From c36d61c0712c4f03415a0b82ca7abfdc016effab Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 6 Feb 2017 16:20:44 +0000 Subject: [PATCH] Update as per comments on review --- app/delivery/send_to_providers.py | 30 ++++++++++--------------- tests/app/celery/test_provider_tasks.py | 4 ---- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index 6276d64cb..f6991c0b0 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -20,7 +20,8 @@ from app.models import SMS_TYPE, KEY_TYPE_TEST, BRANDING_ORG, EMAIL_TYPE, NOTIFI def send_sms_to_provider(notification): service = notification.service - if service_is_inactive(service, notification): + if not service.active: + technical_failure(notification=notification) return if notification.status == 'created': @@ -64,7 +65,8 @@ def send_sms_to_provider(notification): def send_email_to_provider(notification): service = notification.service - if service_is_inactive(service, notification): + if not service.active: + technical_failure(notification=notification) return if notification.status == 'created': provider = provider_to_use(EMAIL_TYPE, notification.id) @@ -190,19 +192,11 @@ def get_html_email_options(service): return dict(govuk_banner=govuk_banner, **branding) -def service_is_inactive(service, notification): - """ - If service is inactive update the notification to technical failure and return true. - :param service: - :param notification: - :return: - """ - if not service.active: - notification.status = NOTIFICATION_TECHNICAL_FAILURE - dao_update_notification(notification) - current_app.logger.warn( - "Send {} for notification id {} to provider is not allowed: service {} is inactive".format( - notification.notification_type, - notification.id, - service.id)) - return not service.active +def technical_failure(notification): + notification.status = NOTIFICATION_TECHNICAL_FAILURE + dao_update_notification(notification) + current_app.logger.warn( + "Send {} for notification id {} to provider is not allowed: service {} is inactive".format( + notification.notification_type, + notification.id, + notification.service_id)) diff --git a/tests/app/celery/test_provider_tasks.py b/tests/app/celery/test_provider_tasks.py index 6a60d3964..d2f815d9d 100644 --- a/tests/app/celery/test_provider_tasks.py +++ b/tests/app/celery/test_provider_tasks.py @@ -4,10 +4,6 @@ from notifications_utils.recipients import InvalidEmailError import app from app.celery import provider_tasks from app.celery.provider_tasks import deliver_sms, deliver_email -from app.clients.email import EmailClientException -from app.models import Notification - -from tests.app.conftest import sample_notification def test_should_have_decorated_tasks_functions():