Merge pull request #1193 from GSA/notify-api-771b

Notify api 771 fix columns in reports
This commit is contained in:
Carlo Costino
2024-02-16 09:59:32 -05:00
committed by GitHub
2 changed files with 63 additions and 93 deletions

View File

@@ -78,32 +78,29 @@ 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",
]
)
else:
fieldnames = [
"Recipient",
"Template",
"Type",
"Sent by",
"Job",
"Carrier",
"Batch File",
"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",
"Sent by",
"Batch File",
"Carrier Response",
"Status",
"Time",
]
current_app.logger.warning("Invoking deprecated report format")
yield ",".join(fieldnames) + "\n"
@@ -118,33 +115,26 @@ 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["created_by_name"],
notification["job_name"],
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"],
notification["template_type"],
notification["created_by_name"] or "",
notification["job_name"] or "",
notification["carrier"],
notification["provider_response"],
notification["status"],
preferred_tz_created_at,

View File

@@ -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",
@@ -46,20 +45,19 @@ 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},
"job_name": job_name,
"carrier": carrier,
"provider_response": provider_response,
"status": status,
"created_at": created_at,
"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)
],
@@ -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,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,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,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
],
),
],
@@ -130,28 +128,22 @@ def test_generate_notifications_csv_without_job(
2028675309
""",
[
"Row number",
"phone_number",
"Template",
"Type",
"Sent by",
"Job",
"Carrier",
"Batch File",
"Carrier Response",
"Status",
"Time",
"phone_number",
],
[
"1",
"2028675309",
"foo",
"sms",
"Fake Person",
"bar.csv",
"ATT Mobility",
"Did not like it",
"Delivered",
"1943-04-19 08:00:00 AM US/Eastern",
"2028675309",
],
),
(
@@ -160,34 +152,28 @@ def test_generate_notifications_csv_without_job(
2028675309, 🐜,🐝,🦀
""",
[
"Row number",
"Template",
"Sent by",
"Batch File",
"Carrier Response",
"Status",
"Time",
"phone_number",
"a",
"b",
"c",
"Template",
"Type",
"Sent by",
"Job",
"Carrier",
"Carrier Response",
"Status",
"Time",
],
[
"1",
"foo",
"Fake Person",
"bar.csv",
"Did not like it",
"Delivered",
"1943-04-19 08:00:00 AM US/Eastern",
"2028675309",
"🐜",
"🐝",
"🦀",
"foo",
"sms",
"Fake Person",
"bar.csv",
"ATT Mobility",
"Did not like it",
"Delivered",
"1943-04-19 08:00:00 AM US/Eastern",
],
),
(
@@ -196,34 +182,28 @@ def test_generate_notifications_csv_without_job(
"2028675309","🐜,🐜","🐝,🐝","🦀"
""",
[
"Row number",
"Template",
"Sent by",
"Batch File",
"Carrier Response",
"Status",
"Time",
"phone_number",
"a",
"b",
"c",
"Template",
"Type",
"Sent by",
"Job",
"Carrier",
"Carrier Response",
"Status",
"Time",
],
[
"1",
"foo",
"Fake Person",
"bar.csv",
"Did not like it",
"Delivered",
"1943-04-19 08:00:00 AM US/Eastern",
"2028675309",
"🐜,🐜",
"🐝,🐝",
"🦀",
"foo",
"sms",
"Fake Person",
"bar.csv",
"ATT Mobility",
"Did not like it",
"Delivered",
"1943-04-19 08:00:00 AM US/Eastern",
],
),
],