From a20fc1aa47493ca117634b3a9f9ea8b95f048bd3 Mon Sep 17 00:00:00 2001 From: Adam Shimali Date: Wed, 18 May 2016 11:44:58 +0100 Subject: [PATCH] If user clicks failed or both filters for notifications status view, append all other failure states to query to api. --- app/main/views/jobs.py | 23 +++++++++++++++++++---- app/templates/views/notifications.html | 2 +- tests/app/main/views/test_jobs.py | 10 +++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index bb8275d2f..a9f969deb 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -41,6 +41,20 @@ def _parse_filter_args(filter_dict): ) +def _set_status_filters(filter_args): + if filter_args.get('status'): + if 'failed' in filter_args.get('status'): + filter_args['status'].extend(['temporary-failure', 'permanent-failure', 'technical-failure']) + else: + # default to everything + filter_args['status'] = ['delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure'] + + +def _set_template_filters(filter_args): + if not filter_args.get('template_type'): + filter_args['template_type'] = ['email', 'sms'] + + @main.route("/services//jobs") @login_required @user_has_permissions('view_activity', admin_override=True) @@ -119,12 +133,14 @@ def view_notifications(service_id): abort(404, "Invalid page argument ({}) reverting to page 1.".format(request.args['page'], None)) filter_args = _parse_filter_args(request.args) + _set_status_filters(filter_args) + _set_template_filters(filter_args) notifications = notification_api_client.get_notifications_for_service( service_id=service_id, page=page, - template_type=filter_args.get('template_type') if 'template_type' in filter_args else ['email', 'sms'], - status=filter_args.get('status') if 'status' in filter_args else ['delivered', 'failed'], + template_type=filter_args.get('template_type'), + status=filter_args.get('status'), limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS']) view_dict = MultiDict(request.args) prev_page = None @@ -152,8 +168,7 @@ def view_notifications(service_id): page=page, page_size=notifications['total'], template_type=filter_args.get('template_type') if 'template_type' in filter_args else ['email', 'sms'], - status=filter_args.get('status') - if 'status' in filter_args else ['delivered', 'failed'], + status=filter_args.get('status'), limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])['notifications']) return csv_content, 200, { 'Content-Type': 'text/csv; charset=utf-8', diff --git a/app/templates/views/notifications.html b/app/templates/views/notifications.html index 3e9b87438..3be1a0792 100644 --- a/app/templates/views/notifications.html +++ b/app/templates/views/notifications.html @@ -91,7 +91,7 @@

{% endcall %} - {{ text_field(item.status|capitalize) }} + {{ text_field(item.status|capitalize|replace('-', ' ')) }} {% call field(align='right') %} {{ item.updated_at|format_datetime_short }} diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index f0d834fbc..ff0de4afe 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -95,7 +95,7 @@ def test_should_show_notifications_for_a_service(app_, page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.h1.string.strip() == 'Activity' - mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed'], template_type=['email', 'sms']) # noqa + mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure'], template_type=['email', 'sms']) # noqa def test_can_view_only_sms_notifications_for_a_service(app_, @@ -123,7 +123,7 @@ def test_can_view_only_sms_notifications_for_a_service(app_, page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.h1.string.strip() == 'Text messages' - mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed'], template_type=['sms']) # noqa + mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure'], template_type=['sms']) # noqa def test_can_view_only_email_notifications_for_a_service(app_, @@ -151,7 +151,7 @@ def test_can_view_only_email_notifications_for_a_service(app_, page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.h1.string.strip() == 'Emails' - mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed'], template_type=['email']) # noqa + mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure'], template_type=['email']) # noqa def test_can_view_successful_notifications_for_a_service(app_, @@ -203,7 +203,7 @@ def test_can_view_failed_notifications_for_a_service(app_, page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.h1.string.strip() == 'Failed emails and text messages' - mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['failed'], template_type=['email', 'sms']) # noqa + mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['failed', 'temporary-failure', 'permanent-failure', 'technical-failure'], template_type=['email', 'sms']) # noqa def test_can_view_failed_combination_of_notification_type_and_status( @@ -225,7 +225,7 @@ def test_can_view_failed_combination_of_notification_type_and_status( page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.h1.string.strip() == 'Failed text messages' - mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['failed'], template_type=['sms']) # noqa + mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['failed', 'temporary-failure', 'permanent-failure', 'technical-failure'], template_type=['sms']) # noqa def test_should_show_notifications_for_a_service_with_next_previous(app_,