Set sent_by if not set during sms provider callback

- refactored argument reference to provider_reference to make it clearer
This commit is contained in:
Ken Tsang
2018-03-21 18:11:10 +00:00
parent 5481d743ac
commit ffa093d8c7
3 changed files with 57 additions and 19 deletions

View File

@@ -61,7 +61,7 @@ def test_outcome_statistics_called_for_successful_callback(sample_notification,
callback_api = create_service_callback_api(service=sample_notification.service, url="https://original_url.com")
reference = str(uuid.uuid4())
success, error = process_sms_client_response(status='3', reference=reference, client_name='MMG')
success, error = process_sms_client_response(status='3', provider_reference=reference, client_name='MMG')
assert success == "MMG callback succeeded. reference {} updated".format(str(reference))
assert error is None
encrypted_data = create_encrypted_callback_data(sample_notification, callback_api)
@@ -78,24 +78,44 @@ def test_sms_resonse_does_not_call_send_callback_if_no_db_entry(sample_notificat
'app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async'
)
reference = str(uuid.uuid4())
process_sms_client_response(status='3', reference=reference, client_name='MMG')
process_sms_client_response(status='3', provider_reference=reference, client_name='MMG')
send_mock.assert_not_called()
def test_process_sms_response_return_success_for_send_sms_code_reference(mocker):
success, error = process_sms_client_response(status='000', reference='send-sms-code', client_name='sms-client')
success, error = process_sms_client_response(
status='000', provider_reference='send-sms-code', client_name='sms-client')
assert success == "{} callback succeeded: send-sms-code".format('sms-client')
assert error is None
def test_process_sms_updates_sent_by_with_client_name_if_not_in_noti(notify_db, sample_notification):
sample_notification.sent_by = None
success, error = process_sms_client_response(
status='3', provider_reference=str(sample_notification.id), client_name='MMG')
assert error is None
assert success == 'MMG callback succeeded. reference {} updated'.format(sample_notification.id)
assert sample_notification.sent_by == 'MMG'
def test_process_sms_does_not_update_sent_by_if_already_set(mocker, notify_db, sample_notification):
mock_update = mocker.patch('app.notifications.process_client_response.set_notification_sent_by')
sample_notification.sent_by = 'MMG'
process_sms_client_response(
status='3', provider_reference=str(sample_notification.id), client_name='MMG')
assert not mock_update.called
def test_process_sms_response_returns_error_bad_reference(mocker):
success, error = process_sms_client_response(status='000', reference='something-bad', client_name='sms-client')
success, error = process_sms_client_response(
status='000', provider_reference='something-bad', client_name='sms-client')
assert success is None
assert error == "{} callback with invalid reference {}".format('sms-client', 'something-bad')
def test_process_sms_response_raises_client_exception_for_unknown_sms_client(mocker):
success, error = process_sms_client_response(status='000', reference=str(uuid.uuid4()), client_name='sms-client')
success, error = process_sms_client_response(
status='000', provider_reference=str(uuid.uuid4()), client_name='sms-client')
assert success is None
assert error == 'unknown sms client: {}'.format('sms-client')
@@ -103,6 +123,6 @@ def test_process_sms_response_raises_client_exception_for_unknown_sms_client(moc
def test_process_sms_response_raises_client_exception_for_unknown_status(mocker):
with pytest.raises(ClientException) as e:
process_sms_client_response(status='000', reference=str(uuid.uuid4()), client_name='Firetext')
process_sms_client_response(status='000', provider_reference=str(uuid.uuid4()), client_name='Firetext')
assert "{} callback failed: status {} not found.".format('Firetext', '000') in str(e.value)