From 75e0d53e766df2a1c28665fb295a956a4947c56e Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Tue, 3 May 2022 15:24:13 +0100 Subject: [PATCH] Simplify test for only showing historic months This goal wasn't clear from the original test, which was checking the entire return value, even though this is covered implicitly by tests of the usage page itself. --- tests/app/main/views/test_dashboard.py | 193 +++---------------------- 1 file changed, 21 insertions(+), 172 deletions(-) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 9d28284ae..c2910157c 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -12,7 +12,6 @@ from app.main.views.dashboard import ( aggregate_template_usage, format_monthly_stats_to_list, get_dashboard_totals, - get_monthly_usage_breakdown, get_tuples_of_financial_years, ) from tests import ( @@ -1093,6 +1092,27 @@ def test_usage_page_monthly_breakdown( assert '1,230 text messages at 1.70p' in monthly_breakdown +@pytest.mark.parametrize( + 'now, expected_number_of_months', [ + (freeze_time("2017-03-31 11:09:00.061258"), 12), + (freeze_time("2017-01-01 11:09:00.061258"), 10) + ] +) +def test_usage_page_monthly_breakdown_shows_months_so_far( + client_request, + service_one, + mock_get_annual_usage_for_service, + mock_get_monthly_usage_for_service, + mock_get_free_sms_fragment_limit, + now, + expected_number_of_months +): + with now: + page = client_request.get('main.usage', service_id=SERVICE_ONE_ID) + rows = page.find('table').find_all('tr', class_='table-row') + assert len(rows) == expected_number_of_months + + @freeze_time("2012-03-31 12:12:12") def test_usage_page_letter_breakdown_ordering( client_request, @@ -1522,177 +1542,6 @@ def test_aggregate_status_types(dict_in, expected_failed, expected_requested): assert sms_counts['requested'] == expected_requested -@pytest.mark.parametrize( - 'now, expected_number_of_months', [ - (freeze_time("2017-12-31 11:09:00.061258"), 12), - (freeze_time("2017-01-01 11:09:00.061258"), 10) - ] -) -def test_get_monthly_usage_breakdown(now, expected_number_of_months): - with now: - breakdown = get_monthly_usage_breakdown(2016, [ - { - 'month': 'April', - 'international': False, - 'rate_multiplier': 1, - 'notification_type': 'sms', - 'rate': 1.65, - 'chargeable_units': 100000, - 'notifications_sent': 1234, - 'sms_charged': 0, - 'sms_free_allowance_used': 100000, - 'sms_cost': 0, - }, - { - 'month': 'May', - 'international': False, - 'rate_multiplier': 1, - 'notification_type': 'sms', - 'rate': 1.65, - 'chargeable_units': 100000, - 'notifications_sent': 1234, - 'sms_charged': 0, - 'sms_free_allowance_used': 100000, - 'sms_cost': 0, - }, - { - 'month': 'June', - 'international': False, - 'rate_multiplier': 1, - 'notification_type': 'sms', - 'rate': 1.71, - 'chargeable_units': 100000, - 'notifications_sent': 1234, - 'sms_charged': 50000, - 'sms_free_allowance_used': 50000, - 'sms_cost': 85500, - }, - { - 'month': 'February', - 'international': False, - 'rate_multiplier': 1, - 'notification_type': 'sms', - 'rate': 1.71, - 'chargeable_units': 2000, - 'notifications_sent': 1234, - 'sms_charged': 2000, - 'sms_free_allowance_used': 0, - 'sms_cost': 3420, - }, - ]) - - assert list(breakdown) == [ - { - 'sms_free_allowance_used': 100000, - 'month': 'April', - 'sms_charged': 0, - 'sms_rate': 1.65, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 100000, - 'month': 'May', - 'sms_charged': 0, - 'sms_rate': 1.65, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 50000, - 'month': 'June', - 'sms_charged': 50000, - 'sms_rate': 1.71, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 85500, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'July', - 'sms_charged': 0, - 'sms_rate': 0, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'August', - 'sms_charged': 0, - 'sms_rate': 0, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'September', - 'sms_charged': 0, - 'sms_rate': 0, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'October', - 'sms_charged': 0, - 'sms_rate': 0, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'November', - 'sms_charged': 0, - 'sms_rate': 0, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'December', - 'sms_charged': 0, - 'sms_rate': 0, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'January', - 'sms_charged': 0, - 'sms_rate': 0, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'February', - 'sms_charged': 2000, - 'sms_rate': 1.71, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 3420, - }, - { - 'sms_free_allowance_used': 0, - 'month': 'March', - 'sms_charged': 0, - 'sms_rate': 0, - 'letter_cost': 0, - 'letter_breakdown': [], - 'sms_cost': 0, - }, - ][:expected_number_of_months] - - def test_get_tuples_of_financial_years(): assert list(get_tuples_of_financial_years( lambda year: 'http://example.com?year={}'.format(year),