From 77f520acba154bddc1903169171e6157faf9b851 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 6 Mar 2017 11:58:49 +0000 Subject: [PATCH 1/2] Created an endpoint to test how the incoming messages from MMG will work. So this just prints the response to logs, removing the phone number first. Then returns the requested RECEIVED. --- app/__init__.py | 1 + app/notifications/rest.py | 9 +++++++++ .../notifications/test_receive_notification.py | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 tests/app/notifications/test_receive_notification.py diff --git a/app/__init__.py b/app/__init__.py index 2f834193b..d40b58895 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -123,6 +123,7 @@ def init_app(app): url_for('notifications.process_ses_response'), url_for('notifications.process_firetext_response'), url_for('notifications.process_mmg_response'), + url_for('notifications.receive_mmg_sms'), url_for('status.show_delivery_status'), url_for('spec.get_spec') ] diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 4f3282cb9..b9ac4ff9f 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -49,6 +49,15 @@ from app.errors import ( register_errors(notifications) +@notifications.route('/notifications/sms/receive/mmg', methods=['POST']) +def receive_mmg_sms(): + post_data = request.get_json() + post_data.pop('MSISDN', None) + current_app.logger.info("POST form data: {}".format(post_data)) + + return "RECEIVED" + + @notifications.route('/notifications/email/ses', methods=['POST']) def process_ses_response(): client_name = 'SES' diff --git a/tests/app/notifications/test_receive_notification.py b/tests/app/notifications/test_receive_notification.py new file mode 100644 index 000000000..f325fe6f9 --- /dev/null +++ b/tests/app/notifications/test_receive_notification.py @@ -0,0 +1,18 @@ +from flask import json + + +def test_receive_notification_returns_received_to_mmg(client): + data = {"ID": "1234", + "MSISDN": "447700900855", + "Message": "Some message to notify", + "Trigger": "Trigger?", + "Number": "40604", + "Channel": "SMS", + "DateReceived": "2012-06-27-12:33:00" + } + response = client.post(path='/notifications/sms/receive/mmg', + data=json.dumps(data), + headers=[('Content-Type', 'application/json')]) + + assert response.status_code == 200 + assert response.get_data(as_text=True) == 'RECEIVED' From 51ab7a5dbf213713f015a53b978bc9d805a38596 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Wed, 8 Mar 2017 14:40:12 +0000 Subject: [PATCH 2/2] Change log message --- app/notifications/rest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/notifications/rest.py b/app/notifications/rest.py index b9ac4ff9f..a255f0850 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -53,7 +53,7 @@ register_errors(notifications) def receive_mmg_sms(): post_data = request.get_json() post_data.pop('MSISDN', None) - current_app.logger.info("POST form data: {}".format(post_data)) + current_app.logger.info("Recieve notification form data: {}".format(post_data)) return "RECEIVED"