From cfcdfcc38c89f87771cb32504088dbaaeede22c1 Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Thu, 17 Jan 2019 14:22:58 +0000
Subject: [PATCH 1/2] Show if letters are sent using a test key
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
It’s inaccurate to have an estimated delivery date for letters sent
using a test key. We shouldn’t reassure people that:
- the letter won’t be printed
- (in the case of precompiled letters) that the letter has passed
validation
---
app/main/views/notifications.py | 5 +-
.../views/notifications/notification.html | 36 +++++++---
tests/app/main/views/test_notifications.py | 70 +++++++++++++++++++
tests/conftest.py | 14 ++--
4 files changed, 108 insertions(+), 17 deletions(-)
diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py
index 1277da379..a4841d970 100644
--- a/app/main/views/notifications.py
+++ b/app/main/views/notifications.py
@@ -125,7 +125,10 @@ def view_notification(service_id, notification_id):
can_receive_inbound=(current_service.has_permission('inbound_sms')),
is_precompiled_letter=notification['template']['is_precompiled_letter'],
letter_print_day=letter_print_day,
- show_cancel_button=show_cancel_button
+ show_cancel_button=show_cancel_button,
+ sent_with_test_key=(
+ notification.get('key_type') == KEY_TYPE_TEST
+ ),
)
diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html
index eda9a1460..6f5f1e8c3 100644
--- a/app/templates/views/notifications/notification.html
+++ b/app/templates/views/notifications/notification.html
@@ -16,7 +16,7 @@
{% if is_precompiled_letter %}
- Provided as PDF
+ Provided as PDF
{% else %}
{% if help %}
‘{{ template.name }}’
@@ -51,15 +51,31 @@
fixed the problem
{% else %}
-
- {{ letter_print_day }}
-
-
- Postage: {{ postage }} class
-
-
- Estimated delivery date: {{ estimated_letter_delivery_date|string|format_date_short }}
-
+ {% if sent_with_test_key %}
+
+ Postage: {{ postage }} class
+
+ {% if is_precompiled_letter %}
+
+ This letter has passed our checks, but it won’t be printed
+ because you used a test key
+
+ {% else %}
+
+ This letter won’t be printed because you used a test key
+
+ {% endif %}
+ {% else %}
+
+ {{ letter_print_day }}
+
+
+ Postage: {{ postage }} class
+
+
+ Estimated delivery date: {{ estimated_letter_delivery_date|string|format_date_short }}
+
+ {% endif %}
{% endif %}
{% endif %}
diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py
index ba926a159..e63b8ef73 100644
--- a/tests/app/main/views/test_notifications.py
+++ b/tests/app/main/views/test_notifications.py
@@ -191,6 +191,76 @@ def test_notification_page_shows_page_for_letter_notification(
assert mock_page_count.call_args_list[0][1]['values'] == {'name': 'Jo'}
+@freeze_time("2016-01-01 01:01")
+@pytest.mark.parametrize('is_precompiled_letter, expected_p1, expected_p2, expected_p3', (
+ (
+ True,
+ 'Provided as PDF on 1 January at 1:01am',
+ 'Postage: second class',
+ 'This letter has passed our checks, but it won’t be printed because you used a test key',
+ ),
+ (
+ False,
+ '‘sample template’ was sent on 1 January at 1:01am',
+ 'Postage: second class',
+ 'This letter won’t be printed because you used a test key',
+ ),
+))
+def test_notification_page_shows_page_for_letter_sent_with_test_key(
+ client_request,
+ mocker,
+ fake_uuid,
+ is_precompiled_letter,
+ expected_p1,
+ expected_p2,
+ expected_p3,
+):
+
+ mocker.patch(
+ 'app.main.views.notifications.view_letter_notification_as_preview',
+ return_value=b'foo'
+ )
+
+ mocker.patch(
+ 'app.main.views.notifications.pdf_page_count',
+ return_value=1
+ )
+
+ mocker.patch(
+ 'app.main.views.notifications.get_page_count_for_letter',
+ return_value=1,
+ )
+
+ notification = mock_get_notification(
+ mocker,
+ fake_uuid,
+ notification_status='created',
+ template_type='letter',
+ is_precompiled_letter=is_precompiled_letter,
+ postage='second',
+ key_type='test',
+ sent_one_off=False,
+ )
+ notification.created_at = datetime.utcnow()
+
+ page = client_request.get(
+ 'main.view_notification',
+ service_id=SERVICE_ONE_ID,
+ notification_id=fake_uuid,
+ )
+
+ assert normalize_spaces(page.select('main p:nth-of-type(1)')[0].text) == (
+ expected_p1
+ )
+ assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == (
+ expected_p2
+ )
+ assert normalize_spaces(page.select('main p:nth-of-type(3)')[0].text) == (
+ expected_p3
+ )
+ assert page.select('p.notification-status') == []
+
+
@pytest.mark.parametrize('notification_status, expected_message', (
(
'permanent-failure',
diff --git a/tests/conftest.py b/tests/conftest.py
index 8f46eb710..f77d66026 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -2693,7 +2693,8 @@ def mock_get_notification(
template_name='sample template',
is_precompiled_letter=False,
key_type=None,
- postage=None
+ postage=None,
+ sent_one_off=True,
):
def _get_notification(
service_id,
@@ -2708,11 +2709,12 @@ def mock_get_notification(
)['notifications'][0]
noti['id'] = notification_id
- noti['created_by'] = {
- 'id': fake_uuid,
- 'name': 'Test User',
- 'email_address': 'test@user.gov.uk'
- }
+ if sent_one_off:
+ noti['created_by'] = {
+ 'id': fake_uuid,
+ 'name': 'Test User',
+ 'email_address': 'test@user.gov.uk'
+ }
noti['personalisation'] = {'name': 'Jo'}
noti['template'] = template_json(
service_id,
From 085856e062c1779d41fe4ff2194601e8a502497b Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Tue, 22 Jan 2019 10:38:40 +0000
Subject: [PATCH 2/2] Revised wording to avoid negative contraction
---
app/templates/views/notifications/notification.html | 5 ++---
tests/app/main/views/test_notifications.py | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html
index 6f5f1e8c3..c51ce0ce7 100644
--- a/app/templates/views/notifications/notification.html
+++ b/app/templates/views/notifications/notification.html
@@ -57,12 +57,11 @@
{% if is_precompiled_letter %}
- This letter has passed our checks, but it won’t be printed
- because you used a test key
+ This letter passed our checks, but we will not print it because you used a test key.
{% else %}
- This letter won’t be printed because you used a test key
+ We will not print this letter because you used a test key.
{% endif %}
{% else %}
diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py
index e63b8ef73..67db060d1 100644
--- a/tests/app/main/views/test_notifications.py
+++ b/tests/app/main/views/test_notifications.py
@@ -197,13 +197,13 @@ def test_notification_page_shows_page_for_letter_notification(
True,
'Provided as PDF on 1 January at 1:01am',
'Postage: second class',
- 'This letter has passed our checks, but it won’t be printed because you used a test key',
+ 'This letter passed our checks, but we will not print it because you used a test key.',
),
(
False,
'‘sample template’ was sent on 1 January at 1:01am',
'Postage: second class',
- 'This letter won’t be printed because you used a test key',
+ 'We will not print this letter because you used a test key.',
),
))
def test_notification_page_shows_page_for_letter_sent_with_test_key(