From cffc697e7f5b0a55109dbe993f88e72ca922e4ab Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 28 Sep 2018 17:30:25 +0100 Subject: [PATCH] letter estimated delivery now takes postage into account --- app/models.py | 2 +- .../notifications/test_get_notifications.py | 28 +++++++------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/models.py b/app/models.py index 8702b0573..6c11689ab 100644 --- a/app/models.py +++ b/app/models.py @@ -1404,7 +1404,7 @@ class Notification(db.Model): serialized['line_6'] = col.get('address_line_6') serialized['postcode'] = col.get('postcode') serialized['estimated_delivery'] = \ - get_letter_timings(serialized['created_at'])\ + get_letter_timings(serialized['created_at'], postage=self.postage)\ .earliest_delivery\ .strftime(DATETIME_FORMAT) diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index 426e5e273..4db097ef3 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -238,21 +238,23 @@ def test_get_notification_by_id_invalid_id(client, sample_notification, id): "status_code": 400} -@pytest.mark.parametrize('created_at_month, estimated_delivery', [ - ( - 12, '2000-12-06T16:00:00.000000Z', # 4pm GMT in winter - ), - ( - 6, '2000-06-05T15:00:00.000000Z', # 4pm BST in summer - ), +@pytest.mark.parametrize('created_at_month, postage, estimated_delivery', [ + (12, 'second', '2000-12-06T16:00:00.000000Z'), # 4pm GMT in winter + (6, 'second', '2000-06-05T15:00:00.000000Z'), # 4pm BST in summer + + (12, 'first', '2000-12-05T16:00:00.000000Z'), # 4pm GMT in winter + (6, 'first', '2000-06-03T15:00:00.000000Z'), # 4pm BST in summer (two days before 2nd class due to weekends) ]) def test_get_notification_adds_delivery_estimate_for_letters( client, sample_letter_notification, created_at_month, + postage, estimated_delivery, ): sample_letter_notification.created_at = datetime.date(2000, created_at_month, 1) + sample_letter_notification.postage = postage + auth_header = create_authorization_header(service_id=sample_letter_notification.service_id) response = client.get( path='/v2/notifications/{}'.format(sample_letter_notification.id), @@ -261,20 +263,10 @@ def test_get_notification_adds_delivery_estimate_for_letters( json_response = json.loads(response.get_data(as_text=True)) assert response.status_code == 200 + assert json_response['postage'] == postage assert json_response['estimated_delivery'] == estimated_delivery -def test_get_notification_by_id_returns_postage_class_for_letters(client, sample_letter_notification): - auth_header = create_authorization_header(service_id=sample_letter_notification.service_id) - response = client.get( - path='/v2/notifications/{}'.format(sample_letter_notification.id), - headers=[('Content-Type', 'application/json'), auth_header] - ) - - assert response.status_code == 200 - assert response.json['postage'] == 'second' - - @pytest.mark.parametrize('template_type', ['sms', 'email']) def test_get_notification_doesnt_have_delivery_estimate_for_non_letters(client, sample_service, template_type): template = create_template(service=sample_service, template_type=template_type)