mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
We are not handling the case of an unknown status code sent by the SMS provider. This PR attempts to fix that.
- If the SMS client sends a status code that we do not recognize raise a ClientException and set the notification status to technical-failure - Simplified the code in process_client_response, using a simple map.
This commit is contained in:
@@ -9,27 +9,15 @@ from app.clients.sms.firetext import get_firetext_responses, SmsClientResponseEx
|
||||
|
||||
|
||||
def test_should_return_correct_details_for_delivery():
|
||||
response_dict = get_firetext_responses('0')
|
||||
assert response_dict['message'] == 'Delivered'
|
||||
assert response_dict['notification_status'] == 'delivered'
|
||||
assert response_dict['notification_statistics_status'] == 'delivered'
|
||||
assert response_dict['success']
|
||||
get_firetext_responses('0') == 'delivered'
|
||||
|
||||
|
||||
def test_should_return_correct_details_for_bounced():
|
||||
response_dict = get_firetext_responses('1')
|
||||
assert response_dict['message'] == 'Declined'
|
||||
assert response_dict['notification_status'] == 'permanent-failure'
|
||||
assert response_dict['notification_statistics_status'] == 'failure'
|
||||
assert not response_dict['success']
|
||||
get_firetext_responses('1') == 'permanent-failure'
|
||||
|
||||
|
||||
def test_should_return_correct_details_for_complaint():
|
||||
response_dict = get_firetext_responses('2')
|
||||
assert response_dict['message'] == 'Undelivered (Pending with Network)'
|
||||
assert response_dict['notification_status'] == 'pending'
|
||||
assert response_dict['notification_statistics_status'] is None
|
||||
assert response_dict['success']
|
||||
get_firetext_responses('2') == 'pending'
|
||||
|
||||
|
||||
def test_should_be_none_if_unrecognised_status_code():
|
||||
|
||||
@@ -10,27 +10,22 @@ from app.clients.sms.mmg import get_mmg_responses, MMGClientResponseException
|
||||
|
||||
|
||||
def test_should_return_correct_details_for_delivery():
|
||||
response_dict = get_mmg_responses('3')
|
||||
assert response_dict['message'] == 'Delivered'
|
||||
assert response_dict['notification_status'] == 'delivered'
|
||||
assert response_dict['notification_statistics_status'] == 'delivered'
|
||||
assert response_dict['success']
|
||||
get_mmg_responses('3') == 'delivered'
|
||||
|
||||
|
||||
def test_should_return_correct_details_for_bounced():
|
||||
response_dict = get_mmg_responses('50')
|
||||
assert response_dict['message'] == 'Declined'
|
||||
assert response_dict['notification_status'] == 'failed'
|
||||
assert response_dict['notification_statistics_status'] == 'failure'
|
||||
assert not response_dict['success']
|
||||
def test_should_return_correct_details_for_temporary_failure():
|
||||
get_mmg_responses('4') == 'temporary-failure'
|
||||
|
||||
|
||||
def test_should_be_none_if_unrecognised_status_code():
|
||||
response_dict = get_mmg_responses('blah')
|
||||
assert response_dict['message'] == 'Declined'
|
||||
assert response_dict['notification_status'] == 'failed'
|
||||
assert response_dict['notification_statistics_status'] == 'failure'
|
||||
assert not response_dict['success']
|
||||
@pytest.mark.parametrize('status', ['5', '2'])
|
||||
def test_should_return_correct_details_for_bounced(status):
|
||||
get_mmg_responses(status) == 'permanent-failure'
|
||||
|
||||
|
||||
def test_should_be_raise_if_unrecognised_status_code():
|
||||
with pytest.raises(KeyError) as e:
|
||||
get_mmg_responses('99')
|
||||
assert '99' in str(e.value)
|
||||
|
||||
|
||||
def test_send_sms_successful_returns_mmg_response(notify_api, mocker):
|
||||
|
||||
Reference in New Issue
Block a user