From 385d24978752e1f1218ae88a741bd077b385e1d3 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Tue, 21 Apr 2020 12:06:28 +0100 Subject: [PATCH] Take into consideration Firetext 000 code - no error. Also change logs from error to warning --- app/dao/notifications_dao.py | 4 ++-- tests/app/notifications/test_process_client_response.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 01a58f28c..d959ecb13 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -94,13 +94,13 @@ def _decide_permanent_temporary_failure(status, notification, code=None): # Firetext will send pending, then send either succes or fail. # If we go from pending to failure we need to set failure type as temporary-failure, # unless we get a detailed code from firetext. Then we should use that code to set status instead. - if code: + if code and code != '000': try: status, reason = get_message_status_and_reason_from_firetext_code(code) current_app.logger.info(f'Updating notification id {notification.id} to status {status}, reason: {reason}') return status except KeyError: - current_app.logger.error(f'Failure code {code} from Firetext not recognised') + current_app.logger.warning(f'Failure code {code} from Firetext not recognised') if notification.status == NOTIFICATION_PENDING and status == NOTIFICATION_PERMANENT_FAILURE: status = NOTIFICATION_TEMPORARY_FAILURE return status diff --git a/tests/app/notifications/test_process_client_response.py b/tests/app/notifications/test_process_client_response.py index 11ff3abe4..9457528e7 100644 --- a/tests/app/notifications/test_process_client_response.py +++ b/tests/app/notifications/test_process_client_response.py @@ -61,6 +61,7 @@ def test_process_sms_client_response_updates_notification_status( ('101', 'permanent-failure', 'Unknown Subscriber'), ('102', 'temporary-failure', 'Absent Subscriber'), (None, 'temporary-failure', None), + ('000', 'temporary-failure', None) ]) def test_process_sms_client_response_updates_notification_status_when_called_second_time( sample_notification, @@ -75,7 +76,7 @@ def test_process_sms_client_response_updates_notification_status_when_called_sec process_sms_client_response('1', str(sample_notification.id), 'Firetext', code) - if code: + if code and code != '000': message = f'Updating notification id {sample_notification.id} to status {expected_notification_status}, reason: {reason}' # noqa mock_logger.assert_called_with(message) @@ -86,7 +87,7 @@ def test_process_sms_client_response_updates_notification_status_when_code_unkno sample_notification, mocker, ): - mock_logger = mocker.patch('app.celery.tasks.current_app.logger.error') + mock_logger = mocker.patch('app.celery.tasks.current_app.logger.warning') sample_notification.status = 'sending' process_sms_client_response('2', str(sample_notification.id), 'Firetext')