From 78ac345148a11ac93a242f5ef2a516f25b79e7f2 Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Mon, 17 Feb 2020 12:58:05 +0000
Subject: [PATCH 1/3] Put day of week on
This helps people understand how delivery dates fit into the week,
because if sending a letter spans the weekend it will take a bit longer.
We can remove `|string` now because `utc_string_to_aware_gmt_datetime`
now accepts datetimes.
---
app/__init__.py | 5 +++++
app/templates/views/notifications/notification.html | 2 +-
tests/app/main/views/test_notifications.py | 6 ++++--
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/app/__init__.py b/app/__init__.py
index 4daf81b80..0242fea30 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -334,6 +334,10 @@ def format_date_human(date):
return get_human_day(date)
+def format_day_of_week(date):
+ return utc_string_to_aware_gmt_datetime(date).strftime('%A')
+
+
def _format_datetime_short(datetime):
return datetime.strftime('%d %B').lstrip('0')
@@ -743,6 +747,7 @@ def add_template_filters(application):
format_date_normal,
format_date_short,
format_datetime_relative,
+ format_day_of_week,
format_delta,
format_notification_status,
format_notification_type,
diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html
index f422414ea..f2004a6ec 100644
--- a/app/templates/views/notifications/notification.html
+++ b/app/templates/views/notifications/notification.html
@@ -67,7 +67,7 @@
{{ letter_print_day }}
- Estimated delivery date: {{ estimated_letter_delivery_date|string|format_date_short }}
+ Estimated delivery date: {{ estimated_letter_delivery_date|format_day_of_week }} {{ estimated_letter_delivery_date|format_date_short }}
{% endif %}
{% endif %}
diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py
index 012ccaa1a..426aeade2 100644
--- a/tests/app/main/views/test_notifications.py
+++ b/tests/app/main/views/test_notifications.py
@@ -202,7 +202,7 @@ def test_notification_page_shows_page_for_letter_notification(
'Printing starts today at 5:30pm'
)
assert normalize_spaces(page.select('main p:nth-of-type(3)')[0].text) == (
- 'Estimated delivery date: 6 January'
+ 'Estimated delivery date: Wednesday 6 January'
)
assert len(page.select('.letter-postage')) == 1
assert normalize_spaces(page.select_one('.letter-postage').text) == (
@@ -473,7 +473,9 @@ def test_notification_page_shows_page_for_first_class_letter_notification(
)
assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == 'Printing starts tomorrow at 5:30pm'
- assert normalize_spaces(page.select('main p:nth-of-type(3)')[0].text) == 'Estimated delivery date: 5 January'
+ assert normalize_spaces(page.select('main p:nth-of-type(3)')[0].text) == (
+ 'Estimated delivery date: Tuesday 5 January'
+ )
assert normalize_spaces(page.select_one('.letter-postage').text) == (
'Postage: first class'
)
From 904007201f8adf32fb7f9cf71bc7cc255a869018 Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Wed, 19 Feb 2020 17:11:31 +0000
Subject: [PATCH 2/3] Make date of sending relative
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This is a friendlier and better way of showing dates anywhere except in
a report which might be archived and referred back to later.
Bit trickier to implement here because a dat requires ‘on’ beforehand,
but we don’t say ‘on today’ in English.
---
app/__init__.py | 21 +++++++--
.../views/notifications/notification.html | 2 +-
tests/app/main/views/test_notifications.py | 45 ++++++++++++++-----
3 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/app/__init__.py b/app/__init__.py
index 0242fea30..c2921bafc 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -291,7 +291,7 @@ def format_time_24h(date):
return utc_string_to_aware_gmt_datetime(date).strftime('%H:%M')
-def get_human_day(time):
+def get_human_day(time, date_prefix=''):
# Add 1 minute to transform 00:00 into ‘midnight today’ instead of ‘midnight tomorrow’
date = (utc_string_to_aware_gmt_datetime(time) - timedelta(minutes=1)).date()
@@ -304,8 +304,15 @@ def get_human_day(time):
if date == (now - timedelta(days=1)).date():
return 'yesterday'
if date.strftime('%Y') != now.strftime('%Y'):
- return '{} {}'.format(_format_datetime_short(date), date.strftime('%Y'))
- return _format_datetime_short(date)
+ return '{} {} {}'.format(
+ date_prefix,
+ _format_datetime_short(date),
+ date.strftime('%Y'),
+ ).strip()
+ return '{} {}'.format(
+ date_prefix,
+ _format_datetime_short(date),
+ ).strip()
def format_time(date):
@@ -334,6 +341,13 @@ def format_date_human(date):
return get_human_day(date)
+def format_datetime_human(date, date_prefix=''):
+ return '{} at {}'.format(
+ get_human_day(date, date_prefix='on'),
+ format_time(date),
+ )
+
+
def format_day_of_week(date):
return utc_string_to_aware_gmt_datetime(date).strftime('%A')
@@ -746,6 +760,7 @@ def add_template_filters(application):
format_date_human,
format_date_normal,
format_date_short,
+ format_datetime_human,
format_datetime_relative,
format_day_of_week,
format_delta,
diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html
index f2004a6ec..825adc81f 100644
--- a/app/templates/views/notifications/notification.html
+++ b/app/templates/views/notifications/notification.html
@@ -34,7 +34,7 @@
{% elif created_by %}
by {{ created_by.name }}
{% endif %}
- on {{ created_at|format_datetime_short }}
+ {{ created_at|format_datetime_human }}
{% if template.template_type == 'letter' %}
diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py
index 426aeade2..10fc2d4d2 100644
--- a/tests/app/main/views/test_notifications.py
+++ b/tests/app/main/views/test_notifications.py
@@ -152,22 +152,43 @@ def test_notification_status_shows_expected_back_link(
assert back_link is None
-@freeze_time("2012-01-01 01:01")
+@pytest.mark.parametrize('time_of_viewing_page, expected_message', (
+ ('2012-01-01 01:01', (
+ "‘sample template’ was sent by Test User today at 1:01am"
+ )),
+ ('2012-01-02 01:01', (
+ "‘sample template’ was sent by Test User yesterday at 1:01am"
+ )),
+ ('2012-01-03 01:01', (
+ "‘sample template’ was sent by Test User on 1 January at 1:01am"
+ )),
+ ('2013-01-03 01:01', (
+ "‘sample template’ was sent by Test User on 1 January 2012 at 1:01am"
+ )),
+))
def test_notification_page_doesnt_link_to_template_in_tour(
+ mocker,
client_request,
fake_uuid,
mock_get_notification,
+ time_of_viewing_page,
+ expected_message,
):
- page = client_request.get(
- 'main.view_notification',
- service_id=SERVICE_ONE_ID,
- notification_id=fake_uuid,
- help=3,
- )
+ with freeze_time('2012-01-01 01:01'):
+ notification = create_notification()
+ mocker.patch('app.notification_api_client.get_notification', return_value=notification)
+
+ with freeze_time(time_of_viewing_page):
+ page = client_request.get(
+ 'main.view_notification',
+ service_id=SERVICE_ONE_ID,
+ notification_id=fake_uuid,
+ help=3,
+ )
assert normalize_spaces(page.select('main p:nth-of-type(1)')[0].text) == (
- "‘sample template’ was sent by Test User on 1 January at 1:01am"
+ expected_message
)
assert len(page.select('main p:nth-of-type(1) a')) == 0
@@ -196,7 +217,7 @@ def test_notification_page_shows_page_for_letter_notification(
)
assert normalize_spaces(page.select('main p:nth-of-type(1)')[0].text) == (
- "‘sample template’ was sent by Test User on 1 January at 1:01am"
+ "‘sample template’ was sent by Test User today at 1:01am"
)
assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == (
'Printing starts today at 5:30pm'
@@ -230,13 +251,13 @@ def test_notification_page_shows_page_for_letter_notification(
@pytest.mark.parametrize('is_precompiled_letter, expected_p1, expected_p2, expected_postage', (
(
True,
- 'Provided as PDF on 1 January at 1:01am',
+ 'Provided as PDF today at 1:01am',
'This letter passed our checks, but we will not print it because you used a test key.',
'Postage: second class'
),
(
False,
- '‘sample template’ was sent on 1 January at 1:01am',
+ '‘sample template’ was sent today at 1:01am',
'We will not print this letter because you used a test key.',
'Postage: second class',
),
@@ -377,7 +398,7 @@ def test_notification_page_shows_cancelled_or_failed_letter(
)
assert normalize_spaces(page.select('main p')[0].text) == (
- "‘sample template’ was sent by Test User on 1 January at 1:01am"
+ "‘sample template’ was sent by Test User today at 1:01am"
)
assert normalize_spaces(page.select('main p')[1].text) == (
expected_message
From 46e16c64fc5732673a76432e32485ea3fa20a566 Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Wed, 19 Feb 2020 17:18:03 +0000
Subject: [PATCH 3/3] =?UTF-8?q?Say=20=E2=80=98Uploaded=E2=80=99=20for=20on?=
=?UTF-8?q?e-off=20precompiled=20letters?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This calls back to what the user has actively done. _Provided as a PDF_
is more passive and suitable for PDF letters sent using the API.
---
.../views/notifications/notification.html | 6 ++-
tests/app/main/views/test_notifications.py | 45 +++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html
index 825adc81f..8aa91cb08 100644
--- a/app/templates/views/notifications/notification.html
+++ b/app/templates/views/notifications/notification.html
@@ -17,7 +17,11 @@
) }}
{% if is_precompiled_letter %}
- Provided as PDF
+ {% if created_by %}
+ Uploaded
+ {% else %}
+ Provided as PDF
+ {% endif %}
{% else %}
{% if help %}
‘{{ template.name }}’
diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py
index 10fc2d4d2..590e61c89 100644
--- a/tests/app/main/views/test_notifications.py
+++ b/tests/app/main/views/test_notifications.py
@@ -247,6 +247,51 @@ def test_notification_page_shows_page_for_letter_notification(
assert mock_page_count.call_args_list[0][1]['values'] == {'name': 'Jo'}
+@freeze_time("2020-01-01 00:00")
+def test_notification_page_shows_uploaded_letter(
+ client_request,
+ mocker,
+ fake_uuid,
+):
+ mocker.patch(
+ 'app.main.views.notifications.view_letter_notification_as_preview',
+ return_value=(b'foo', {
+ 'message': '',
+ 'invalid_pages': '[]',
+ 'page_count': '1'
+ })
+ )
+ 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 = create_notification(
+ notification_status='created',
+ template_type='letter',
+ is_precompiled_letter=True,
+ sent_one_off=True,
+ )
+ mocker.patch('app.notification_api_client.get_notification', return_value=notification)
+
+ 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) == (
+ 'Uploaded by Test User yesterday at midnight'
+ )
+ assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == (
+ 'Printing starts today at 5:30pm'
+ )
+
+
@freeze_time("2016-01-01 01:01")
@pytest.mark.parametrize('is_precompiled_letter, expected_p1, expected_p2, expected_postage', (
(