mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Test logging and error message
This commit is contained in:
@@ -83,13 +83,13 @@ def create_letters_pdf(self, notification_id):
|
||||
except Exception:
|
||||
try:
|
||||
current_app.logger.exception(
|
||||
"RETRY: calling create-letter-pdf task for notification {} failed".format(notification_id)
|
||||
f"RETRY: calling create-letter-pdf task for notification {notification_id} failed"
|
||||
)
|
||||
self.retry(queue=QueueNames.RETRY)
|
||||
except self.MaxRetriesExceededError:
|
||||
message = "RETRY FAILED: Max retries reached. " \
|
||||
"The task create-letter-pdf failed for notification {}. " \
|
||||
"Notification has been updated to technical-failure".format(notification_id)
|
||||
message = f"RETRY FAILED: Max retries reached. " \
|
||||
f"The task create-letter-pdf failed for notification id {notification_id}. " \
|
||||
f"Notification has been updated to technical-failure"
|
||||
update_notification_status_by_id(notification_id, NOTIFICATION_TECHNICAL_FAILURE)
|
||||
raise NotificationTechnicalFailureException(message)
|
||||
|
||||
|
||||
@@ -97,11 +97,15 @@ def test_create_letters_pdf_retries_upon_error(mocker, sample_letter_notificatio
|
||||
mock_celery = mocker.patch('app.celery.letters_pdf_tasks.notify_celery.send_task', side_effect=Exception())
|
||||
mocker.patch('app.celery.letters_pdf_tasks.get_letter_pdf_filename', return_value='LETTER.PDF')
|
||||
mock_retry = mocker.patch('app.celery.letters_pdf_tasks.create_letters_pdf.retry')
|
||||
mock_logger = mocker.patch('app.celery.tasks.current_app.logger.exception')
|
||||
|
||||
create_letters_pdf(sample_letter_notification.id)
|
||||
|
||||
assert mock_celery.called
|
||||
assert mock_retry.called
|
||||
mock_logger.assert_called_once_with(
|
||||
f"RETRY: calling create-letter-pdf task for notification {sample_letter_notification.id} failed"
|
||||
)
|
||||
|
||||
|
||||
def test_create_letters_pdf_sets_technical_failure_max_retries(mocker, sample_letter_notification):
|
||||
@@ -111,9 +115,12 @@ def test_create_letters_pdf_sets_technical_failure_max_retries(mocker, sample_le
|
||||
'app.celery.letters_pdf_tasks.create_letters_pdf.retry', side_effect=MaxRetriesExceededError)
|
||||
mock_update_noti = mocker.patch('app.celery.letters_pdf_tasks.update_notification_status_by_id')
|
||||
|
||||
with pytest.raises(NotificationTechnicalFailureException):
|
||||
with pytest.raises(NotificationTechnicalFailureException) as e:
|
||||
create_letters_pdf(sample_letter_notification.id)
|
||||
|
||||
assert e.value.args[0] == f"RETRY FAILED: Max retries reached. " \
|
||||
f"The task create-letter-pdf failed for notification id {sample_letter_notification.id}. " \
|
||||
f"Notification has been updated to technical-failure"
|
||||
assert mock_celery.called
|
||||
assert mock_retry.called
|
||||
mock_update_noti.assert_called_once_with(sample_letter_notification.id, 'technical-failure')
|
||||
|
||||
Reference in New Issue
Block a user