From 3c416d36315eb351a771b407d851880ccd91c5c7 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Wed, 31 May 2017 16:15:25 +0100 Subject: [PATCH 1/2] Simple end point for fire text inbound SMS callbacks. --- app/notifications/receive_notifications.py | 12 +++++++++++- .../app/notifications/test_receive_notification.py | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/notifications/receive_notifications.py b/app/notifications/receive_notifications.py index 08122fb41..9c6b63c48 100644 --- a/app/notifications/receive_notifications.py +++ b/app/notifications/receive_notifications.py @@ -1,5 +1,5 @@ from flask import Blueprint -from flask import current_app +from flask import current_app, jsonify from flask import request from app.errors import register_errors @@ -15,3 +15,13 @@ def receive_mmg_sms(): current_app.logger.info("Recieve notification form data: {}".format(post_data)) return "RECEIVED" + + +@receive_notifications_blueprint.route('/notifications/sms/receive/firetext', methods=['POST']) +def receive_firetext_sms(): + post_data = request.get_json() + current_app.logger.info("Received Firetext notification form data: {}".format(post_data)) + + return jsonify({ + "status": "ok" + }), 200 diff --git a/tests/app/notifications/test_receive_notification.py b/tests/app/notifications/test_receive_notification.py index f325fe6f9..91eac620a 100644 --- a/tests/app/notifications/test_receive_notification.py +++ b/tests/app/notifications/test_receive_notification.py @@ -16,3 +16,16 @@ def test_receive_notification_returns_received_to_mmg(client): assert response.status_code == 200 assert response.get_data(as_text=True) == 'RECEIVED' + + +def test_receive_notification_returns_received_to_firetext(client): + data = {"some": "thing"} + response = client.post( + path='/notifications/sms/receive/firetext', + data=json.dumps(data), + headers=[('Content-Type', 'application/json')]) + + assert response.status_code == 200 + result = json.loads(response.get_data(as_text=True)) + + assert result['status'] == 'ok' From a7fd624db5a14530dd867bbdab41527244b9bf04 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Thu, 1 Jun 2017 08:21:18 +0100 Subject: [PATCH 2/2] Added simple logging endpoint for fire text inbound SMS calls - logs post data - OK to log all as not currently in use so no real user data expected. --- app/notifications/receive_notifications.py | 2 +- tests/app/notifications/test_receive_notification.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/notifications/receive_notifications.py b/app/notifications/receive_notifications.py index 9c6b63c48..923701cda 100644 --- a/app/notifications/receive_notifications.py +++ b/app/notifications/receive_notifications.py @@ -19,7 +19,7 @@ def receive_mmg_sms(): @receive_notifications_blueprint.route('/notifications/sms/receive/firetext', methods=['POST']) def receive_firetext_sms(): - post_data = request.get_json() + post_data = request.form current_app.logger.info("Received Firetext notification form data: {}".format(post_data)) return jsonify({ diff --git a/tests/app/notifications/test_receive_notification.py b/tests/app/notifications/test_receive_notification.py index 91eac620a..e82d3e638 100644 --- a/tests/app/notifications/test_receive_notification.py +++ b/tests/app/notifications/test_receive_notification.py @@ -19,11 +19,12 @@ def test_receive_notification_returns_received_to_mmg(client): def test_receive_notification_returns_received_to_firetext(client): - data = {"some": "thing"} + data = "source=07999999999&destination=07111111111&message=this is a message&time=2017-01-01 12:00:00" + response = client.post( path='/notifications/sms/receive/firetext', - data=json.dumps(data), - headers=[('Content-Type', 'application/json')]) + data=data, + headers=[('Content-Type', 'application/x-www-form-urlencoded')]) assert response.status_code == 200 result = json.loads(response.get_data(as_text=True))