Show international letters on the usage page

The api returns letter details split by postage, so international
letters are returned with a postage of `europe` or `rest-of-world` not
`international` and these rows need to be added together when the rate
is the same before they are displayed on the usage page.

To do this, we need to replace the postage of `europe` and
`rest-of-world` with `international`. The data then needs to be sorted
by postage and rate before the letter units for rows which are
international and have the same rate are added together.
This commit is contained in:
Katie Smith
2020-07-09 18:44:03 +01:00
parent 2a6691f665
commit 355e981028
4 changed files with 104 additions and 16 deletions

View File

@@ -967,7 +967,7 @@ def test_usage_page(
assert 'April' in table
assert 'February' in table
assert 'March' in table
assert '£20.59' in table
assert '£28.99' in table
assert '140 free text messages' in table
assert '£20.30' in table
assert '1,230 text messages at 1.65p' in table
@@ -1009,12 +1009,13 @@ def test_usage_page_with_letters(
assert 'April' in table
assert 'February' in table
assert 'March' in table
assert '£20.59' in table
assert '£28.99' in table
assert '140 free text messages' in table
assert '£20.30' in table
assert '1,230 text messages at 1.65p' in table
assert '10 second class letters at 31p' in normalize_spaces(table)
assert '5 first class letters at 33p' in normalize_spaces(table)
assert '10 international letters at 84p' in normalize_spaces(table)
@freeze_time("2012-04-30 12:12:12")
@@ -1027,6 +1028,9 @@ def test_usage_page_displays_letters_ordered_by_postage(
):
billable_units_resp = [
{'month': 'April', 'notification_type': 'letter', 'rate': 0.5, 'billing_units': 1, 'postage': 'second'},
{'month': 'April', 'notification_type': 'letter', 'rate': 1, 'billing_units': 1, 'postage': 'europe'},
{'month': 'April', 'notification_type': 'letter', 'rate': 1, 'billing_units': 2, 'postage': 'rest-of-word'},
{'month': 'April', 'notification_type': 'letter', 'rate': 1.5, 'billing_units': 7, 'postage': 'europe'},
{'month': 'April', 'notification_type': 'letter', 'rate': 0.3, 'billing_units': 3, 'postage': 'second'},
{'month': 'April', 'notification_type': 'letter', 'rate': 0.5, 'billing_units': 1, 'postage': 'first'},
]
@@ -1040,10 +1044,44 @@ def test_usage_page_displays_letters_ordered_by_postage(
row_for_april = page.find('table').find('tr', class_='table-row')
postage_details = row_for_april.find_all('li', class_='tabular-numbers')
assert len(postage_details) == 3
assert len(postage_details) == 5
assert normalize_spaces(postage_details[0].text) == '1 first class letter at 50p'
assert normalize_spaces(postage_details[1].text) == '3 second class letters at 30p'
assert normalize_spaces(postage_details[2].text) == '1 second class letter at 50p'
assert normalize_spaces(postage_details[3].text) == '3 international letters at £1.00'
assert normalize_spaces(postage_details[4].text) == '7 international letters at £1.50'
@freeze_time("2012-07-30 12:12:12")
def test_usage_page_displays_letters_split_by_month_and_postage(
mocker,
client_request,
service_one,
mock_get_usage,
mock_get_free_sms_fragment_limit
):
billable_units_resp = [
{'month': 'April', 'notification_type': 'letter', 'rate': 0.5, 'billing_units': 1, 'postage': 'second'},
{'month': 'April', 'notification_type': 'letter', 'rate': 1, 'billing_units': 1, 'postage': 'europe'},
{'month': 'May', 'notification_type': 'letter', 'rate': 1, 'billing_units': 7, 'postage': 'europe'},
{'month': 'May', 'notification_type': 'letter', 'rate': 0.5, 'billing_units': 3, 'postage': 'second'},
{'month': 'May', 'notification_type': 'letter', 'rate': 0.7, 'billing_units': 1, 'postage': 'first'},
]
mocker.patch('app.billing_api_client.get_billable_units', return_value=billable_units_resp)
service_one['permissions'].append('letter')
page = client_request.get(
'main.usage',
service_id=SERVICE_ONE_ID,
)
april_row = normalize_spaces(page.find('table').find_all('tr')[1].text)
may_row = normalize_spaces(page.find('table').find_all('tr')[2].text)
assert '1 second class letter at 50p' in april_row
assert '1 international letter at £1.00' in april_row
assert '1 first class letter at 70p' in may_row
assert '3 second class letters at 50p' in may_row
assert '7 international letters at £1.00' in may_row
def test_usage_page_with_year_argument(