From c559ff8c973b05618038e355ea432c17d3adc693 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 31 May 2019 12:13:34 +0100 Subject: [PATCH 1/3] refactored live_services_csv with the aim of making the link between api return values and csv column headers more apparent --- app/main/views/platform_admin.py | 52 ++++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/app/main/views/platform_admin.py b/app/main/views/platform_admin.py index ba3b7c4a1..72a9e46cb 100644 --- a/app/main/views/platform_admin.py +++ b/app/main/views/platform_admin.py @@ -203,33 +203,33 @@ def platform_admin_reports(): @user_is_platform_admin def live_services_csv(): results = service_api_client.get_live_services_data()["data"] - live_services_columns = [ - "Service ID", "Organisation", "Organisation type", "Service name", "Consent to research", "Main contact", - "Contact email", "Contact mobile", "Live date", "SMS volume intent", "Email volume intent", - "Letter volume intent", "SMS sent this year", "Emails sent this year", "Letters sent this year" - ] - live_services_data = [] - live_services_data.append(live_services_columns) + + column_names = OrderedDict([ + ('service_id', 'Service ID'), + ('organisation_name', 'Organisation'), + ('organisation_type', 'Organisation type'), + ('service_name', 'Service name'), + ('consent_to_research', 'Consent to research'), + ('contact_name', 'Main contact'), + ('contact_email', 'Contact email'), + ('contact_mobile', 'Contact mobile'), + ('live_date', 'Live date'), + ('sms_volume_intent', 'SMS volume intent'), + ('email_volume_intent', 'Email volume intent'), + ('letter_volume_intent', 'Letter volume intent'), + ('sms_totals', 'SMS sent this year'), + ('email_totals', 'Emails sent this year'), + ('letter_totals', 'Letters sent this year'), + ]) + + # initialise with header row + live_services_data = [[x for x in column_names.values()]] + for row in results: - live_services_data.append([ - row["service_id"], - row["organisation_name"], - row["organisation_type"], - row["service_name"], - row["consent_to_research"], - row["contact_name"], - row["contact_email"], - row["contact_mobile"], - datetime.strptime( - row["live_date"], '%a, %d %b %Y %X %Z' - ).strftime("%d-%m-%Y") if row["live_date"] else None, - row["sms_volume_intent"], - row["email_volume_intent"], - row["letter_volume_intent"], - row["sms_totals"], - row["email_totals"], - row["letter_totals"], - ]) + if row['live_date']: + row['live_date'] = datetime.strptime(row["live_date"], '%a, %d %b %Y %X %Z').strftime("%d-%m-%Y") + + live_services_data.append([row[api_key] for api_key in column_names.keys()]) return Spreadsheet.from_rows(live_services_data).as_csv_data, 200, { 'Content-Type': 'text/csv; charset=utf-8', From daa8868fd83e0afe5728f3762b7c82f025cf8bee Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 31 May 2019 12:22:54 +0100 Subject: [PATCH 2/3] make test marginally more readable --- tests/app/main/views/test_platform_admin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/app/main/views/test_platform_admin.py b/tests/app/main/views/test_platform_admin.py index 44a5bb81f..633d882c0 100644 --- a/tests/app/main/views/test_platform_admin.py +++ b/tests/app/main/views/test_platform_admin.py @@ -976,9 +976,12 @@ def test_get_live_services_report(client, platform_admin_user, mocker): assert report.strip() == ( 'Service ID,Organisation,Organisation type,Service name,Consent to research,Main contact,Contact email,' + 'Contact mobile,Live date,SMS volume intent,Email volume intent,Letter volume intent,SMS sent this year,' - + 'Emails sent this year,Letters sent this year\r\n1,Forest,Ecosystem,jessie the oak tree,True,Forest fairy,' - + 'forest.fairy@digital.cabinet-office.gov.uk,+447700900986,29-03-2014,100,50,20,300,1200,0\r\n2,Forest,' - + 'Ecosystem,james the pine tree,,,,,,,60,0,0,0,0' + + 'Emails sent this year,Letters sent this year\r\n' + + + '1,Forest,Ecosystem,jessie the oak tree,True,Forest fairy,forest.fairy@digital.cabinet-office.gov.uk,' + + '+447700900986,29-03-2014,100,50,20,300,1200,0\r\n' + + + '2,Forest,Ecosystem,james the pine tree,,,,,,,60,0,0,0,0' ) From fb0279b8200b4fd35cbd690a1afe9c3371315239 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 31 May 2019 12:24:18 +0100 Subject: [PATCH 3/3] return free sms allowance in live services csv report --- app/main/views/platform_admin.py | 1 + tests/app/main/views/test_platform_admin.py | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/main/views/platform_admin.py b/app/main/views/platform_admin.py index 72a9e46cb..47dddc90f 100644 --- a/app/main/views/platform_admin.py +++ b/app/main/views/platform_admin.py @@ -220,6 +220,7 @@ def live_services_csv(): ('sms_totals', 'SMS sent this year'), ('email_totals', 'Emails sent this year'), ('letter_totals', 'Letters sent this year'), + ('free_sms_fragment_limit', 'Free sms allowance'), ]) # initialise with header row diff --git a/tests/app/main/views/test_platform_admin.py b/tests/app/main/views/test_platform_admin.py index 633d882c0..2e0b5a765 100644 --- a/tests/app/main/views/test_platform_admin.py +++ b/tests/app/main/views/test_platform_admin.py @@ -962,12 +962,14 @@ def test_get_live_services_report(client, platform_admin_user, mocker): '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}, + 'letter_volume_intent': 20, 'sms_totals': 300, 'email_totals': 1200, 'letter_totals': 0, + 'free_sms_fragment_limit': 100}, {'service_id': 2, '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, - 'letter_volume_intent': 0, 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 0}, + 'letter_volume_intent': 0, 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 0, + 'free_sms_fragment_limit': 200}, ]} ) response = client.get(url_for('main.live_services_csv')) @@ -976,12 +978,12 @@ def test_get_live_services_report(client, platform_admin_user, mocker): assert report.strip() == ( 'Service ID,Organisation,Organisation type,Service name,Consent to research,Main contact,Contact email,' + 'Contact mobile,Live date,SMS volume intent,Email volume intent,Letter volume intent,SMS sent this year,' - + 'Emails sent this year,Letters sent this year\r\n' + + 'Emails sent this year,Letters sent this year,Free sms allowance\r\n' + '1,Forest,Ecosystem,jessie the oak tree,True,Forest fairy,forest.fairy@digital.cabinet-office.gov.uk,' - + '+447700900986,29-03-2014,100,50,20,300,1200,0\r\n' + + '+447700900986,29-03-2014,100,50,20,300,1200,0,100\r\n' - + '2,Forest,Ecosystem,james the pine tree,,,,,,,60,0,0,0,0' + + '2,Forest,Ecosystem,james the pine tree,,,,,,,60,0,0,0,0,200' )