Add process_mmg_responses

Refactor process_firetext_responses
Removed the abstract ClientResponses for firetext and mmg. There is a map for each response to handle the status codes sent by each client.
Since MMG has about 20 different status code, none of which seem to be a pending state (unlike firetext that has 3 status one for pending - network delay).
For MMG status codes, look for 00 as successful, everything else is assumed to be a failure.
This commit is contained in:
Rebecca Law
2016-04-06 14:31:33 +01:00
parent f2ee8f3eb7
commit 4806123d5c
11 changed files with 343 additions and 191 deletions

View File

@@ -1,32 +1,33 @@
import pytest
from app.clients.sms import firetext
responses = firetext.FiretextResponses()
from app.clients.sms.firetext import get_firetext_responses
def test_should_return_correct_details_for_delivery():
assert responses.response_code_to_message('0') == 'Delivered'
assert responses.response_code_to_notification_status('0') == 'delivered'
assert responses.response_code_to_notification_statistics_status('0') == 'delivered'
assert responses.response_code_to_notification_success('0')
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']
def test_should_return_correct_details_for_bounced():
assert responses.response_code_to_message('1') == 'Declined'
assert responses.response_code_to_notification_status('1') == 'failed'
assert responses.response_code_to_notification_statistics_status('1') == 'failure'
assert not responses.response_code_to_notification_success('1')
response_dict = get_firetext_responses('1')
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_complaint():
assert responses.response_code_to_message('2') == 'Undelivered (Pending with Network)'
assert responses.response_code_to_notification_status('2') == 'sent'
assert not responses.response_code_to_notification_statistics_status('2')
assert not responses.response_code_to_notification_success('2')
response_dict = get_firetext_responses('2')
assert response_dict['message'] == 'Undelivered (Pending with Network)'
assert response_dict['notification_status'] == 'sent'
assert not response_dict['notification_statistics_status']
assert not response_dict['success']
def test_should_be_none_if_unrecognised_status_code():
with pytest.raises(KeyError) as e:
responses.response_code_to_object('99')
get_firetext_responses('99')
assert '99' in str(e.value)