From c3bc1d0df9e3263cad0bf6ee1de05238ccf8050b Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Fri, 29 Apr 2022 10:20:54 +0100 Subject: [PATCH 1/7] Remove redundant test data for usage DAOs This is unnecessary since we now have separate "_variable_rates" tests that check the behaviour for multiple rates explicitly for the two types of notifications it affects. --- tests/app/dao/test_ft_billing_dao.py | 51 ++++++++-------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index 96b699c95..58b17b944 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -50,7 +50,6 @@ def set_up_yearly_data(): for dt in (date(2016, 3, 31), date(2017, 4, 1)): create_ft_billing(bst_date=dt, template=sms_template, rate=0.163) create_ft_billing(bst_date=dt, template=email_template, rate=0, billable_unit=0) - create_ft_billing(bst_date=dt, template=letter_template, rate=0.34, postage='second') create_ft_billing(bst_date=dt, template=letter_template, rate=0.31, postage='second') start_date = date(2016, 4, 1) @@ -61,7 +60,6 @@ def set_up_yearly_data(): create_ft_billing(bst_date=dt, template=sms_template, rate=0.162) create_ft_billing(bst_date=dt, template=email_template, rate=0, billable_unit=0) - create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second') create_ft_billing(bst_date=dt, template=letter_template, rate=0.30, postage='second') return service @@ -429,7 +427,7 @@ def test_fetch_monthly_billing_for_year(notify_db_session): create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2016) results = fetch_monthly_billing_for_year(service.id, 2016) - assert len(results) == 48 + assert len(results) == 36 assert str(results[0].month) == "2016-04-01" assert results[0].notification_type == 'email' @@ -451,29 +449,19 @@ def test_fetch_monthly_billing_for_year(notify_db_session): assert results[1].free_allowance_used == 0 assert results[1].charged_units == 30 - assert str(results[1].month) == "2016-04-01" - assert results[2].notification_type == 'letter' + assert str(results[2].month) == "2016-04-01" + assert results[2].notification_type == 'sms' assert results[2].notifications_sent == 30 assert results[2].billable_units == 30 assert results[2].chargeable_units == 30 - assert results[2].rate == Decimal('0.33') - assert results[2].cost == Decimal('9.9') - assert results[2].free_allowance_used == 0 - assert results[2].charged_units == 30 - - assert str(results[3].month) == "2016-04-01" - assert results[3].notification_type == 'sms' - assert results[3].notifications_sent == 30 - assert results[3].billable_units == 30 - assert results[3].chargeable_units == 30 - assert results[3].rate == Decimal('0.162') + assert results[2].rate == Decimal('0.162') # free allowance is 10, so (30 - 10) * 0.162 - assert results[3].cost == Decimal('3.24') - assert results[3].free_allowance_used == 10 - assert results[3].charged_units == 20 + assert results[2].cost == Decimal('3.24') + assert results[2].free_allowance_used == 10 + assert results[2].charged_units == 20 - assert str(results[4].month) == "2016-05-01" - assert str(results[47].month) == "2017-03-01" + assert str(results[3].month) == "2016-05-01" + assert str(results[35].month) == "2017-03-01" def test_fetch_monthly_billing_for_year_variable_rates(notify_db_session): @@ -552,7 +540,7 @@ def test_fetch_billing_totals_for_year(notify_db_session): create_annual_billing(service_id=service.id, free_sms_fragment_limit=1000, financial_year_start=2016) results = fetch_billing_totals_for_year(service_id=service.id, year=2016) - assert len(results) == 4 + assert len(results) == 3 assert results[0].notification_type == 'email' assert results[0].notifications_sent == 365 assert results[0].billable_units == 365 @@ -571,23 +559,14 @@ def test_fetch_billing_totals_for_year(notify_db_session): assert results[1].free_allowance_used == 0 assert results[1].charged_units == 365 - assert results[2].notification_type == 'letter' + assert results[2].notification_type == 'sms' assert results[2].notifications_sent == 365 assert results[2].billable_units == 365 assert results[2].chargeable_units == 365 - assert results[2].rate == Decimal('0.33') - assert results[2].cost == Decimal('120.45') - assert results[2].free_allowance_used == 0 - assert results[2].charged_units == 365 - - assert results[3].notification_type == 'sms' - assert results[3].notifications_sent == 365 - assert results[3].billable_units == 365 - assert results[3].chargeable_units == 365 - assert results[3].rate == Decimal('0.162') - assert results[3].cost == Decimal('0') - assert results[3].free_allowance_used == 365 - assert results[3].charged_units == 0 + assert results[2].rate == Decimal('0.162') + assert results[2].cost == Decimal('0') + assert results[2].free_allowance_used == 365 + assert results[2].charged_units == 0 def test_fetch_billing_totals_for_year_uses_current_annual_billing(notify_db_session): From 1fab73ef9ee9c2a83d9ff2e9a18b675b2d50c067 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Fri, 29 Apr 2022 10:30:45 +0100 Subject: [PATCH 2/7] Speed up usage DAO tests with minimal test data This slowed me down when making changes to the DAO functions. It's really not necessary to do 3 * 367 DB insertions for both tests. Before: time pytest tests/app/dao/test_ft_billing_dao.py -k for_year ... pytest tests/app/dao/test_ft_billing_dao.py -k for_year 3.95s user 0.40s system 62% cpu 6.971 total After: time pytest tests/app/dao/test_ft_billing_dao.py -k for_year ... pytest tests/app/dao/test_ft_billing_dao.py -k for_year 1.84s user 0.25s system 69% cpu 3.006 total --- tests/app/dao/test_ft_billing_dao.py | 69 +++++++++++++--------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index 58b17b944..d3d1f760a 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -52,12 +52,9 @@ def set_up_yearly_data(): create_ft_billing(bst_date=dt, template=email_template, rate=0, billable_unit=0) create_ft_billing(bst_date=dt, template=letter_template, rate=0.31, postage='second') - start_date = date(2016, 4, 1) - end_date = date(2017, 4, 1) - - for n in range((end_date - start_date).days): - dt = start_date + timedelta(days=n) - + # a selection of dates that represent the extreme ends of the financial year + # and some arbitrary dates in between + for dt in (date(2016, 4, 1), date(2016, 4, 29), date(2017, 2, 6), date(2017, 3, 31)): create_ft_billing(bst_date=dt, template=sms_template, rate=0.162) create_ft_billing(bst_date=dt, template=email_template, rate=0, billable_unit=0) create_ft_billing(bst_date=dt, template=letter_template, rate=0.30, postage='second') @@ -424,15 +421,15 @@ def test_get_rate_for_letters_when_page_count_is_zero(notify_db_session): def test_fetch_monthly_billing_for_year(notify_db_session): service = set_up_yearly_data() - create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2016) + create_annual_billing(service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016) results = fetch_monthly_billing_for_year(service.id, 2016) - assert len(results) == 36 + assert len(results) == 9 # 3 billed months for each type assert str(results[0].month) == "2016-04-01" assert results[0].notification_type == 'email' - assert results[0].notifications_sent == 30 - assert results[0].billable_units == 30 + assert results[0].notifications_sent == 2 + assert results[0].billable_units == 2 assert results[0].chargeable_units == 0 assert results[0].rate == Decimal('0') assert results[0].cost == Decimal('0') @@ -441,27 +438,27 @@ def test_fetch_monthly_billing_for_year(notify_db_session): assert str(results[1].month) == "2016-04-01" assert results[1].notification_type == 'letter' - assert results[1].notifications_sent == 30 - assert results[1].billable_units == 30 - assert results[1].chargeable_units == 30 + assert results[1].notifications_sent == 2 + assert results[1].billable_units == 2 + assert results[1].chargeable_units == 2 assert results[1].rate == Decimal('0.30') - assert results[1].cost == Decimal('9') + assert results[1].cost == Decimal('0.60') assert results[1].free_allowance_used == 0 - assert results[1].charged_units == 30 + assert results[1].charged_units == 2 assert str(results[2].month) == "2016-04-01" assert results[2].notification_type == 'sms' - assert results[2].notifications_sent == 30 - assert results[2].billable_units == 30 - assert results[2].chargeable_units == 30 + assert results[2].notifications_sent == 2 + assert results[2].billable_units == 2 + assert results[2].chargeable_units == 2 assert results[2].rate == Decimal('0.162') - # free allowance is 10, so (30 - 10) * 0.162 - assert results[2].cost == Decimal('3.24') - assert results[2].free_allowance_used == 10 - assert results[2].charged_units == 20 + # free allowance is 1 + assert results[2].cost == Decimal('0.162') + assert results[2].free_allowance_used == 1 + assert results[2].charged_units == 1 - assert str(results[3].month) == "2016-05-01" - assert str(results[35].month) == "2017-03-01" + assert str(results[3].month) == "2017-02-01" + assert str(results[8].month) == "2017-03-01" def test_fetch_monthly_billing_for_year_variable_rates(notify_db_session): @@ -542,8 +539,8 @@ def test_fetch_billing_totals_for_year(notify_db_session): assert len(results) == 3 assert results[0].notification_type == 'email' - assert results[0].notifications_sent == 365 - assert results[0].billable_units == 365 + assert results[0].notifications_sent == 4 + assert results[0].billable_units == 4 assert results[0].chargeable_units == 0 assert results[0].rate == Decimal('0') assert results[0].cost == Decimal('0') @@ -551,21 +548,21 @@ def test_fetch_billing_totals_for_year(notify_db_session): assert results[0].charged_units == 0 assert results[1].notification_type == 'letter' - assert results[1].notifications_sent == 365 - assert results[1].billable_units == 365 - assert results[1].chargeable_units == 365 + assert results[1].notifications_sent == 4 + assert results[1].billable_units == 4 + assert results[1].chargeable_units == 4 assert results[1].rate == Decimal('0.3') - assert results[1].cost == Decimal('109.5') + assert results[1].cost == Decimal('1.2') assert results[1].free_allowance_used == 0 - assert results[1].charged_units == 365 + assert results[1].charged_units == 4 assert results[2].notification_type == 'sms' - assert results[2].notifications_sent == 365 - assert results[2].billable_units == 365 - assert results[2].chargeable_units == 365 + assert results[2].notifications_sent == 4 + assert results[2].billable_units == 4 + assert results[2].chargeable_units == 4 assert results[2].rate == Decimal('0.162') assert results[2].cost == Decimal('0') - assert results[2].free_allowance_used == 365 + assert results[2].free_allowance_used == 4 assert results[2].charged_units == 0 @@ -580,7 +577,7 @@ def test_fetch_billing_totals_for_year_uses_current_annual_billing(notify_db_ses if result.notification_type == 'sms' ) - assert result.chargeable_units == 365 + assert result.chargeable_units == 4 assert result.cost > 0 From f978a4fe457ce58535b020a333a990c1faf1263d Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Fri, 29 Apr 2022 10:37:19 +0100 Subject: [PATCH 3/7] Remove redundant test data for annual usage API This test should be focussed on the structural properties of the API. We can leave more detailed testing of rate multipliers, etc. to lower-level DAO tests. --- tests/app/billing/test_rest.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/app/billing/test_rest.py b/tests/app/billing/test_rest.py index e0d979066..58ced0238 100644 --- a/tests/app/billing/test_rest.py +++ b/tests/app/billing/test_rest.py @@ -206,10 +206,6 @@ def set_up_yearly_data(): create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), template=sms_template, rate=0.0162) - create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), - template=sms_template, - rate_multiplier=2, - rate=0.0162) create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), template=email_template, billable_unit=0, @@ -278,11 +274,11 @@ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_ assert json_response[1]['charged_units'] == 275 assert json_response[2]['notification_type'] == 'sms' - assert json_response[2]['billing_units'] == 825 - assert json_response[2]['chargeable_units'] == 825 - assert json_response[2]['notifications_sent'] == 550 + assert json_response[2]['billing_units'] == 275 + assert json_response[2]['chargeable_units'] == 275 + assert json_response[2]['notifications_sent'] == 275 assert json_response[2]['rate'] == 0.0162 assert json_response[2]['letter_total'] == 0 - assert json_response[2]['cost'] == 13.3002 + assert json_response[2]['cost'] == 4.3902 assert json_response[2]['free_allowance_used'] == 4 - assert json_response[2]['charged_units'] == 821 + assert json_response[2]['charged_units'] == 271 From 2fdec58496e69d9cfc0e6659234494c3154d7065 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Fri, 29 Apr 2022 10:40:16 +0100 Subject: [PATCH 4/7] Remove unused line in annual usage API test data --- tests/app/billing/test_rest.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/app/billing/test_rest.py b/tests/app/billing/test_rest.py index 58ced0238..6598c2899 100644 --- a/tests/app/billing/test_rest.py +++ b/tests/app/billing/test_rest.py @@ -6,10 +6,7 @@ from freezegun import freeze_time from app.billing.rest import update_free_sms_fragment_limit_data from app.dao.annual_billing_dao import dao_get_free_sms_fragment_limit_for_year -from app.dao.date_util import ( - get_current_financial_year_start_year, - get_month_start_and_end_date_in_utc, -) +from app.dao.date_util import get_current_financial_year_start_year from tests.app.db import ( create_annual_billing, create_ft_billing, @@ -214,7 +211,6 @@ def set_up_yearly_data(): template=letter_template, rate=0.33, postage='second') - start_date, end_date = get_month_start_and_end_date_in_utc(datetime(2016, int(mon), 1)) create_annual_billing(service_id=service.id, free_sms_fragment_limit=4, financial_year_start=2016) return service From efae436c4a173c9ac60c56001a9921e5bb823a31 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Fri, 29 Apr 2022 10:51:08 +0100 Subject: [PATCH 5/7] Speed up usage API tests with minimal test data This slowed me down when making changes to the APIs. As well as being unnecessary given the structural focus of these tests, I found the way the test data was generated was quite confusing. Before: time pytest tests/app/billing/test_rest.py ... pytest tests/app/billing/test_rest.py 4.16s user 0.43s system 55% cpu 8.355 total After: time pytest tests/app/billing/test_rest.py ... pytest tests/app/billing/test_rest.py 2.16s user 0.25s system 70% cpu 3.413 total --- tests/app/billing/test_rest.py | 102 +++++++++++++-------------------- 1 file changed, 39 insertions(+), 63 deletions(-) diff --git a/tests/app/billing/test_rest.py b/tests/app/billing/test_rest.py index 6598c2899..a4d571a0b 100644 --- a/tests/app/billing/test_rest.py +++ b/tests/app/billing/test_rest.py @@ -1,5 +1,4 @@ -from calendar import monthrange -from datetime import datetime +from datetime import date, datetime import pytest from freezegun import freeze_time @@ -128,24 +127,12 @@ def set_up_monthly_data(): email_template = create_template(service=service, template_type="email") letter_template = create_template(service=service, template_type="letter") - for month in range(1, 13): - mon = str(month).zfill(2) - for day in range(1, monthrange(2016, month)[1] + 1): - d = str(day).zfill(2) - create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), - template=sms_template, - billable_unit=1, - rate=0.162) - create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), - template=email_template, - rate=0) - create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), - template=letter_template, - billable_unit=1, - rate=0.33, - postage='second') + for dt in (date(2016, 4, 28), date(2016, 11, 10), date(2017, 2, 26)): + create_ft_billing(bst_date=dt, template=sms_template, rate=0.0162) + create_ft_billing(bst_date=dt, template=email_template, billable_unit=0, rate=0) + create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second') - create_annual_billing(service_id=service.id, free_sms_fragment_limit=4, financial_year_start=2016) + create_annual_billing(service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016) return service @@ -158,7 +145,7 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se year=2016 ) - assert len(json_response) == 18 + assert len(json_response) == 6 # 3 billed months for SMS and letters email_rows = [row for row in json_response if row['notification_type'] == 'email'] assert len(email_rows) == 0 @@ -168,26 +155,26 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se assert letter_row["month"] == "April" assert letter_row["notification_type"] == "letter" - assert letter_row["billing_units"] == 30 - assert letter_row["chargeable_units"] == 30 - assert letter_row["notifications_sent"] == 30 + assert letter_row["billing_units"] == 1 + assert letter_row["chargeable_units"] == 1 + assert letter_row["notifications_sent"] == 1 assert letter_row["rate"] == 0.33 assert letter_row["postage"] == "second" - assert letter_row["cost"] == 9.9 + assert letter_row["cost"] == 0.33 assert letter_row["free_allowance_used"] == 0 - assert letter_row["charged_units"] == 30 + assert letter_row["charged_units"] == 1 assert sms_row["month"] == "April" assert sms_row["notification_type"] == "sms" - assert sms_row["billing_units"] == 30 - assert sms_row["chargeable_units"] == 30 - assert sms_row["notifications_sent"] == 30 - assert sms_row["rate"] == 0.162 + assert sms_row["billing_units"] == 1 + assert sms_row["chargeable_units"] == 1 + assert sms_row["notifications_sent"] == 1 + assert sms_row["rate"] == 0.0162 assert sms_row["postage"] == "none" - # free allowance is 4, so (30 - 4) * 0.162 - assert sms_row["cost"] == 4.212 - assert sms_row["free_allowance_used"] == 4 - assert sms_row["charged_units"] == 26 + # free allowance is 1 + assert sms_row["cost"] == 0 + assert sms_row["free_allowance_used"] == 1 + assert sms_row["charged_units"] == 0 def set_up_yearly_data(): @@ -196,23 +183,12 @@ def set_up_yearly_data(): email_template = create_template(service=service, template_type="email") letter_template = create_template(service=service, template_type="letter") - for month in range(1, 13): - mon = str(month).zfill(2) - for day in range(1, monthrange(2016, month)[1] + 1): - d = str(day).zfill(2) - create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), - template=sms_template, - rate=0.0162) - create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), - template=email_template, - billable_unit=0, - rate=0) - create_ft_billing(bst_date='2016-{}-{}'.format(mon, d), - template=letter_template, - rate=0.33, - postage='second') + for dt in (date(2016, 4, 28), date(2016, 11, 10), date(2017, 2, 26)): + create_ft_billing(bst_date=dt, template=sms_template, rate=0.0162) + create_ft_billing(bst_date=dt, template=email_template, billable_unit=0, rate=0) + create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second') - create_annual_billing(service_id=service.id, free_sms_fragment_limit=4, financial_year_start=2016) + create_annual_billing(service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016) return service @@ -250,9 +226,9 @@ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_ assert len(json_response) == 3 assert json_response[0]['notification_type'] == 'email' - assert json_response[0]['billing_units'] == 275 + assert json_response[0]['billing_units'] == 3 assert json_response[0]['chargeable_units'] == 0 - assert json_response[0]['notifications_sent'] == 275 + assert json_response[0]['notifications_sent'] == 3 assert json_response[0]['rate'] == 0 assert json_response[0]['letter_total'] == 0 assert json_response[0]['cost'] == 0 @@ -260,21 +236,21 @@ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_ assert json_response[0]['charged_units'] == 0 assert json_response[1]['notification_type'] == 'letter' - assert json_response[1]['billing_units'] == 275 - assert json_response[1]['chargeable_units'] == 275 - assert json_response[1]['notifications_sent'] == 275 + assert json_response[1]['billing_units'] == 3 + assert json_response[1]['chargeable_units'] == 3 + assert json_response[1]['notifications_sent'] == 3 assert json_response[1]['rate'] == 0.33 - assert json_response[1]['letter_total'] == 90.75 - assert json_response[1]['cost'] == 90.75 + assert json_response[1]['letter_total'] == 0.99 + assert json_response[1]['cost'] == 0.99 assert json_response[1]['free_allowance_used'] == 0 - assert json_response[1]['charged_units'] == 275 + assert json_response[1]['charged_units'] == 3 assert json_response[2]['notification_type'] == 'sms' - assert json_response[2]['billing_units'] == 275 - assert json_response[2]['chargeable_units'] == 275 - assert json_response[2]['notifications_sent'] == 275 + assert json_response[2]['billing_units'] == 3 + assert json_response[2]['chargeable_units'] == 3 + assert json_response[2]['notifications_sent'] == 3 assert json_response[2]['rate'] == 0.0162 assert json_response[2]['letter_total'] == 0 - assert json_response[2]['cost'] == 4.3902 - assert json_response[2]['free_allowance_used'] == 4 - assert json_response[2]['charged_units'] == 271 + assert json_response[2]['cost'] == 0.0324 + assert json_response[2]['free_allowance_used'] == 1 + assert json_response[2]['charged_units'] == 2 From b8cd99d9faaadb5af6df0f7425d33226675a0cf2 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Fri, 29 Apr 2022 10:58:41 +0100 Subject: [PATCH 6/7] Move usage API test data inline with tests This makes it easier to compare assertions against the test data, especially since each function was only used in one test. --- tests/app/billing/test_rest.py | 38 +++++++++++++--------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/app/billing/test_rest.py b/tests/app/billing/test_rest.py index a4d571a0b..48ae02a46 100644 --- a/tests/app/billing/test_rest.py +++ b/tests/app/billing/test_rest.py @@ -121,8 +121,10 @@ def test_update_free_sms_fragment_limit_data(client, sample_service): assert annual_billing.free_sms_fragment_limit == 9999 -def set_up_monthly_data(): +def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_session): service = create_service() + create_annual_billing(service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016) + sms_template = create_template(service=service, template_type="sms") email_template = create_template(service=service, template_type="email") letter_template = create_template(service=service, template_type="letter") @@ -132,13 +134,6 @@ def set_up_monthly_data(): create_ft_billing(bst_date=dt, template=email_template, billable_unit=0, rate=0) create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second') - create_annual_billing(service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016) - return service - - -def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_session): - service = set_up_monthly_data() - json_response = admin_request.get( 'billing.get_yearly_usage_by_monthly_from_ft_billing', service_id=service.id, @@ -177,21 +172,6 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se assert sms_row["charged_units"] == 0 -def set_up_yearly_data(): - service = create_service() - sms_template = create_template(service=service, template_type="sms") - email_template = create_template(service=service, template_type="email") - letter_template = create_template(service=service, template_type="letter") - - for dt in (date(2016, 4, 28), date(2016, 11, 10), date(2017, 2, 26)): - create_ft_billing(bst_date=dt, template=sms_template, rate=0.0162) - create_ft_billing(bst_date=dt, template=email_template, billable_unit=0, rate=0) - create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second') - - create_annual_billing(service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016) - return service - - def test_get_yearly_billing_usage_summary_from_ft_billing_returns_400_if_missing_year(admin_request, sample_service): json_response = admin_request.get( 'billing.get_yearly_billing_usage_summary_from_ft_billing', @@ -215,7 +195,17 @@ def test_get_yearly_billing_usage_summary_from_ft_billing_returns_empty_list_if_ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_db_session): - service = set_up_yearly_data() + service = create_service() + create_annual_billing(service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016) + + sms_template = create_template(service=service, template_type="sms") + email_template = create_template(service=service, template_type="email") + letter_template = create_template(service=service, template_type="letter") + + for dt in (date(2016, 4, 28), date(2016, 11, 10), date(2017, 2, 26)): + create_ft_billing(bst_date=dt, template=sms_template, rate=0.0162) + create_ft_billing(bst_date=dt, template=email_template, billable_unit=0, rate=0) + create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second') json_response = admin_request.get( 'billing.get_yearly_billing_usage_summary_from_ft_billing', From 52b2982b92e4f67cdd713efc9d7a1c3d4dc09b2a Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Fri, 29 Apr 2022 11:01:27 +0100 Subject: [PATCH 7/7] Rename test_ft_billing... to match file under test This tripped me up several times when modifying the DAO functions and then trying to search for the test file associated with them. --- .../app/dao/{test_ft_billing_dao.py => test_fact_billing_dao.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/app/dao/{test_ft_billing_dao.py => test_fact_billing_dao.py} (100%) diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_fact_billing_dao.py similarity index 100% rename from tests/app/dao/test_ft_billing_dao.py rename to tests/app/dao/test_fact_billing_dao.py