Merge pull request #816 from alphagov/refactor-send_to_providers

Small refactor to reuse code.
This commit is contained in:
Rebecca Law
2017-02-07 17:27:51 +00:00
committed by GitHub
2 changed files with 12 additions and 15 deletions

View File

@@ -21,11 +21,7 @@ from app.models import SMS_TYPE, KEY_TYPE_TEST, BRANDING_ORG, EMAIL_TYPE, NOTIFI
def send_sms_to_provider(notification):
service = notification.service
if not service.active:
notification.status = NOTIFICATION_TECHNICAL_FAILURE
dao_update_notification(notification)
current_app.logger.warn(
"Send sms for notification id {} to provider is not allowed: service {} is inactive".format(notification.id,
service.id))
technical_failure(notification=notification)
return
if notification.status == 'created':
@@ -70,12 +66,7 @@ def send_sms_to_provider(notification):
def send_email_to_provider(notification):
service = notification.service
if not service.active:
notification.status = NOTIFICATION_TECHNICAL_FAILURE
dao_update_notification(notification)
current_app.logger.warn(
"Send email for notification id {} to provider is not allowed: service {} is inactive".format(
notification.id,
service.id))
technical_failure(notification=notification)
return
if notification.status == 'created':
provider = provider_to_use(EMAIL_TYPE, notification.id)
@@ -199,3 +190,13 @@ def get_html_email_options(service):
branding = {}
return dict(govuk_banner=govuk_banner, **branding)
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))

View File

@@ -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():