From ef799d0515e29aefe9b3e06a90654b67e9e2422d Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 30 May 2017 11:08:59 +0100 Subject: [PATCH] add sad path tests for inbound sms --- .../test_receive_notification.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/app/notifications/test_receive_notification.py b/tests/app/notifications/test_receive_notification.py index 3a38449a4..d4f14e5bc 100644 --- a/tests/app/notifications/test_receive_notification.py +++ b/tests/app/notifications/test_receive_notification.py @@ -2,13 +2,14 @@ from datetime import datetime import pytest from flask import json -import freezegun from app.notifications.receive_notifications import ( format_message, create_inbound_sms_object ) +from tests.app.db import create_service + def test_receive_notification_returns_received_to_mmg(client, sample_service): data = {"ID": "1234", @@ -57,3 +58,26 @@ def test_create_inbound_sms_object(sample_service): assert inbound_sms.provider_reference == 'bar' assert inbound_sms._content != 'hello there 📩' assert inbound_sms.content == 'hello there 📩' + + +@pytest.mark.parametrize('notify_number', ['foo', 'baz'], ids=['two_matching_services', 'no_matching_services']) +def test_receive_notification_error_if_not_single_matching_service(client, notify_db_session, notify_number): + create_service(service_name='a', sms_sender='foo') + create_service(service_name='b', sms_sender='foo') + + data = { + 'Message': 'hello', + 'Number': notify_number, + 'MSISDN': '7700900001', + 'DateReceived': '2017-01-02 03:04:05', + 'ID': 'bar', + } + response = client.post(path='/notifications/sms/receive/mmg', + data=json.dumps(data), + headers=[('Content-Type', 'application/json')]) + + assert response.status_code == 400 + assert json.loads(response.get_data(as_text=True)) == { + 'result': 'error', + 'message': 'Inbound number "{}" not associated with exactly one service'.format(notify_number) + }