Merge pull request #3179 from alphagov/add-international-firetext-api-key

Add international API key for firetext
This commit is contained in:
Rebecca Law
2021-04-21 08:49:11 +01:00
committed by GitHub
9 changed files with 66 additions and 29 deletions

View File

@@ -47,7 +47,7 @@ def test_send_sms_successful_returns_firetext_response(mocker, mock_firetext_cli
with requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/firetext', json=response_dict, status_code=200)
response = mock_firetext_client.send_sms(to, content, reference)
response = mock_firetext_client.send_sms(to, content, reference, False)
response_json = response.json()
assert response.status_code == 200
@@ -65,7 +65,7 @@ def test_send_sms_calls_firetext_correctly(mocker, mock_firetext_client):
with requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/firetext', json=response_dict, status_code=200)
mock_firetext_client.send_sms(to, content, reference)
mock_firetext_client.send_sms(to, content, reference, False)
assert request_mock.call_count == 1
assert request_mock.request_history[0].url == 'https://example.com/firetext'
@@ -79,6 +79,30 @@ def test_send_sms_calls_firetext_correctly(mocker, mock_firetext_client):
assert request_args['reference'][0] == reference
def test_send_sms_calls_firetext_correctly_for_international(mocker, mock_firetext_client):
to = '+607234567890'
content = 'my message'
reference = 'my reference'
response_dict = {
'code': 0,
}
with requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/firetext', json=response_dict, status_code=200)
mock_firetext_client.send_sms(to, content, reference, True)
assert request_mock.call_count == 1
assert request_mock.request_history[0].url == 'https://example.com/firetext'
assert request_mock.request_history[0].method == 'POST'
request_args = parse_qs(request_mock.request_history[0].text)
assert request_args['apiKey'][0] == 'international'
assert request_args['from'][0] == 'bar'
assert request_args['to'][0] == '607234567890'
assert request_args['message'][0] == content
assert request_args['reference'][0] == reference
def test_send_sms_raises_if_firetext_rejects(mocker, mock_firetext_client):
to = content = reference = 'foo'
response_dict = {
@@ -90,7 +114,7 @@ def test_send_sms_raises_if_firetext_rejects(mocker, mock_firetext_client):
with pytest.raises(SmsClientResponseException) as exc, requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/firetext', json=response_dict, status_code=200)
mock_firetext_client.send_sms(to, content, reference)
mock_firetext_client.send_sms(to, content, reference, False)
assert exc.value.status_code == 200
assert '"description": "Some kind of error"' in exc.value.text
@@ -103,7 +127,7 @@ def test_send_sms_raises_if_firetext_rejects_with_unexpected_data(mocker, mock_f
with pytest.raises(SmsClientResponseException) as exc, requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/firetext', json=response_dict, status_code=400)
mock_firetext_client.send_sms(to, content, reference)
mock_firetext_client.send_sms(to, content, reference, False)
assert exc.value.status_code == 400
assert exc.value.text == '{"something": "gone bad"}'
@@ -121,7 +145,7 @@ def test_send_sms_override_configured_shortcode_with_sender(mocker, mock_firetex
with requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/firetext', json=response_dict, status_code=200)
mock_firetext_client.send_sms(to, content, reference, sender=sender)
mock_firetext_client.send_sms(to, content, reference, False, sender=sender)
request_args = parse_qs(request_mock.request_history[0].text)
assert request_args['from'][0] == 'fromservice'
@@ -132,7 +156,7 @@ def test_send_sms_raises_if_firetext_rejects_with_connect_timeout(rmock, mock_fi
with pytest.raises(FiretextClientResponseException) as exc:
rmock.register_uri('POST', 'https://example.com/firetext', exc=ConnectTimeout)
mock_firetext_client.send_sms(to, content, reference)
mock_firetext_client.send_sms(to, content, reference, False)
assert exc.value.status_code == 504
assert exc.value.text == 'Gateway Time-out'
@@ -143,7 +167,7 @@ def test_send_sms_raises_if_firetext_rejects_with_read_timeout(rmock, mock_firet
with pytest.raises(FiretextClientResponseException) as exc:
rmock.register_uri('POST', 'https://example.com/firetext', exc=ReadTimeout)
mock_firetext_client.send_sms(to, content, reference)
mock_firetext_client.send_sms(to, content, reference, False)
assert exc.value.status_code == 504
assert exc.value.text == 'Gateway Time-out'

View File

@@ -44,7 +44,7 @@ def test_send_sms_successful_returns_mmg_response(notify_api, mocker):
with requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/mmg', json=response_dict, status_code=200)
response = mmg_client.send_sms(to, content, reference)
response = mmg_client.send_sms(to, content, reference, False)
response_json = response.json()
assert response.status_code == 200
@@ -59,7 +59,7 @@ def test_send_sms_calls_mmg_correctly(notify_api, mocker):
with requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/mmg', json=response_dict, status_code=200)
mmg_client.send_sms(to, content, reference)
mmg_client.send_sms(to, content, reference, False)
assert request_mock.call_count == 1
assert request_mock.request_history[0].url == 'https://example.com/mmg'
@@ -83,7 +83,7 @@ def test_send_sms_raises_if_mmg_rejects(notify_api, mocker):
with pytest.raises(SmsClientResponseException) as exc, requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/mmg', json=response_dict, status_code=400)
mmg_client.send_sms(to, content, reference)
mmg_client.send_sms(to, content, reference, False)
assert exc.value.status_code == 400
assert '"Error": 206' in exc.value.text
@@ -100,7 +100,7 @@ def test_send_sms_override_configured_shortcode_with_sender(notify_api, mocker):
with requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/mmg', json=response_dict, status_code=200)
mmg_client.send_sms(to, content, reference, sender=sender)
mmg_client.send_sms(to, content, reference, False, sender=sender)
request_args = request_mock.request_history[0].json()
assert request_args['sender'] == 'fromservice'
@@ -112,7 +112,7 @@ def test_send_sms_raises_if_mmg_fails_to_return_json(notify_api, mocker):
with pytest.raises(SmsClientResponseException) as exc, requests_mock.Mocker() as request_mock:
request_mock.post('https://example.com/mmg', text=response_dict, status_code=200)
mmg_client.send_sms(to, content, reference)
mmg_client.send_sms(to, content, reference, False)
assert 'Code 200 text NOT AT ALL VALID JSON {"key" : "value"}} exception Expecting value: line 1 column 1 (char 0)' in str(exc.value) # noqa
assert exc.value.status_code == 200
@@ -124,7 +124,7 @@ def test_send_sms_raises_if_mmg_rejects_with_connect_timeout(rmock):
with pytest.raises(MMGClientResponseException) as exc:
rmock.register_uri('POST', 'https://example.com/mmg', exc=ConnectTimeout)
mmg_client.send_sms(to, content, reference)
mmg_client.send_sms(to, content, reference, False)
assert exc.value.status_code == 504
assert exc.value.text == 'Gateway Time-out'
@@ -135,7 +135,7 @@ def test_send_sms_raises_if_mmg_rejects_with_read_timeout(rmock):
with pytest.raises(MMGClientResponseException) as exc:
rmock.register_uri('POST', 'https://example.com/mmg', exc=ReadTimeout)
mmg_client.send_sms(to, content, reference)
mmg_client.send_sms(to, content, reference, False)
assert exc.value.status_code == 504
assert exc.value.text == 'Gateway Time-out'

View File

@@ -594,6 +594,7 @@ def mock_firetext_client(mocker):
current_app = mocker.Mock(config={
'FIRETEXT_URL': 'https://example.com/firetext',
'FIRETEXT_API_KEY': 'foo',
'FIRETEXT_INTERNATIONAL_API_KEY': 'international',
'FROM_NUMBER': 'bar'
})
client.init_app(current_app, statsd_client)

View File

@@ -123,7 +123,8 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
to="447234123123",
content="Sample service: Hello Jo\nHere is <em>some HTML</em> & entities",
reference=str(db_notification.id),
sender=current_app.config['FROM_NUMBER']
sender=current_app.config['FROM_NUMBER'],
international=False
)
notification = Notification.query.filter_by(id=db_notification.id).one()
@@ -158,7 +159,7 @@ def test_should_send_personalised_template_to_correct_email_provider_and_persist
'Jo <em>some HTML</em>',
body='Hello Jo\nThis is an email from GOV.\u200bUK with <em>some HTML</em>\n',
html_body=ANY,
reply_to_address=None
reply_to_address=None,
)
assert '<!DOCTYPE html' in app.aws_ses_client.send_email.call_args[1]['html_body']
@@ -185,7 +186,7 @@ def test_should_not_send_email_message_when_service_is_inactive_notifcation_is_i
@pytest.mark.parametrize("client_send", ["app.mmg_client.send_sms", "app.firetext_client.send_sms"])
def test_should_not_send_sms_message_when_service_is_inactive_notifcation_is_in_tech_failure(
def test_should_not_send_sms_message_when_service_is_inactive_notification_is_in_tech_failure(
sample_service, sample_notification, mocker, client_send):
sample_service.active = False
send_mock = mocker.patch(client_send, return_value='reference')
@@ -226,7 +227,8 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
to=validate_and_format_phone_number("+447234123123"),
content="Sample service: This is a template:\nwith a newline",
reference=str(db_notification.id),
sender=current_app.config['FROM_NUMBER']
sender=current_app.config['FROM_NUMBER'],
international=False
)
persisted_notification = notifications_dao.get_notification_by_id(db_notification.id)
@@ -324,7 +326,8 @@ def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
to=ANY,
content=gsm_message,
reference=ANY,
sender=ANY
sender=ANY,
international=False
)
@@ -345,7 +348,8 @@ def test_send_sms_should_use_service_sms_sender(
to=ANY,
content=ANY,
reference=ANY,
sender=sms_sender.sms_sender
sender=sms_sender.sms_sender,
international=False
)
@@ -666,7 +670,8 @@ def test_should_send_sms_to_international_providers(
to="447234123999",
content=ANY,
reference=str(notification_uk.id),
sender=current_app.config['FROM_NUMBER']
sender=current_app.config['FROM_NUMBER'],
international=False
)
send_to_providers.send_sms_to_provider(
@@ -677,7 +682,8 @@ def test_should_send_sms_to_international_providers(
to="601117224412",
content=ANY,
reference=str(notification_international.id),
sender=current_app.config['FROM_NUMBER']
sender=current_app.config['FROM_NUMBER'],
international=True
)
assert notification_uk.status == 'sending'
@@ -715,6 +721,7 @@ def test_should_handle_sms_sender_and_prefix_message(
sender=expected_sender,
to=ANY,
reference=ANY,
international=False
)
@@ -750,7 +757,8 @@ def test_send_sms_to_provider_should_use_normalised_to(
send_mock.assert_called_once_with(to=notification.normalised_to,
content=ANY,
reference=str(notification.id),
sender=notification.reply_to_text)
sender=notification.reply_to_text,
international=False)
def test_send_email_to_provider_should_user_normalised_to(
@@ -801,7 +809,8 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
send_mock.assert_called_once_with(to=notification.normalised_to,
content=ANY,
reference=str(notification.id),
sender=notification.reply_to_text)
sender=notification.reply_to_text,
international=False)
def test_send_email_to_provider_should_return_template_if_found_in_redis(