From fc8a9c184b61e2e77abc08fe54013cc1722c673d Mon Sep 17 00:00:00 2001 From: David McDonald Date: Fri, 6 Dec 2019 16:36:54 +0000 Subject: [PATCH] Bill `NOTIFICATION_PENDING` notifications SMS and emails may be marked as `NOTIFICATION_PENDING`. These will be billed as they will have been sent to the provider and will eventually turn to a final state such as `NOTIFICATION_DELIVERED` or `NOTIFICATION_PERMANENT_FAILURE`. This change will fix a discrepency on the billing page were the number of messages being billed was less than the number of messages reported as sent on a services dashboard when some of those messages were in a pending state. In reality, I don't think this bug would have had any longer affects for incorrect billing as messages would not stay in the pending state for too long and billing calculations would happen after that point. --- app/models.py | 1 + tests/app/dao/test_ft_billing_dao.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models.py b/app/models.py index 682e8bd83..296203d5b 100644 --- a/app/models.py +++ b/app/models.py @@ -1297,6 +1297,7 @@ NOTIFICATION_STATUS_TYPES_BILLABLE = [ NOTIFICATION_SENDING, NOTIFICATION_SENT, NOTIFICATION_DELIVERED, + NOTIFICATION_PENDING, NOTIFICATION_FAILED, NOTIFICATION_TEMPORARY_FAILURE, NOTIFICATION_PERMANENT_FAILURE, diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index 3b5554405..2216a96f7 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -59,19 +59,20 @@ def set_up_yearly_data(): def test_fetch_billing_data_for_today_includes_data_with_the_right_status(notify_db_session): + today = convert_utc_to_bst(datetime.utcnow()) service = create_service() template = create_template(service=service, template_type="email") + for status in ['created', 'technical-failure']: create_notification(template=template, status=status) - - today = convert_utc_to_bst(datetime.utcnow()) results = fetch_billing_data_for_day(today.date()) assert results == [] - for status in ['delivered', 'sending', 'temporary-failure']: + + for status in ['delivered', 'sending', 'temporary-failure', 'pending']: create_notification(template=template, status=status) results = fetch_billing_data_for_day(today.date()) assert len(results) == 1 - assert results[0].notifications_sent == 3 + assert results[0].notifications_sent == 4 def test_fetch_billing_data_for_today_includes_data_with_the_right_key_type(notify_db_session): @@ -299,8 +300,8 @@ def test_fetch_billing_data_for_day_bills_correctly_for_status(notify_db_session sms_results = [x for x in results if x[2] == 'sms'] email_results = [x for x in results if x[2] == 'email'] letter_results = [x for x in results if x[2] == 'letter'] - assert 7 == sms_results[0][7] - assert 7 == email_results[0][7] + assert 8 == sms_results[0][7] + assert 8 == email_results[0][7] assert 3 == letter_results[0][7]