mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Don’t convert Excel reports to CSV before output
Converting Python data to CSV makes every field a string. This means that in the report we return to the user every field will be a string, even if it’s come from an `int` type in Python. This is because the CSV ‘standard’ doesn’t support any kind of typing. Excel does support types for fields, so we can make our reports more useful by preserving these types. This is particularly relevant in the report we generate for performance platform, which needs the `count` column to be a number type. This commit adds extra code paths to the `Spreadsheet` class which mean that it can be instantiated from either CSV data or a list of Python data. Previously we were converting the Python data to CSV as an intermediate step, before instantiating the class.
This commit is contained in:
@@ -989,12 +989,12 @@ def test_get_performance_platform_report(client, platform_admin_user, mocker):
|
||||
mocker.patch(
|
||||
'app.service_api_client.get_live_services_data',
|
||||
return_value={'data': [
|
||||
{'service_id': 1, 'service_name': 'jessie the oak tree', 'organisation_name': 'Forest',
|
||||
{'service_id': 'abc123', 'service_name': 'jessie the oak tree', 'organisation_name': 'Forest',
|
||||
'consent_to_research': True, 'contact_name': 'Forest fairy', 'organisation_type': 'Ecosystem',
|
||||
'contact_email': 'forest.fairy@digital.cabinet-office.gov.uk', 'contact_mobile': '+447700900986',
|
||||
'live_date': 'Sat, 29 Mar 2014 00:00:00 GMT', 'sms_volume_intent': 100, 'email_volume_intent': 50,
|
||||
'letter_volume_intent': 20, 'sms_totals': 300, 'email_totals': 1200, 'letter_totals': 0},
|
||||
{'service_id': 2, 'service_name': 'james the pine tree', 'organisation_name': 'Forest',
|
||||
{'service_id': 'def456', 'service_name': 'james the pine tree', 'organisation_name': 'Forest',
|
||||
'consent_to_research': None, 'contact_name': None, 'organisation_type': 'Ecosystem',
|
||||
'contact_email': None, 'contact_mobile': None,
|
||||
'live_date': None, 'sms_volume_intent': None, 'email_volume_intent': 60,
|
||||
@@ -1008,6 +1008,6 @@ def test_get_performance_platform_report(client, platform_admin_user, mocker):
|
||||
file_stream=response.get_data(),
|
||||
) == [
|
||||
['service_id', 'agency', 'service_name', '_timestamp', 'service', 'count'],
|
||||
['1', 'Forest', 'jessie the oak tree', '2014-03-29T00:00:00Z', 'govuk-notify', '1'],
|
||||
['2', 'Forest', 'james the pine tree', '', 'govuk-notify', '1'],
|
||||
['abc123', 'Forest', 'jessie the oak tree', '2014-03-29T00:00:00Z', 'govuk-notify', 1],
|
||||
['def456', 'Forest', 'james the pine tree', '', 'govuk-notify', 1],
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user