mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-07 10:38:25 -04:00
Update NotificationTechnicalFailureException
- Change the NotificationTechnicalFailureException so that it only inherits from Exception. - The notify_celery task should create the logging message on failure. - Fix unit tests - Remove named parameter when raising exception.
This commit is contained in:
@@ -373,7 +373,7 @@ def update_letter_notifications_to_error(self, notification_references):
|
|||||||
message = "Updated {} letter notifications to technical-failure with references {}".format(
|
message = "Updated {} letter notifications to technical-failure with references {}".format(
|
||||||
updated_count, notification_references
|
updated_count, notification_references
|
||||||
)
|
)
|
||||||
raise NotificationTechnicalFailureException(message=message)
|
raise NotificationTechnicalFailureException(message)
|
||||||
|
|
||||||
|
|
||||||
def handle_exception(task, notification, notification_id, exc):
|
def handle_exception(task, notification, notification_id, exc):
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ class DVLAException(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationTechnicalFailureException(Exception):
|
class NotificationTechnicalFailureException(Exception):
|
||||||
def __init__(self, message):
|
pass
|
||||||
self.message = message
|
|
||||||
|
|
||||||
|
|
||||||
class ArchiveValidationError(Exception):
|
class ArchiveValidationError(Exception):
|
||||||
|
|||||||
@@ -173,9 +173,7 @@ def test_update_letter_notifications_to_sent_to_dvla_updates_based_on_notificati
|
|||||||
|
|
||||||
|
|
||||||
def test_update_letter_notifications_to_error_updates_based_on_notification_references(
|
def test_update_letter_notifications_to_error_updates_based_on_notification_references(
|
||||||
client,
|
sample_letter_template
|
||||||
sample_letter_template,
|
|
||||||
mocker
|
|
||||||
):
|
):
|
||||||
first = create_notification(sample_letter_template, reference='first ref')
|
first = create_notification(sample_letter_template, reference='first ref')
|
||||||
second = create_notification(sample_letter_template, reference='second ref')
|
second = create_notification(sample_letter_template, reference='second ref')
|
||||||
@@ -184,7 +182,7 @@ def test_update_letter_notifications_to_error_updates_based_on_notification_refe
|
|||||||
with freeze_time(dt):
|
with freeze_time(dt):
|
||||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||||
update_letter_notifications_to_error([first.reference])
|
update_letter_notifications_to_error([first.reference])
|
||||||
assert first.reference in e.value.message
|
assert first.reference in e.value
|
||||||
|
|
||||||
assert first.status == NOTIFICATION_TECHNICAL_FAILURE
|
assert first.status == NOTIFICATION_TECHNICAL_FAILURE
|
||||||
assert first.sent_by is None
|
assert first.sent_by is None
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ def test_update_status_of_notifications_after_timeout(notify_api, sample_templat
|
|||||||
seconds=current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD') + 10))
|
seconds=current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD') + 10))
|
||||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||||
timeout_notifications()
|
timeout_notifications()
|
||||||
assert str(not2.id) in e.value.message
|
assert str(not2.id) in e.value
|
||||||
assert not1.status == 'temporary-failure'
|
assert not1.status == 'temporary-failure'
|
||||||
assert not2.status == 'technical-failure'
|
assert not2.status == 'technical-failure'
|
||||||
assert not3.status == 'temporary-failure'
|
assert not3.status == 'temporary-failure'
|
||||||
|
|||||||
@@ -65,11 +65,11 @@ def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_sms_task(s
|
|||||||
|
|
||||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||||
deliver_sms(sample_notification.id)
|
deliver_sms(sample_notification.id)
|
||||||
|
assert sample_notification.id in e.value
|
||||||
|
|
||||||
provider_tasks.deliver_sms.retry.assert_called_with(queue="retry-tasks", countdown=0)
|
provider_tasks.deliver_sms.retry.assert_called_with(queue="retry-tasks", countdown=0)
|
||||||
|
|
||||||
assert sample_notification.status == 'technical-failure'
|
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):
|
def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_email_task(sample_notification, mocker):
|
||||||
@@ -78,10 +78,10 @@ def test_should_go_into_technical_error_if_exceeds_retries_on_deliver_email_task
|
|||||||
|
|
||||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||||
deliver_email(sample_notification.id)
|
deliver_email(sample_notification.id)
|
||||||
|
assert sample_notification.id in e.value
|
||||||
|
|
||||||
provider_tasks.deliver_email.retry.assert_called_with(queue="retry-tasks")
|
provider_tasks.deliver_email.retry.assert_called_with(queue="retry-tasks")
|
||||||
assert sample_notification.status == 'technical-failure'
|
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):
|
def test_should_technical_error_and_not_retry_if_invalid_email(sample_notification, mocker):
|
||||||
|
|||||||
@@ -139,9 +139,9 @@ def test_should_not_send_email_message_when_service_is_inactive_notifcation_is_i
|
|||||||
|
|
||||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||||
send_to_providers.send_email_to_provider(sample_notification)
|
send_to_providers.send_email_to_provider(sample_notification)
|
||||||
|
assert sample_notification.id in e.value
|
||||||
send_mock.assert_not_called()
|
send_mock.assert_not_called()
|
||||||
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
|
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
|
||||||
assert str(sample_notification.id) in e.value.message
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("client_send", ["app.mmg_client.send_sms", "app.firetext_client.send_sms"])
|
@pytest.mark.parametrize("client_send", ["app.mmg_client.send_sms", "app.firetext_client.send_sms"])
|
||||||
@@ -152,9 +152,9 @@ def test_should_not_send_sms_message_when_service_is_inactive_notifcation_is_in_
|
|||||||
|
|
||||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||||
send_to_providers.send_sms_to_provider(sample_notification)
|
send_to_providers.send_sms_to_provider(sample_notification)
|
||||||
|
assert sample_notification.id in e.value
|
||||||
send_mock.assert_not_called()
|
send_mock.assert_not_called()
|
||||||
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
|
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
|
||||||
assert str(sample_notification.id) in e.value.message
|
|
||||||
|
|
||||||
|
|
||||||
def test_send_sms_should_use_template_version_from_notification_not_latest(
|
def test_send_sms_should_use_template_version_from_notification_not_latest(
|
||||||
|
|||||||
Reference in New Issue
Block a user