From d828c1c4815db9b3c273b8235227f712748531c8 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 22 May 2020 10:43:12 +0100 Subject: [PATCH 1/4] Bump utils to 39.4.0 Adds delivery estimates for letters posted to Europe or the rest of the world. --- app/main/views/notifications.py | 13 +++++++++---- requirements-app.txt | 2 +- requirements.txt | 8 ++++---- tests/__init__.py | 3 +-- tests/app/main/views/test_notifications.py | 4 ++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index 07bbb9b35..2a533bc30 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -134,6 +134,14 @@ def view_notification(service_id, notification_id): status='sending,delivered,failed', ) + if notification['notification_type'] == 'letter': + estimated_letter_delivery_date = get_letter_timings( + notification['created_at'], + postage=notification['postage'] + ).earliest_delivery + else: + estimated_letter_delivery_date = None + return render_template( 'views/notifications/notification.html', finished=(notification['status'] in (DELIVERED_STATUSES + FAILURE_STATUSES)), @@ -154,10 +162,7 @@ def view_notification(service_id, notification_id): created_at=notification['created_at'], updated_at=notification['updated_at'], help=get_help_argument(), - estimated_letter_delivery_date=get_letter_timings( - notification['created_at'], - postage=notification['postage'] - ).earliest_delivery, + estimated_letter_delivery_date=estimated_letter_delivery_date, notification_id=notification['id'], postage=notification['postage'], can_receive_inbound=(current_service.has_permission('inbound_sms')), diff --git a/requirements-app.txt b/requirements-app.txt index 80a3f30f7..30c25d2d7 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -23,5 +23,5 @@ notifications-python-client==5.5.1 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 -git+https://github.com/alphagov/notifications-utils.git@39.3.0#egg=notifications-utils==39.3.0 +git+https://github.com/alphagov/notifications-utils.git@39.4.0#egg=notifications-utils==39.4.0 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha diff --git a/requirements.txt b/requirements.txt index f5d52fee8..836a10979 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,14 +25,14 @@ notifications-python-client==5.5.1 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 -git+https://github.com/alphagov/notifications-utils.git@39.3.0#egg=notifications-utils==39.3.0 +git+https://github.com/alphagov/notifications-utils.git@39.4.0#egg=notifications-utils==39.4.0 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha ## The following requirements were added by pip freeze: -awscli==1.18.63 +awscli==1.18.66 bleach==3.1.4 boto3==1.10.38 -botocore==1.16.13 +botocore==1.16.16 certifi==2020.4.5.1 chardet==3.0.4 click==7.1.2 @@ -67,7 +67,7 @@ redis==3.5.2 requests==2.23.0 rsa==3.4.2 s3transfer==0.3.3 -six==1.14.0 +six==1.15.0 smartypants==2.0.1 statsd==3.3.0 texttable==1.6.2 diff --git a/tests/__init__.py b/tests/__init__.py index f1a8d6626..dba3573c1 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -443,8 +443,7 @@ def notification_json( if status is None: status = 'delivered' links = {} - if template_type == 'letter': - postage = postage or 'second' + postage = postage or 'second' if with_links: links = { diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index f4b70e642..625048c9c 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -530,13 +530,13 @@ def test_notification_page_does_not_show_cancel_link_for_letter_which_cannot_be_ 'europe', 'Postage: international', 'letter-postage-international', - 'Estimated delivery date: Wednesday 6 January', + 'Estimated delivery date: Friday 8 January', ), ( 'rest-of-world', 'Postage: international', 'letter-postage-international', - 'Estimated delivery date: Wednesday 6 January', + 'Estimated delivery date: Monday 11 January', ), )) @freeze_time("2016-01-01 18:00") From e0de65cd81a166e01e2a63ded676ce6d0858f6d2 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 26 May 2020 13:25:40 +0100 Subject: [PATCH 2/4] Call mock rather than using fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our get_notifications fixture tries to be too clever and work out which fields to return based on what arguments it’s called with. This is very indirect and makes the tests less specific. In other places we call the mocking code directly with arguments that make it more explicit what the mocked response should be. This commit does this for tests that we’d otherwise have to make changes to the fixture for, because postage can no longer be `None` for letter notifications. --- tests/__init__.py | 3 ++- tests/app/main/views/test_jobs.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index dba3573c1..f1a8d6626 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -443,7 +443,8 @@ def notification_json( if status is None: status = 'delivered' links = {} - postage = postage or 'second' + if template_type == 'letter': + postage = postage or 'second' if with_links: links = { diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 8a81153b4..996d77dcc 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -349,13 +349,17 @@ def test_should_show_letter_job( @freeze_time("2016-01-01 11:09:00") def test_should_show_letter_job_with_banner_after_sending_before_1730( + mocker, client_request, mock_get_service_letter_template, mock_get_letter_job, - mock_get_notifications, mock_get_service_data_retention, fake_uuid, ): + mocker.patch( + 'app.notification_api_client.get_notifications_for_service', + return_value=create_notifications(template_type='letter', postage='second') + ) page = client_request.get( 'main.view_job', @@ -373,13 +377,17 @@ def test_should_show_letter_job_with_banner_after_sending_before_1730( @freeze_time("2016-01-01 11:09:00") def test_should_show_letter_job_with_banner_when_there_are_multiple_CSV_rows( + mocker, client_request, mock_get_service_letter_template, mock_get_letter_job_in_progress, - mock_get_notifications, mock_get_service_data_retention, fake_uuid, ): + mocker.patch( + 'app.notification_api_client.get_notifications_for_service', + return_value=create_notifications(template_type='letter', postage='second') + ) page = client_request.get( 'main.view_job', @@ -396,13 +404,17 @@ def test_should_show_letter_job_with_banner_when_there_are_multiple_CSV_rows( @freeze_time("2016-01-01 18:09:00") def test_should_show_letter_job_with_banner_after_sending_after_1730( + mocker, client_request, mock_get_service_letter_template, mock_get_letter_job, - mock_get_notifications, mock_get_service_data_retention, fake_uuid, ): + mocker.patch( + 'app.notification_api_client.get_notifications_for_service', + return_value=create_notifications(template_type='letter', postage='second') + ) page = client_request.get( 'main.view_job', From 9da843ceffbf6bf1d20686db3a624d1d03d3d144 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 26 May 2020 13:28:55 +0100 Subject: [PATCH 3/4] Bump utils to 39.4.1 --- requirements-app.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-app.txt b/requirements-app.txt index 30c25d2d7..b268c62e0 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -23,5 +23,5 @@ notifications-python-client==5.5.1 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 -git+https://github.com/alphagov/notifications-utils.git@39.4.0#egg=notifications-utils==39.4.0 +git+https://github.com/alphagov/notifications-utils.git@39.4.1#egg=notifications-utils==39.4.1 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha diff --git a/requirements.txt b/requirements.txt index 836a10979..070b2ed8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,7 @@ notifications-python-client==5.5.1 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 -git+https://github.com/alphagov/notifications-utils.git@39.4.0#egg=notifications-utils==39.4.0 +git+https://github.com/alphagov/notifications-utils.git@39.4.1#egg=notifications-utils==39.4.1 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha ## The following requirements were added by pip freeze: From 67be9d98c94c3cdbd58cc43e1c683b85fd513102 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 27 May 2020 15:23:38 +0100 Subject: [PATCH 4/4] Bump utils to 39.4.2 --- requirements-app.txt | 2 +- requirements.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements-app.txt b/requirements-app.txt index b268c62e0..e70659ff1 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -23,5 +23,5 @@ notifications-python-client==5.5.1 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 -git+https://github.com/alphagov/notifications-utils.git@39.4.1#egg=notifications-utils==39.4.1 +git+https://github.com/alphagov/notifications-utils.git@39.4.2#egg=notifications-utils==39.4.2 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha diff --git a/requirements.txt b/requirements.txt index 070b2ed8d..196fce3b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,14 +25,14 @@ notifications-python-client==5.5.1 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 -git+https://github.com/alphagov/notifications-utils.git@39.4.1#egg=notifications-utils==39.4.1 +git+https://github.com/alphagov/notifications-utils.git@39.4.2#egg=notifications-utils==39.4.2 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha ## The following requirements were added by pip freeze: -awscli==1.18.66 +awscli==1.18.67 bleach==3.1.4 boto3==1.10.38 -botocore==1.16.16 +botocore==1.16.17 certifi==2020.4.5.1 chardet==3.0.4 click==7.1.2