notify-api-771 fix columns in reports

This commit is contained in:
Kenneth Kehl
2024-02-05 12:27:40 -08:00
parent e18054d2d8
commit 80135b2ff6
2 changed files with 51 additions and 59 deletions
+30 -32
View File
@@ -78,21 +78,21 @@ def generate_notifications_csv(**kwargs):
template=get_sample_template(kwargs["template_type"]), template=get_sample_template(kwargs["template_type"]),
) )
original_column_headers = original_upload.column_headers original_column_headers = original_upload.column_headers
fieldnames = ( fieldnames = [
["Row number"] "Template",
+ original_column_headers "Type",
+ [ "Sent by",
"Template", "Job",
"Type", "Carrier",
"Sent by", "Carrier Response",
"Job", "Status",
"Carrier", "Time",
"Carrier Response", ]
"Status", for header in original_column_headers:
"Time", fieldnames.append(header)
]
)
else: else:
# TODO This is deprecated because everything should be a job now, is it ever invoked?
fieldnames = [ fieldnames = [
"Recipient", "Recipient",
"Template", "Template",
@@ -104,6 +104,7 @@ def generate_notifications_csv(**kwargs):
"Status", "Status",
"Time", "Time",
] ]
current_app.logger.warning("Invoking deprecated report format")
yield ",".join(fieldnames) + "\n" yield ",".join(fieldnames) + "\n"
@@ -118,26 +119,23 @@ def generate_notifications_csv(**kwargs):
current_app.logger.info(f"\n\n{notification}") current_app.logger.info(f"\n\n{notification}")
if kwargs.get("job_id"): if kwargs.get("job_id"):
values = ( values = [
[ notification["template_name"],
notification["row_number"], 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 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: else:
# TODO This is deprecated, should not be invoked. See above
values = [ values = [
notification["recipient"], notification["recipient"],
notification["template_name"], notification["template_name"],
+21 -27
View File
@@ -46,9 +46,6 @@ def _get_notifications_csv(
"notifications": [ "notifications": [
{ {
"row_number": row_number + i, "row_number": row_number + i,
"to": recipient,
"recipient": recipient,
"client_reference": "ref 1234",
"template_name": template_name, "template_name": template_name,
"template_type": template_type, "template_type": template_type,
"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, "updated_at": None,
"created_by_name": created_by_name, "created_by_name": created_by_name,
"created_by_email_address": created_by_email_address, "created_by_email_address": created_by_email_address,
"to": recipient,
"recipient": recipient,
"client_reference": "ref 1234",
} }
for i in range(rows) for i in range(rows)
], ],
@@ -130,8 +130,6 @@ def test_generate_notifications_csv_without_job(
2028675309 2028675309
""", """,
[ [
"Row number",
"phone_number",
"Template", "Template",
"Type", "Type",
"Sent by", "Sent by",
@@ -140,10 +138,9 @@ def test_generate_notifications_csv_without_job(
"Carrier Response", "Carrier Response",
"Status", "Status",
"Time", "Time",
"phone_number",
], ],
[ [
"1",
"2028675309",
"foo", "foo",
"sms", "sms",
"Fake Person", "Fake Person",
@@ -152,6 +149,7 @@ def test_generate_notifications_csv_without_job(
"Did not like it", "Did not like it",
"Delivered", "Delivered",
"1943-04-19 08:00:00 AM US/Eastern", "1943-04-19 08:00:00 AM US/Eastern",
"2028675309",
], ],
), ),
( (
@@ -160,11 +158,6 @@ def test_generate_notifications_csv_without_job(
2028675309, 🐜,🐝,🦀 2028675309, 🐜,🐝,🦀
""", """,
[ [
"Row number",
"phone_number",
"a",
"b",
"c",
"Template", "Template",
"Type", "Type",
"Sent by", "Sent by",
@@ -173,13 +166,12 @@ def test_generate_notifications_csv_without_job(
"Carrier Response", "Carrier Response",
"Status", "Status",
"Time", "Time",
"phone_number",
"a",
"b",
"c",
], ],
[ [
"1",
"2028675309",
"🐜",
"🐝",
"🦀",
"foo", "foo",
"sms", "sms",
"Fake Person", "Fake Person",
@@ -188,6 +180,10 @@ def test_generate_notifications_csv_without_job(
"Did not like it", "Did not like it",
"Delivered", "Delivered",
"1943-04-19 08:00:00 AM US/Eastern", "1943-04-19 08:00:00 AM US/Eastern",
"2028675309",
"🐜",
"🐝",
"🦀",
], ],
), ),
( (
@@ -196,11 +192,6 @@ def test_generate_notifications_csv_without_job(
"2028675309","🐜,🐜","🐝,🐝","🦀" "2028675309","🐜,🐜","🐝,🐝","🦀"
""", """,
[ [
"Row number",
"phone_number",
"a",
"b",
"c",
"Template", "Template",
"Type", "Type",
"Sent by", "Sent by",
@@ -209,13 +200,12 @@ def test_generate_notifications_csv_without_job(
"Carrier Response", "Carrier Response",
"Status", "Status",
"Time", "Time",
"phone_number",
"a",
"b",
"c",
], ],
[ [
"1",
"2028675309",
"🐜,🐜",
"🐝,🐝",
"🦀",
"foo", "foo",
"sms", "sms",
"Fake Person", "Fake Person",
@@ -224,6 +214,10 @@ def test_generate_notifications_csv_without_job(
"Did not like it", "Did not like it",
"Delivered", "Delivered",
"1943-04-19 08:00:00 AM US/Eastern", "1943-04-19 08:00:00 AM US/Eastern",
"2028675309",
"🐜,🐜",
"🐝,🐝",
"🦀",
], ],
), ),
], ],