From 429a23934d2846ce2453d2f4c8976647acef32a9 Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Tue, 4 Dec 2018 15:07:20 +0000 Subject: [PATCH] Display cancelled letters show as failed In the long term, we don't want to show cancelled letters. But for now, this changes cancelled letters to display in the same way that letters with a status of permanent-failure, since we are currently giving letters that we want to cancel the status of permanent failure. --- app/__init__.py | 2 ++ app/notify_client/job_api_client.py | 3 ++- app/templates/components/table.html | 2 +- app/templates/views/notifications/notification.html | 2 +- app/utils.py | 3 ++- tests/app/main/views/test_activity.py | 5 +++-- tests/app/main/views/test_jobs.py | 6 ++++-- tests/app/main/views/test_notifications.py | 4 ++++ 8 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 92397a688..0221981a8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -373,6 +373,7 @@ def format_notification_status(status, template_type): 'pending-virus-check': 'Pending virus check', 'virus-scan-failed': 'Virus detected', 'returned-letter': 'Delivered', + 'cancelled': 'Cancelled,' } }[template_type].get(status, status) @@ -398,6 +399,7 @@ def format_notification_status_as_field_status(status, notification_type): 'pending-virus-check': None, 'virus-scan-failed': 'error', 'returned-letter': None, + 'cancelled': 'error', } }.get( notification_type, diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index 34dfdbe88..c40feebce 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -25,7 +25,8 @@ class JobApiClient(NotifyAdminAPIClient): def __convert_statistics(job): results = defaultdict(int) for outcome in job['statistics']: - if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']: + if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', + 'permanent-failure', 'cancelled']: results['failed'] += outcome['count'] if outcome['status'] in ['sending', 'pending', 'created']: results['sending'] += outcome['count'] diff --git a/app/templates/components/table.html b/app/templates/components/table.html index bb0c76196..cb5622c60 100644 --- a/app/templates/components/table.html +++ b/app/templates/components/table.html @@ -162,7 +162,7 @@ notification.template.template_type ) }} {% endif %} - {% if notification.notification_type == "letter" and notification.status in ['permanent-failure', 'validation-failed'] %} + {% if notification.notification_type == "letter" and notification.status in ['permanent-failure', 'validation-failed', 'cancelled'] %} Cancelled {% endif %} {% if notification.status|format_notification_status_as_url(notification.notification_type) %} diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html index 78a618908..29bf446d0 100644 --- a/app/templates/views/notifications/notification.html +++ b/app/templates/views/notifications/notification.html @@ -37,7 +37,7 @@

{% if template.template_type == 'letter' %} - {% if notification_status == 'permanent-failure' %} + {% if notification_status in ('permanent-failure', 'cancelled') %}

Cancelled {{ updated_at|format_datetime_short }}

diff --git a/app/utils.py b/app/utils.py index d15ed9cc6..0d771275c 100644 --- a/app/utils.py +++ b/app/utils.py @@ -39,7 +39,8 @@ from werkzeug.datastructures import MultiDict SENDING_STATUSES = ['created', 'pending', 'sending', 'pending-virus-check'] DELIVERED_STATUSES = ['delivered', 'sent', 'returned-letter'] -FAILURE_STATUSES = ['failed', 'temporary-failure', 'permanent-failure', 'technical-failure', 'virus-scan-failed'] +FAILURE_STATUSES = ['failed', 'temporary-failure', 'permanent-failure', + 'technical-failure', 'virus-scan-failed', 'cancelled'] REQUESTED_STATUSES = SENDING_STATUSES + DELIVERED_STATUSES + FAILURE_STATUSES diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py index 1a028867b..b6c2f1a52 100644 --- a/tests/app/main/views/test_activity.py +++ b/tests/app/main/views/test_activity.py @@ -52,7 +52,8 @@ from tests.conftest import ( [ 'created', 'pending', 'sending', 'pending-virus-check', 'delivered', 'sent', 'returned-letter', - 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure', 'virus-scan-failed', + 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure', + 'virus-scan-failed', 'cancelled', ] ), ( @@ -65,7 +66,7 @@ from tests.conftest import ( ), ( 'failed', - ['failed', 'temporary-failure', 'permanent-failure', 'technical-failure', 'virus-scan-failed'] + ['failed', 'temporary-failure', 'permanent-failure', 'technical-failure', 'virus-scan-failed', 'cancelled'] ) ] ) diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 98729d3f4..22d5ac11a 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -156,7 +156,8 @@ def test_jobs_page_doesnt_show_scheduled_on_page_2( [ 'created', 'pending', 'sending', 'pending-virus-check', 'delivered', 'sent', 'returned-letter', - 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure', 'virus-scan-failed', + 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure', + 'virus-scan-failed', 'cancelled', ] ), ( @@ -169,7 +170,7 @@ def test_jobs_page_doesnt_show_scheduled_on_page_2( ), ( 'failed', - ['failed', 'temporary-failure', 'permanent-failure', 'technical-failure', 'virus-scan-failed'] + ['failed', 'temporary-failure', 'permanent-failure', 'technical-failure', 'virus-scan-failed', 'cancelled'] ) ] ) @@ -339,6 +340,7 @@ def test_should_show_letter_job( 'permanent-failure', 'technical-failure', 'virus-scan-failed', + 'cancelled', ], ) diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index 48c234b27..0c7df6afb 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -195,6 +195,10 @@ def test_notification_page_shows_page_for_letter_notification( 'permanent-failure', 'Cancelled 1 January at 1:02am', ), + ( + 'cancelled', + 'Cancelled 1 January at 1:02am', + ), ( 'validation-failed', 'Cancelled 1 January at 1:02am (letter has content outside the printable area)',