From 0e473cace595508fcaa5da04e23e2c18b9f3eff3 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Thu, 16 Nov 2017 14:45:02 +0000 Subject: [PATCH] Update rest endpoint to handle include_jobs arg --- app/v2/notifications/get_notifications.py | 6 +++- .../notifications/test_get_notifications.py | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/v2/notifications/get_notifications.py b/app/v2/notifications/get_notifications.py index cd721f596..14adb9028 100644 --- a/app/v2/notifications/get_notifications.py +++ b/app/v2/notifications/get_notifications.py @@ -35,6 +35,9 @@ def get_notifications(): if 'reference' in _data: _data['reference'] = _data['reference'][0] + if 'include_jobs' in _data: + _data['include_jobs'] = _data['include_jobs'][0] + data = validate(_data, get_notifications_request) paginated_notifications = notifications_dao.get_notifications_for_service( @@ -44,7 +47,8 @@ def get_notifications(): personalisation=True, older_than=data.get('older_than'), client_reference=data.get('reference'), - page_size=current_app.config.get('API_PAGE_SIZE') + page_size=current_app.config.get('API_PAGE_SIZE'), + include_jobs=data.get('include_jobs') ) def _build_links(notifications): diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index fc6b091c9..5519c3d1a 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -295,6 +295,34 @@ def test_get_all_notifications_returns_200(client, sample_template): assert not json_response['notifications'][0]['scheduled_for'] +def test_get_all_notifications_with_include_jobs_arg_returns_200( + client, sample_template, sample_job +): + notifications = [ + create_notification(template=sample_template, job=sample_job), + create_notification(template=sample_template) + ] + notification = notifications[-1] + + auth_header = create_authorization_header(service_id=notification.service_id) + response = client.get( + path='/v2/notifications?include_jobs=true', + headers=[('Content-Type', 'application/json'), auth_header]) + + json_response = json.loads(response.get_data(as_text=True)) + + assert response.status_code == 200 + assert json_response['links']['current'].endswith("/v2/notifications?include_jobs=true") + assert 'next' in json_response['links'].keys() + assert len(json_response['notifications']) == 2 + + assert json_response['notifications'][0]['id'] == str(notification.id) + assert json_response['notifications'][0]['status'] == notification.status + assert json_response['notifications'][0]['phone_number'] == notification.to + assert json_response['notifications'][0]['type'] == notification.template.template_type + assert not json_response['notifications'][0]['scheduled_for'] + + def test_get_all_notifications_no_notifications_if_no_notifications(client, sample_service): auth_header = create_authorization_header(service_id=sample_service.id) response = client.get(