mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
tests for send_sms through mmg/firetext
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
from app.clients.sms.mmg import get_mmg_responses
|
||||
import pytest
|
||||
import requests_mock
|
||||
|
||||
from app.clients.sms.mmg import (get_mmg_responses, MMGClientException)
|
||||
|
||||
|
||||
def test_should_return_correct_details_for_delivery():
|
||||
@@ -23,3 +26,54 @@ def test_should_be_none_if_unrecognised_status_code():
|
||||
assert response_dict['notification_status'] == 'failed'
|
||||
assert response_dict['notification_statistics_status'] == 'failure'
|
||||
assert not response_dict['success']
|
||||
|
||||
|
||||
def test_send_sms_successful_returns_mmg_response(mocker, mock_mmg_client):
|
||||
to = content = reference = 'foo'
|
||||
response_dict = {'Reference': 12345678}
|
||||
|
||||
with requests_mock.Mocker() as request_mock:
|
||||
request_mock.post('https://www.mmgrp.co.uk/API/json/api.php', json=response_dict, status_code=200)
|
||||
response = mock_mmg_client.send_sms(to, content, reference)
|
||||
|
||||
response_json = response.json()
|
||||
assert response.status_code == 200
|
||||
assert response_json['Reference'] == 12345678
|
||||
|
||||
|
||||
def test_send_sms_calls_mmg_correctly(mocker, mock_mmg_client):
|
||||
to = '+447234567890'
|
||||
content = 'my message'
|
||||
reference = 'my reference'
|
||||
response_dict = {'Reference': 12345678}
|
||||
|
||||
with requests_mock.Mocker() as request_mock:
|
||||
request_mock.post('https://www.mmgrp.co.uk/API/json/api.php', json=response_dict, status_code=200)
|
||||
mock_mmg_client.send_sms(to, content, reference)
|
||||
|
||||
assert request_mock.call_count == 1
|
||||
assert request_mock.request_history[0].url == 'https://www.mmgrp.co.uk/API/json/api.php'
|
||||
assert request_mock.request_history[0].method == 'POST'
|
||||
|
||||
request_args = request_mock.request_history[0].json()
|
||||
assert request_args['reqType'] == 'BULK'
|
||||
assert request_args['MSISDN'] == to
|
||||
assert request_args['msg'] == content
|
||||
assert request_args['sender'] == 'bar'
|
||||
assert request_args['cid'] == reference
|
||||
assert request_args['multi'] is True
|
||||
|
||||
|
||||
def test_send_sms_raises_if_mmg_rejects(mocker, mock_mmg_client):
|
||||
to = content = reference = 'foo'
|
||||
response_dict = {
|
||||
'Error': 206,
|
||||
'Description': 'Some kind of error'
|
||||
}
|
||||
|
||||
with pytest.raises(MMGClientException) as exc, requests_mock.Mocker() as request_mock:
|
||||
request_mock.post('https://www.mmgrp.co.uk/API/json/api.php', json=response_dict, status_code=400)
|
||||
mock_mmg_client.send_sms(to, content, reference)
|
||||
|
||||
assert exc.value.code == 206
|
||||
assert exc.value.description == 'Some kind of error'
|
||||
|
||||
Reference in New Issue
Block a user