mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-11 09:27:56 -04:00
Change function and variable names for readability and consistency
This commit is contained in:
@@ -8,25 +8,25 @@ import requests_mock
|
||||
from app.clients.sms.firetext import get_firetext_responses, SmsClientResponseException, FiretextClientResponseException
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code, result', [
|
||||
@pytest.mark.parametrize('detailed_status_code, result', [
|
||||
(None, ('delivered', None)), ('000', ('delivered', None))
|
||||
])
|
||||
def test_get_firetext_responses_should_return_correct_details_for_delivery(code, result):
|
||||
assert get_firetext_responses('0', code) == result
|
||||
def test_get_firetext_responses_should_return_correct_details_for_delivery(detailed_status_code, result):
|
||||
assert get_firetext_responses('0', detailed_status_code) == result
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code, result', [
|
||||
@pytest.mark.parametrize('detailed_status_code, result', [
|
||||
(None, ('permanent-failure', None)), ('401', ('permanent-failure', 'Message Rejected'))
|
||||
])
|
||||
def test_get_firetext_responses_should_return_correct_details_for_bounced(code, result):
|
||||
assert get_firetext_responses('1', code) == result
|
||||
def test_get_firetext_responses_should_return_correct_details_for_bounced(detailed_status_code, result):
|
||||
assert get_firetext_responses('1', detailed_status_code) == result
|
||||
|
||||
|
||||
def test_get_firetext_responses_should_return_correct_details_for_complaint():
|
||||
assert get_firetext_responses('2') == ('pending', None)
|
||||
|
||||
|
||||
def test_get_firetext_responses_should_be_none_if_unrecognised_status_code():
|
||||
def test_get_firetext_responses_raises_KeyError_if_unrecognised_status_code():
|
||||
with pytest.raises(KeyError) as e:
|
||||
get_firetext_responses('99')
|
||||
assert '99' in str(e.value)
|
||||
|
||||
@@ -9,31 +9,31 @@ from app.clients.sms import SmsClientResponseException
|
||||
from app.clients.sms.mmg import get_mmg_responses, MMGClientResponseException
|
||||
|
||||
|
||||
@pytest.mark.parametrize('substatus, result', [
|
||||
@pytest.mark.parametrize('detailed_status_code, result', [
|
||||
(None, ('delivered', None)), ('5', ('delivered', 'Delivered to handset'))
|
||||
])
|
||||
def test_get_mmg_responses_should_return_correct_details_for_delivery(substatus, result):
|
||||
assert get_mmg_responses('3', substatus) == result
|
||||
def test_get_mmg_responses_should_return_correct_details_for_delivery(detailed_status_code, result):
|
||||
assert get_mmg_responses('3', detailed_status_code) == result
|
||||
|
||||
|
||||
@pytest.mark.parametrize('substatus, result', [
|
||||
@pytest.mark.parametrize('detailed_status_code, result', [
|
||||
(None, ('temporary-failure', None)), ('15', ('temporary-failure', 'Expired'))
|
||||
])
|
||||
def test_get_mmg_responses_should_return_correct_details_for_temporary_failure(substatus, result):
|
||||
assert get_mmg_responses('4', substatus) == result
|
||||
def test_get_mmg_responses_should_return_correct_details_for_temporary_failure(detailed_status_code, result):
|
||||
assert get_mmg_responses('4', detailed_status_code) == result
|
||||
|
||||
|
||||
@pytest.mark.parametrize('status, substatus, result', [
|
||||
@pytest.mark.parametrize('status, detailed_status_code, result', [
|
||||
('2', None, ('permanent-failure', None)),
|
||||
('2', '12', ('permanent-failure', "Illegal equipment")),
|
||||
('5', None, ('permanent-failure', None)),
|
||||
('5', '20', ('permanent-failure', 'Rejected by anti-flooding mechanism'))
|
||||
])
|
||||
def test_get_mmg_responses_should_return_correct_details_for_bounced(status, substatus, result):
|
||||
assert get_mmg_responses(status, substatus) == result
|
||||
def test_get_mmg_responses_should_return_correct_details_for_bounced(status, detailed_status_code, result):
|
||||
assert get_mmg_responses(status, detailed_status_code) == result
|
||||
|
||||
|
||||
def test_get_mmg_responses_should_be_raise_if_unrecognised_status_code():
|
||||
def test_get_mmg_responses_raises_KeyError_if_unrecognised_status_code():
|
||||
with pytest.raises(KeyError) as e:
|
||||
get_mmg_responses('99')
|
||||
assert '99' in str(e.value)
|
||||
|
||||
@@ -35,7 +35,7 @@ def test_process_sms_response_raises_client_exception_for_unknown_status(
|
||||
assert sample_notification.status == NOTIFICATION_TECHNICAL_FAILURE
|
||||
|
||||
|
||||
@pytest.mark.parametrize('status, substatus, sms_provider, expected_notification_status, reason', [
|
||||
@pytest.mark.parametrize('status, detailed_status_code, sms_provider, expected_notification_status, reason', [
|
||||
('0', None, 'Firetext', 'delivered', None),
|
||||
('1', '101', 'Firetext', 'permanent-failure', 'Unknown Subscriber'),
|
||||
('2', '102', 'Firetext', 'pending', 'Absent Subscriber'),
|
||||
@@ -48,7 +48,7 @@ def test_process_sms_client_response_updates_notification_status(
|
||||
sample_notification,
|
||||
mocker,
|
||||
status,
|
||||
substatus,
|
||||
detailed_status_code,
|
||||
sms_provider,
|
||||
expected_notification_status,
|
||||
reason
|
||||
@@ -56,14 +56,14 @@ def test_process_sms_client_response_updates_notification_status(
|
||||
mock_logger = mocker.patch('app.celery.tasks.current_app.logger.info')
|
||||
sample_notification.status = 'sending'
|
||||
|
||||
process_sms_client_response(status, str(sample_notification.id), sms_provider, substatus)
|
||||
process_sms_client_response(status, str(sample_notification.id), sms_provider, detailed_status_code)
|
||||
|
||||
message = f"{sms_provider} callback returned status of {expected_notification_status}: {reason} for reference: {sample_notification.id}" # noqa
|
||||
mock_logger.assert_any_call(message)
|
||||
assert sample_notification.status == expected_notification_status
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code, expected_notification_status, reason', [
|
||||
@pytest.mark.parametrize('detailed_status_code, expected_notification_status, reason', [
|
||||
('101', 'permanent-failure', 'Unknown Subscriber'),
|
||||
('102', 'temporary-failure', 'Absent Subscriber'),
|
||||
(None, 'temporary-failure', None),
|
||||
@@ -72,7 +72,7 @@ def test_process_sms_client_response_updates_notification_status(
|
||||
def test_process_sms_client_response_updates_notification_status_when_called_second_time(
|
||||
sample_notification,
|
||||
mocker,
|
||||
code,
|
||||
detailed_status_code,
|
||||
expected_notification_status,
|
||||
reason
|
||||
):
|
||||
@@ -80,29 +80,29 @@ def test_process_sms_client_response_updates_notification_status_when_called_sec
|
||||
sample_notification.status = 'sending'
|
||||
process_sms_client_response('2', str(sample_notification.id), 'Firetext')
|
||||
|
||||
process_sms_client_response('1', str(sample_notification.id), 'Firetext', code)
|
||||
process_sms_client_response('1', str(sample_notification.id), 'Firetext', detailed_status_code)
|
||||
|
||||
if code and code != '000':
|
||||
if detailed_status_code and detailed_status_code != '000':
|
||||
message = f'Updating notification id {sample_notification.id} to status {expected_notification_status}, reason: {reason}' # noqa
|
||||
mock_logger.assert_called_with(message)
|
||||
|
||||
assert sample_notification.status == expected_notification_status
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code', ['102', None, '000'])
|
||||
def test_process_sms_client_response_updates_notification_status_to_pending_with_and_without_failire_code_present(
|
||||
@pytest.mark.parametrize('detailed_status_code', ['102', None, '000'])
|
||||
def test_process_sms_client_response_updates_notification_status_to_pending_with_and_without_failure_code_present(
|
||||
sample_notification,
|
||||
mocker,
|
||||
code
|
||||
detailed_status_code
|
||||
):
|
||||
sample_notification.status = 'sending'
|
||||
|
||||
process_sms_client_response('2', str(sample_notification.id), 'Firetext', code)
|
||||
process_sms_client_response('2', str(sample_notification.id), 'Firetext', detailed_status_code)
|
||||
|
||||
assert sample_notification.status == 'pending'
|
||||
|
||||
|
||||
def test_process_sms_client_response_updates_notification_status_when_code_unknown(
|
||||
def test_process_sms_client_response_updates_notification_status_when_detailed_status_code_not_recognised(
|
||||
sample_notification,
|
||||
mocker,
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user