From c6f5467009d8246fd8e67fd9d4781132a64b2eaf Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Tue, 26 Apr 2022 15:26:08 +0100 Subject: [PATCH] Extend main test for service usage page This adds missing assertions for email and SMS usage, as well as letters with the help of some additional test data. Previously we were only checking monthly usage (in other tests). --- tests/app/main/views/test_dashboard.py | 28 ++++++++++++++++++++------ tests/conftest.py | 9 ++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 4f51a50d0..877dc3b3a 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1002,15 +1002,31 @@ def test_usage_page( mock_get_usage.assert_called_once_with(SERVICE_ONE_ID, 2011) mock_get_free_sms_fragment_limit.assert_called_with(SERVICE_ONE_ID, 2011) - cols = page.find_all('div', {'class': 'govuk-grid-column-one-third'}) nav = page.find('ul', {'class': 'pill'}) unselected_nav_links = nav.select('a:not(.pill-item--selected)') - assert normalize_spaces(nav.find('a', {'aria-current': 'page'}).text) == '2011 to 2012 financial year' assert normalize_spaces(unselected_nav_links[0].text) == '2010 to 2011 financial year' assert normalize_spaces(unselected_nav_links[1].text) == '2009 to 2010 financial year' - assert '252,190' in cols[1].text - assert 'Text messages' in cols[1].text + + annual_usage = page.find_all('div', {'class': 'govuk-grid-column-one-third'}) + + # annual stats are shown in two rows, each with three column; email is col 1 + email_column = normalize_spaces(annual_usage[0].text + annual_usage[3].text) + assert 'Emails' in email_column + assert '1,000 sent' in email_column + + sms_column = normalize_spaces(annual_usage[1].text + annual_usage[4].text) + assert 'Text messages' in sms_column + assert '252,190 sent' in sms_column + assert '250,000 free allowance' in sms_column + assert '0 free allowance remaining' in sms_column + assert '£36.14 spent' in sms_column + assert '2,190 at 1.65 pence' in sms_column + + letter_column = normalize_spaces(annual_usage[2].text + annual_usage[5].text) + assert 'Letters' in letter_column + assert '100 sent' in letter_column + assert '£30.00 spent' in letter_column @freeze_time("2012-03-31 12:12:12") @@ -1834,7 +1850,7 @@ def test_breadcrumb_shows_if_service_is_suspended( ['email', 'sms'], ['email', 'sms', 'letter'], )) -def test_should_show_usage_on_dashboard( +def test_service_dashboard_shows_usage( client_request, service_one, mock_get_service_templates, @@ -1855,6 +1871,6 @@ def test_should_show_usage_on_dashboard( 'free email allowance ' '£36.14 ' 'spent on text messages ' - '£0.00 ' + '£30.00 ' 'spent on letters' ) diff --git a/tests/conftest.py b/tests/conftest.py index 721474770..9d4dc3a61 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2350,7 +2350,14 @@ def mock_get_usage(mocker, service_one, fake_uuid): "notifications_sent": 90, "rate": 0.0165, "letter_total": 0 - } + }, + { + "notification_type": "letter", + "chargeable_units": 300, + "notifications_sent": 100, + "rate": 0.1, + "letter_total": 30 + }, ] return mocker.patch(