mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 23:41:17 -05:00
Update as per comments on review
This commit is contained in:
@@ -20,7 +20,8 @@ from app.models import SMS_TYPE, KEY_TYPE_TEST, BRANDING_ORG, EMAIL_TYPE, NOTIFI
|
|||||||
|
|
||||||
def send_sms_to_provider(notification):
|
def send_sms_to_provider(notification):
|
||||||
service = notification.service
|
service = notification.service
|
||||||
if service_is_inactive(service, notification):
|
if not service.active:
|
||||||
|
technical_failure(notification=notification)
|
||||||
return
|
return
|
||||||
|
|
||||||
if notification.status == 'created':
|
if notification.status == 'created':
|
||||||
@@ -64,7 +65,8 @@ def send_sms_to_provider(notification):
|
|||||||
|
|
||||||
def send_email_to_provider(notification):
|
def send_email_to_provider(notification):
|
||||||
service = notification.service
|
service = notification.service
|
||||||
if service_is_inactive(service, notification):
|
if not service.active:
|
||||||
|
technical_failure(notification=notification)
|
||||||
return
|
return
|
||||||
if notification.status == 'created':
|
if notification.status == 'created':
|
||||||
provider = provider_to_use(EMAIL_TYPE, notification.id)
|
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)
|
return dict(govuk_banner=govuk_banner, **branding)
|
||||||
|
|
||||||
|
|
||||||
def service_is_inactive(service, notification):
|
def technical_failure(notification):
|
||||||
"""
|
notification.status = NOTIFICATION_TECHNICAL_FAILURE
|
||||||
If service is inactive update the notification to technical failure and return true.
|
dao_update_notification(notification)
|
||||||
:param service:
|
current_app.logger.warn(
|
||||||
:param notification:
|
"Send {} for notification id {} to provider is not allowed: service {} is inactive".format(
|
||||||
:return:
|
notification.notification_type,
|
||||||
"""
|
notification.id,
|
||||||
if not service.active:
|
notification.service_id))
|
||||||
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
|
|
||||||
|
|||||||
@@ -4,10 +4,6 @@ from notifications_utils.recipients import InvalidEmailError
|
|||||||
import app
|
import app
|
||||||
from app.celery import provider_tasks
|
from app.celery import provider_tasks
|
||||||
from app.celery.provider_tasks import deliver_sms, deliver_email
|
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():
|
def test_should_have_decorated_tasks_functions():
|
||||||
|
|||||||
Reference in New Issue
Block a user