From a564b9aeb010cb654547e3d3c94cb25b64990f3c Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 8 May 2017 17:20:21 +0100 Subject: [PATCH] Update /service/{}/notifications to look for a "to" query string, if it exists call the search notifications_by_to_field method. --- app/schemas.py | 1 + app/service/rest.py | 4 +++- tests/app/service/test_rest.py | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/schemas.py b/app/schemas.py index 2a42c7d15..2435b9a83 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -492,6 +492,7 @@ class NotificationsFilterSchema(ma.Schema): include_from_test_key = fields.Boolean(required=False) older_than = fields.UUID(required=False) format_for_csv = fields.String() + to = fields.String() @pre_load def handle_multidict(self, in_data): diff --git a/app/service/rest.py b/app/service/rest.py index 01a7fd07a..4122db82a 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -242,6 +242,8 @@ def get_service_history(service_id): @service_blueprint.route('//notifications', methods=['GET']) def get_all_notifications_for_service(service_id): data = notifications_filter_schema.load(request.args).data + if data.get("to", None): + return search_for_notification_by_to_field(service_id, request.query_string.decode()) page = data['page'] if 'page' in data else 1 page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE') limit_days = data.get('limit_days') @@ -271,8 +273,8 @@ def get_all_notifications_for_service(service_id): ), 200 -@service_blueprint.route('//notification/', methods=['GET']) def search_for_notification_by_to_field(service_id, search_term): + search_term = search_term.replace('to=', '') results = notifications_dao.dao_get_notifications_by_to_field(service_id, search_term) return jsonify( notifications=notification_with_template_schema.dump(results, many=True).data), 200 diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 22e1dfd3f..f0bae91cb 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1621,7 +1621,7 @@ def test_search_for_notification_by_to_field(client, notify_db, notify_db_sessio to_field="+447700900855") notification2 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com") - response = client.get('/service/{}/notification/{}'.format(notification1.service_id, "jack@gmail.com"), + response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "jack@gmail.com"), headers=[create_authorization_header()]) assert response.status_code == 200 result = json.loads(response.get_data(as_text=True)) @@ -1635,7 +1635,7 @@ def test_search_for_notification_by_to_field_return_empty_list_if_there_is_no_ma to_field="+447700900855") notification2 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com") - response = client.get('/service/{}/notification/{}'.format(notification1.service_id, "+447700900800"), + response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "+447700900800"), headers=[create_authorization_header()]) assert response.status_code == 200 assert len(json.loads(response.get_data(as_text=True))["notifications"]) == 0 @@ -1651,7 +1651,7 @@ def test_search_for_notification_by_to_field_return_multiple_matches( to_field="+44770 0900 855") notification4 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com") - response = client.get('/service/{}/notification/{}'.format(notification1.service_id, "+447700900855"), + response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "+447700900855"), headers=[create_authorization_header()]) assert response.status_code == 200 result = json.loads(response.get_data(as_text=True))