From 80135b2ff647567d41773ea1960815be48ac0a23 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 5 Feb 2024 12:27:40 -0800 Subject: [PATCH 1/3] notify-api-771 fix columns in reports --- app/utils/csv.py | 62 ++++++++++++++++++------------------- tests/app/utils/test_csv.py | 48 +++++++++++++--------------- 2 files changed, 51 insertions(+), 59 deletions(-) diff --git a/app/utils/csv.py b/app/utils/csv.py index 7cfcb8975..9531e0b5d 100644 --- a/app/utils/csv.py +++ b/app/utils/csv.py @@ -78,21 +78,21 @@ def generate_notifications_csv(**kwargs): template=get_sample_template(kwargs["template_type"]), ) original_column_headers = original_upload.column_headers - fieldnames = ( - ["Row number"] - + original_column_headers - + [ - "Template", - "Type", - "Sent by", - "Job", - "Carrier", - "Carrier Response", - "Status", - "Time", - ] - ) + fieldnames = [ + "Template", + "Type", + "Sent by", + "Job", + "Carrier", + "Carrier Response", + "Status", + "Time", + ] + for header in original_column_headers: + fieldnames.append(header) + else: + # TODO This is deprecated because everything should be a job now, is it ever invoked? fieldnames = [ "Recipient", "Template", @@ -104,6 +104,7 @@ def generate_notifications_csv(**kwargs): "Status", "Time", ] + current_app.logger.warning("Invoking deprecated report format") yield ",".join(fieldnames) + "\n" @@ -118,26 +119,23 @@ def generate_notifications_csv(**kwargs): current_app.logger.info(f"\n\n{notification}") if kwargs.get("job_id"): - values = ( - [ - notification["row_number"], - ] - + [ + values = [ + notification["template_name"], + notification["template_type"], + notification["created_by_name"], + notification["job_name"], + notification["carrier"], + notification["provider_response"], + notification["status"], + preferred_tz_created_at, + ] + for header in original_column_headers: + values.append( original_upload[notification["row_number"] - 1].get(header).data - for header in original_column_headers - ] - + [ - notification["template_name"], - notification["template_type"], - notification["created_by_name"], - notification["job_name"], - notification["carrier"], - notification["provider_response"], - notification["status"], - preferred_tz_created_at, - ] - ) + ) + else: + # TODO This is deprecated, should not be invoked. See above values = [ notification["recipient"], notification["template_name"], diff --git a/tests/app/utils/test_csv.py b/tests/app/utils/test_csv.py index b237d8ad5..c39414ae5 100644 --- a/tests/app/utils/test_csv.py +++ b/tests/app/utils/test_csv.py @@ -46,9 +46,6 @@ def _get_notifications_csv( "notifications": [ { "row_number": row_number + i, - "to": recipient, - "recipient": recipient, - "client_reference": "ref 1234", "template_name": template_name, "template_type": template_type, "template": {"name": template_name, "template_type": template_type}, @@ -60,6 +57,9 @@ def _get_notifications_csv( "updated_at": None, "created_by_name": created_by_name, "created_by_email_address": created_by_email_address, + "to": recipient, + "recipient": recipient, + "client_reference": "ref 1234", } for i in range(rows) ], @@ -130,8 +130,6 @@ def test_generate_notifications_csv_without_job( 2028675309 """, [ - "Row number", - "phone_number", "Template", "Type", "Sent by", @@ -140,10 +138,9 @@ def test_generate_notifications_csv_without_job( "Carrier Response", "Status", "Time", + "phone_number", ], [ - "1", - "2028675309", "foo", "sms", "Fake Person", @@ -152,6 +149,7 @@ def test_generate_notifications_csv_without_job( "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", + "2028675309", ], ), ( @@ -160,11 +158,6 @@ def test_generate_notifications_csv_without_job( 2028675309, 🐜,🐝,🦀 """, [ - "Row number", - "phone_number", - "a", - "b", - "c", "Template", "Type", "Sent by", @@ -173,13 +166,12 @@ def test_generate_notifications_csv_without_job( "Carrier Response", "Status", "Time", + "phone_number", + "a", + "b", + "c", ], [ - "1", - "2028675309", - "🐜", - "🐝", - "🦀", "foo", "sms", "Fake Person", @@ -188,6 +180,10 @@ def test_generate_notifications_csv_without_job( "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", + "2028675309", + "🐜", + "🐝", + "🦀", ], ), ( @@ -196,11 +192,6 @@ def test_generate_notifications_csv_without_job( "2028675309","🐜,🐜","🐝,🐝","🦀" """, [ - "Row number", - "phone_number", - "a", - "b", - "c", "Template", "Type", "Sent by", @@ -209,13 +200,12 @@ def test_generate_notifications_csv_without_job( "Carrier Response", "Status", "Time", + "phone_number", + "a", + "b", + "c", ], [ - "1", - "2028675309", - "🐜,🐜", - "🐝,🐝", - "🦀", "foo", "sms", "Fake Person", @@ -224,6 +214,10 @@ def test_generate_notifications_csv_without_job( "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", + "2028675309", + "🐜,🐜", + "🐝,🐝", + "🦀", ], ), ], From 2aa9f2c532fa2880a5eef70754a48efa7d02dcb6 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 9 Feb 2024 07:27:28 -0800 Subject: [PATCH 2/3] remove carrier column --- app/utils/csv.py | 4 ---- tests/app/utils/test_csv.py | 16 ++++------------ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/utils/csv.py b/app/utils/csv.py index 9531e0b5d..679bdb84a 100644 --- a/app/utils/csv.py +++ b/app/utils/csv.py @@ -83,7 +83,6 @@ def generate_notifications_csv(**kwargs): "Type", "Sent by", "Job", - "Carrier", "Carrier Response", "Status", "Time", @@ -99,7 +98,6 @@ def generate_notifications_csv(**kwargs): "Type", "Sent by", "Job", - "Carrier", "Carrier Response", "Status", "Time", @@ -124,7 +122,6 @@ def generate_notifications_csv(**kwargs): notification["template_type"], notification["created_by_name"], notification["job_name"], - notification["carrier"], notification["provider_response"], notification["status"], preferred_tz_created_at, @@ -142,7 +139,6 @@ def generate_notifications_csv(**kwargs): notification["template_type"], notification["created_by_name"] or "", notification["job_name"] or "", - notification["carrier"], notification["provider_response"], notification["status"], preferred_tz_created_at, diff --git a/tests/app/utils/test_csv.py b/tests/app/utils/test_csv.py index c39414ae5..a3dc446d2 100644 --- a/tests/app/utils/test_csv.py +++ b/tests/app/utils/test_csv.py @@ -18,7 +18,6 @@ def _get_notifications_csv( template_name="foo", template_type="sms", job_name="bar.csv", - carrier="ATT Mobility", provider_response="Did not like it", status="Delivered", created_at="1943-04-19 12:00:00", @@ -50,7 +49,6 @@ def _get_notifications_csv( "template_type": template_type, "template": {"name": template_name, "template_type": template_type}, "job_name": job_name, - "carrier": carrier, "provider_response": provider_response, "status": status, "created_at": created_at, @@ -90,15 +88,15 @@ def get_notifications_csv_mock( ( None, [ - "Recipient,Template,Type,Sent by,Job,Carrier,Carrier Response,Status,Time\n", - "foo@bar.com,foo,sms,,,ATT Mobility,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", + "Recipient,Template,Type,Sent by,Job,Carrier Response,Status,Time\n", + "foo@bar.com,foo,sms,,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", ], ), ( "Anne Example", [ - "Recipient,Template,Type,Sent by,Job,Carrier,Carrier Response,Status,Time\n", - "foo@bar.com,foo,sms,Anne Example,,ATT Mobility,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", # noqa + "Recipient,Template,Type,Sent by,Job,Carrier Response,Status,Time\n", + "foo@bar.com,foo,sms,Anne Example,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", # noqa ], ), ], @@ -134,7 +132,6 @@ def test_generate_notifications_csv_without_job( "Type", "Sent by", "Job", - "Carrier", "Carrier Response", "Status", "Time", @@ -145,7 +142,6 @@ def test_generate_notifications_csv_without_job( "sms", "Fake Person", "bar.csv", - "ATT Mobility", "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", @@ -162,7 +158,6 @@ def test_generate_notifications_csv_without_job( "Type", "Sent by", "Job", - "Carrier", "Carrier Response", "Status", "Time", @@ -176,7 +171,6 @@ def test_generate_notifications_csv_without_job( "sms", "Fake Person", "bar.csv", - "ATT Mobility", "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", @@ -196,7 +190,6 @@ def test_generate_notifications_csv_without_job( "Type", "Sent by", "Job", - "Carrier", "Carrier Response", "Status", "Time", @@ -210,7 +203,6 @@ def test_generate_notifications_csv_without_job( "sms", "Fake Person", "bar.csv", - "ATT Mobility", "Did not like it", "Delivered", "1943-04-19 08:00:00 AM US/Eastern", From 53549495ea8777e0b51e708bb4b7ea952c4bfe39 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 14 Feb 2024 10:39:52 -0800 Subject: [PATCH 3/3] remove Type and change Job to Batch File --- app/utils/csv.py | 8 ++------ tests/app/utils/test_csv.py | 20 +++++++------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/app/utils/csv.py b/app/utils/csv.py index 679bdb84a..ff3c43335 100644 --- a/app/utils/csv.py +++ b/app/utils/csv.py @@ -80,9 +80,8 @@ def generate_notifications_csv(**kwargs): original_column_headers = original_upload.column_headers fieldnames = [ "Template", - "Type", "Sent by", - "Job", + "Batch File", "Carrier Response", "Status", "Time", @@ -95,9 +94,8 @@ def generate_notifications_csv(**kwargs): fieldnames = [ "Recipient", "Template", - "Type", "Sent by", - "Job", + "Batch File", "Carrier Response", "Status", "Time", @@ -119,7 +117,6 @@ def generate_notifications_csv(**kwargs): if kwargs.get("job_id"): values = [ notification["template_name"], - notification["template_type"], notification["created_by_name"], notification["job_name"], notification["provider_response"], @@ -136,7 +133,6 @@ def generate_notifications_csv(**kwargs): values = [ notification["recipient"], notification["template_name"], - notification["template_type"], notification["created_by_name"] or "", notification["job_name"] or "", notification["provider_response"], diff --git a/tests/app/utils/test_csv.py b/tests/app/utils/test_csv.py index a3dc446d2..6963aedfe 100644 --- a/tests/app/utils/test_csv.py +++ b/tests/app/utils/test_csv.py @@ -88,15 +88,15 @@ def get_notifications_csv_mock( ( None, [ - "Recipient,Template,Type,Sent by,Job,Carrier Response,Status,Time\n", - "foo@bar.com,foo,sms,,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", + "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", ], ), ( "Anne Example", [ - "Recipient,Template,Type,Sent by,Job,Carrier Response,Status,Time\n", - "foo@bar.com,foo,sms,Anne Example,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern\r\n", # noqa + "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 ], ), ], @@ -129,9 +129,8 @@ def test_generate_notifications_csv_without_job( """, [ "Template", - "Type", "Sent by", - "Job", + "Batch File", "Carrier Response", "Status", "Time", @@ -139,7 +138,6 @@ def test_generate_notifications_csv_without_job( ], [ "foo", - "sms", "Fake Person", "bar.csv", "Did not like it", @@ -155,9 +153,8 @@ def test_generate_notifications_csv_without_job( """, [ "Template", - "Type", "Sent by", - "Job", + "Batch File", "Carrier Response", "Status", "Time", @@ -168,7 +165,6 @@ def test_generate_notifications_csv_without_job( ], [ "foo", - "sms", "Fake Person", "bar.csv", "Did not like it", @@ -187,9 +183,8 @@ def test_generate_notifications_csv_without_job( """, [ "Template", - "Type", "Sent by", - "Job", + "Batch File", "Carrier Response", "Status", "Time", @@ -200,7 +195,6 @@ def test_generate_notifications_csv_without_job( ], [ "foo", - "sms", "Fake Person", "bar.csv", "Did not like it",