From 46cbac62efd122c5e3afccb516810c31810fd415 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Wed, 27 Apr 2022 15:07:49 +0100 Subject: [PATCH] Fix misleading billable_units in letter test data Letters are weird: - "rate" is adjusted based on the number of pages [^1]. - "billable_units" is the number of sheets [^2], but doesn't seem to be used for anything. Instead of "billable_units", we multiply "notifications_sent" and the page-adjusted "rate" to determine the cost of a batch [^3][^4]. [^1]: https://github.com/alphagov/notifications-api/blob/a4fe11a3aaa75d72cf3f0d5b1e8283fbb6622171/app/dao/fact_billing_dao.py#L473 [^2]: https://github.com/alphagov/notifications-api/blob/a4fe11a3aaa75d72cf3f0d5b1e8283fbb6622171/app/letters/utils.py#L230 [^3]: https://github.com/alphagov/notifications-api/blob/a4fe11a3aaa75d72cf3f0d5b1e8283fbb6622171/app/dao/fact_billing_dao.py#L828 [^4]: https://github.com/alphagov/notifications-api/blob/a4fe11a3aaa75d72cf3f0d5b1e8283fbb6622171/app/dao/fact_billing_dao.py#L128 --- tests/app/dao/test_ft_billing_dao.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index 5a162a1d3..5976da676 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -76,7 +76,16 @@ def set_up_yearly_data_variable_rates(): create_ft_billing(bst_date='2018-05-17', template=sms_template, rate_multiplier=2, rate=0.162, billable_unit=2) create_ft_billing(bst_date='2018-05-16', template=sms_template, rate_multiplier=2, rate=0.0150, billable_unit=2) create_ft_billing(bst_date='2018-05-16', template=letter_template, rate=0.33, postage='second') - create_ft_billing(bst_date='2018-05-17', template=letter_template, rate=0.36, billable_unit=2, postage='second') + + create_ft_billing( + bst_date='2018-05-17', + template=letter_template, + rate=0.36, + notifications_sent=2, + billable_unit=4, # 2 pages each + postage='second' + ) + return service @@ -464,8 +473,8 @@ def test_fetch_monthly_billing_for_year_variable_rates(notify_db_session): assert str(results[1].month) == "2018-05-01" assert results[1].notification_type == 'letter' - assert results[1].notifications_sent == 1 - assert results[1].billable_units == 1 + assert results[1].notifications_sent == 2 + assert results[1].billable_units == 2 assert results[1].rate == Decimal('0.36') assert str(results[2].month) == "2018-05-01" @@ -537,8 +546,8 @@ def test_fetch_billing_totals_for_year_variable_rates(notify_db_session): assert results[0].rate == Decimal('0.33') assert results[1].notification_type == 'letter' - assert results[1].notifications_sent == 1 - assert results[1].billable_units == 1 + assert results[1].notifications_sent == 2 + assert results[1].billable_units == 2 assert results[1].rate == Decimal('0.36') assert results[2].notification_type == 'sms'