mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Update logging for provider tasks.
Move the info message before the fetch. Include the exception in the log message.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
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.clients.email.aws_ses import AwsSesClientException
|
||||
from app.exceptions import NotificationTechnicalFailureException
|
||||
|
||||
|
||||
@@ -92,6 +94,24 @@ def test_should_technical_error_and_not_retry_if_invalid_email(sample_notificati
|
||||
assert sample_notification.status == 'technical-failure'
|
||||
|
||||
|
||||
def test_should_retry_and_log_exception(sample_notification, mocker):
|
||||
error_response = {
|
||||
'Error': {
|
||||
'Code': 'SomeError',
|
||||
'Message': 'some error message from amazon',
|
||||
'Type': 'Sender'
|
||||
}
|
||||
}
|
||||
ex = ClientError(error_response=error_response, operation_name='opname')
|
||||
mocker.patch('app.delivery.send_to_providers.send_email_to_provider', side_effect=AwsSesClientException(str(ex)))
|
||||
mocker.patch('app.celery.provider_tasks.deliver_email.retry')
|
||||
|
||||
deliver_email(sample_notification.id)
|
||||
|
||||
assert provider_tasks.deliver_email.retry.called is True
|
||||
assert sample_notification.status == 'created'
|
||||
|
||||
|
||||
def test_send_sms_should_switch_providers_on_provider_failure(sample_notification, mocker):
|
||||
provider_to_use = mocker.patch('app.delivery.send_to_providers.provider_to_use')
|
||||
provider_to_use.return_value.send_sms.side_effect = Exception('Error')
|
||||
|
||||
Reference in New Issue
Block a user