From cfda2897467d96d9e75616b6e9f99d29671e1e23 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 9 Sep 2020 10:55:55 +0100 Subject: [PATCH] Allow international letters to be cancelled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our code was assuming that any notifications with `international` set to `True` were text messages. It was then trying to look up delivery information for a notification which wasn’t sent to a phone number, causing an exception. --- app/dao/notifications_dao.py | 6 +++++- .../app/dao/notification_dao/test_notification_dao.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 078fa9b6b..ae9c6e239 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -140,7 +140,11 @@ def update_notification_status_by_id(notification_id, status, sent_by=None, deta _duplicate_update_warning(notification, status) return None - if notification.international and not country_records_delivery(notification.phone_prefix): + if ( + notification.notification_type == 'sms' + and notification.international + and not country_records_delivery(notification.phone_prefix) + ): return None if not notification.sent_by and sent_by: notification.sent_by = sent_by diff --git a/tests/app/dao/notification_dao/test_notification_dao.py b/tests/app/dao/notification_dao/test_notification_dao.py index af51104ca..5628ae527 100644 --- a/tests/app/dao/notification_dao/test_notification_dao.py +++ b/tests/app/dao/notification_dao/test_notification_dao.py @@ -122,6 +122,17 @@ def test_should_update_status_by_id_if_pending_virus_check(sample_letter_templat assert updated.status == 'cancelled' +def test_should_update_status_of_international_letter_to_cancelled(sample_letter_template): + notification = create_notification( + template=sample_letter_template, + international=True, + postage='europe', + ) + assert Notification.query.get(notification.id).international is True + update_notification_status_by_id(notification.id, 'cancelled') + assert Notification.query.get(notification.id).status == 'cancelled' + + def test_should_update_status_by_id_and_set_sent_by(sample_template): notification = create_notification(template=sample_template, status='sending')