mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Throw an exception whenever we updated a notification to technical failure.
If this is happening we want to know about it.
This commit is contained in:
@@ -5,7 +5,7 @@ import pytest
|
||||
from freezegun import freeze_time
|
||||
from flask import current_app
|
||||
|
||||
from app.exceptions import DVLAException
|
||||
from app.exceptions import DVLAException, NotificationTechnicalFailureException
|
||||
from app.models import (
|
||||
Job,
|
||||
Notification,
|
||||
@@ -276,7 +276,9 @@ def test_update_letter_notifications_to_error_updates_based_on_notification_refe
|
||||
create_service_callback_api(service=sample_letter_template.service, url="https://original_url.com")
|
||||
dt = datetime.utcnow()
|
||||
with freeze_time(dt):
|
||||
update_letter_notifications_to_error([first.reference])
|
||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||
update_letter_notifications_to_error([first.reference])
|
||||
assert first.reference in e.value.message
|
||||
|
||||
assert first.status == NOTIFICATION_TECHNICAL_FAILURE
|
||||
assert first.sent_by is None
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import pytest
|
||||
from celery.exceptions import MaxRetriesExceededError
|
||||
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.exceptions import NotificationTechnicalFailureException
|
||||
|
||||
|
||||
def test_should_have_decorated_tasks_functions():
|
||||
@@ -59,21 +61,25 @@ def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_sms_task(s
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_to_provider', side_effect=Exception("EXPECTED"))
|
||||
mocker.patch('app.celery.provider_tasks.deliver_sms.retry', side_effect=MaxRetriesExceededError())
|
||||
|
||||
deliver_sms(sample_notification.id)
|
||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||
deliver_sms(sample_notification.id)
|
||||
|
||||
provider_tasks.deliver_sms.retry.assert_called_with(queue="retry-tasks")
|
||||
|
||||
assert sample_notification.status == 'technical-failure'
|
||||
assert str(sample_notification.id) in e.value.message
|
||||
|
||||
|
||||
def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_email_task(sample_notification, mocker):
|
||||
mocker.patch('app.delivery.send_to_providers.send_email_to_provider', side_effect=Exception("EXPECTED"))
|
||||
mocker.patch('app.celery.provider_tasks.deliver_email.retry', side_effect=MaxRetriesExceededError())
|
||||
|
||||
deliver_email(sample_notification.id)
|
||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||
deliver_email(sample_notification.id)
|
||||
|
||||
provider_tasks.deliver_email.retry.assert_called_with(queue="retry-tasks")
|
||||
assert sample_notification.status == 'technical-failure'
|
||||
assert str(sample_notification.id) in e.value.message
|
||||
|
||||
|
||||
def test_should_technical_error_and_not_retry_if_invalid_email(sample_notification, mocker):
|
||||
|
||||
@@ -44,6 +44,7 @@ from app.dao.provider_details_dao import (
|
||||
dao_update_provider_details,
|
||||
get_current_provider
|
||||
)
|
||||
from app.exceptions import NotificationTechnicalFailureException
|
||||
from app.models import (
|
||||
MonthlyBilling,
|
||||
NotificationHistory,
|
||||
@@ -181,8 +182,10 @@ def test_update_status_of_notifications_after_timeout(notify_api, sample_templat
|
||||
status='pending',
|
||||
created_at=datetime.utcnow() - timedelta(
|
||||
seconds=current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD') + 10))
|
||||
timeout_notifications()
|
||||
|
||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||
timeout_notifications()
|
||||
print(e.value.message)
|
||||
assert str(not2.id) in e.value.message
|
||||
assert not1.status == 'temporary-failure'
|
||||
assert not2.status == 'technical-failure'
|
||||
assert not3.status == 'temporary-failure'
|
||||
|
||||
Reference in New Issue
Block a user