From 4742cc77b5bd94fafd77566dcd35681e5b7761ca Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 21 Feb 2024 07:45:21 -0800 Subject: [PATCH] change batch file report to look like full csv report --- app/main/views/dashboard.py | 4 +++- app/utils/csv.py | 16 ++++++++++------ tests/app/main/views/test_dashboard.py | 2 +- tests/app/utils/test_csv.py | 24 ++++++++++++------------ 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index c2a11eccf..24b3e0490 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -49,7 +49,9 @@ def service_dashboard(service_id): return redirect(url_for("main.choose_template", service_id=service_id)) job_response = job_api_client.get_jobs(service_id)["data"] - notifications_response = notification_api_client.get_notifications_for_service(service_id)["notifications"] + notifications_response = notification_api_client.get_notifications_for_service( + service_id + )["notifications"] service_data_retention_days = 7 aggregate_notifications_by_job = defaultdict(list) diff --git a/app/utils/csv.py b/app/utils/csv.py index ff3c43335..e923b2eb2 100644 --- a/app/utils/csv.py +++ b/app/utils/csv.py @@ -79,6 +79,7 @@ def generate_notifications_csv(**kwargs): ) original_column_headers = original_upload.column_headers fieldnames = [ + "Recipient", "Template", "Sent by", "Batch File", @@ -87,7 +88,8 @@ def generate_notifications_csv(**kwargs): "Time", ] for header in original_column_headers: - fieldnames.append(header) + if header.lower() != "phone number": + fieldnames.append(header) else: # TODO This is deprecated because everything should be a job now, is it ever invoked? @@ -113,9 +115,9 @@ def generate_notifications_csv(**kwargs): notification["created_at"] ) - current_app.logger.info(f"\n\n{notification}") if kwargs.get("job_id"): values = [ + notification["recipient"], notification["template_name"], notification["created_by_name"], notification["job_name"], @@ -124,12 +126,14 @@ def generate_notifications_csv(**kwargs): preferred_tz_created_at, ] for header in original_column_headers: - values.append( - original_upload[notification["row_number"] - 1].get(header).data - ) + if header.lower() != "phone number": + values.append( + original_upload[notification["row_number"] - 1] + .get(header) + .data + ) else: - # TODO This is deprecated, should not be invoked. See above values = [ notification["recipient"], notification["template_name"], diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 53a8a7feb..37674e797 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -122,7 +122,7 @@ MOCK_JOBS_AND_NOTIFICATIONS = [ "notification_count": MOCK_JOBS["data"][0]["notification_count"], "notifications": FAKE_ONE_OFF_NOTIFICATION["notifications"], "time_left": "Data available for 7 days", - "view_job_link": "/services/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/jobs/463b5ecb-4e32-43e5-aa90-0234d19fceaa" + "view_job_link": "/services/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/jobs/463b5ecb-4e32-43e5-aa90-0234d19fceaa", }, ] diff --git a/tests/app/utils/test_csv.py b/tests/app/utils/test_csv.py index 6963aedfe..4a43b81c3 100644 --- a/tests/app/utils/test_csv.py +++ b/tests/app/utils/test_csv.py @@ -14,7 +14,7 @@ from tests.conftest import fake_uuid def _get_notifications_csv( row_number=1, - recipient="foo@bar.com", + recipient="2028675309", template_name="foo", template_type="sms", job_name="bar.csv", @@ -89,14 +89,14 @@ def get_notifications_csv_mock( None, [ "Recipient,Template,Sent by,Batch File,Carrier Response,Status,Time\n", - "foo@bar.com,foo,,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", + "2028675309,foo,,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", ], ), ( "Anne Example", [ "Recipient,Template,Sent by,Batch File,Carrier Response,Status,Time\n", - "foo@bar.com,foo,Anne Example,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", # noqa + "2028675309,foo,Anne Example,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", # noqa ], ), ], @@ -124,53 +124,53 @@ def test_generate_notifications_csv_without_job( [ ( """ - phone_number + phone number 2028675309 """, [ + "Recipient", "Template", "Sent by", "Batch File", "Carrier Response", "Status", "Time", - "phone_number", ], [ + "2028675309", "foo", "Fake Person", "bar.csv", "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", - "2028675309", ], ), ( """ - phone_number, a, b, c + phone number, a, b, c 2028675309, 🐜,🐝,🦀 """, [ + "Recipient", "Template", "Sent by", "Batch File", "Carrier Response", "Status", "Time", - "phone_number", "a", "b", "c", ], [ + "2028675309", "foo", "Fake Person", "bar.csv", "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", - "2028675309", "🐜", "🐝", "🦀", @@ -178,29 +178,29 @@ def test_generate_notifications_csv_without_job( ), ( """ - "phone_number", "a", "b", "c" + "phone number", "a", "b", "c" "2028675309","🐜,🐜","🐝,🐝","🦀" """, [ + "Recipient", "Template", "Sent by", "Batch File", "Carrier Response", "Status", "Time", - "phone_number", "a", "b", "c", ], [ + "2028675309", "foo", "Fake Person", "bar.csv", "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", - "2028675309", "🐜,🐜", "🐝,🐝", "🦀",