mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-19 22:13:48 -04:00
Merge pull request #1230 from GSA/notify-admin-1228
change batch file report to look like full csv report
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -71,6 +71,7 @@ def generate_notifications_csv(**kwargs):
|
||||
if "page" not in kwargs:
|
||||
kwargs["page"] = 1
|
||||
|
||||
# This generates the "batch" csv report
|
||||
if kwargs.get("job_id"):
|
||||
original_file_contents = s3download(kwargs["service_id"], kwargs["job_id"])
|
||||
original_upload = RecipientCSV(
|
||||
@@ -79,6 +80,7 @@ def generate_notifications_csv(**kwargs):
|
||||
)
|
||||
original_column_headers = original_upload.column_headers
|
||||
fieldnames = [
|
||||
"Phone Number",
|
||||
"Template",
|
||||
"Sent by",
|
||||
"Batch File",
|
||||
@@ -87,12 +89,13 @@ 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?
|
||||
# This generates the "full" csv report
|
||||
fieldnames = [
|
||||
"Recipient",
|
||||
"Phone Number",
|
||||
"Template",
|
||||
"Sent by",
|
||||
"Batch File",
|
||||
@@ -100,7 +103,6 @@ def generate_notifications_csv(**kwargs):
|
||||
"Status",
|
||||
"Time",
|
||||
]
|
||||
current_app.logger.warning("Invoking deprecated report format")
|
||||
|
||||
yield ",".join(fieldnames) + "\n"
|
||||
|
||||
@@ -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"],
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ from tests.conftest import fake_uuid
|
||||
|
||||
def _get_notifications_csv(
|
||||
row_number=1,
|
||||
recipient="foo@bar.com",
|
||||
recipient="8005555555",
|
||||
template_name="foo",
|
||||
template_type="sms",
|
||||
job_name="bar.csv",
|
||||
@@ -88,15 +88,15 @@ 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",
|
||||
"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time\n",
|
||||
"8005555555,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
|
||||
"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time\n",
|
||||
"8005555555,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
|
||||
2028675309
|
||||
phone number
|
||||
8005555555
|
||||
""",
|
||||
[
|
||||
"Phone Number",
|
||||
"Template",
|
||||
"Sent by",
|
||||
"Batch File",
|
||||
"Carrier Response",
|
||||
"Status",
|
||||
"Time",
|
||||
"phone_number",
|
||||
],
|
||||
[
|
||||
"8005555555",
|
||||
"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
|
||||
2028675309, 🐜,🐝,🦀
|
||||
phone number, a, b, c
|
||||
8005555555, 🐜,🐝,🦀
|
||||
""",
|
||||
[
|
||||
"Phone Number",
|
||||
"Template",
|
||||
"Sent by",
|
||||
"Batch File",
|
||||
"Carrier Response",
|
||||
"Status",
|
||||
"Time",
|
||||
"phone_number",
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
],
|
||||
[
|
||||
"8005555555",
|
||||
"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"
|
||||
"2028675309","🐜,🐜","🐝,🐝","🦀"
|
||||
"phone number", "a", "b", "c"
|
||||
"8005555555","🐜,🐜","🐝,🐝","🦀"
|
||||
""",
|
||||
[
|
||||
"Phone Number",
|
||||
"Template",
|
||||
"Sent by",
|
||||
"Batch File",
|
||||
"Carrier Response",
|
||||
"Status",
|
||||
"Time",
|
||||
"phone_number",
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
],
|
||||
[
|
||||
"8005555555",
|
||||
"foo",
|
||||
"Fake Person",
|
||||
"bar.csv",
|
||||
"Did not like it",
|
||||
"Delivered",
|
||||
"1943-04-19 08:00:00 AM US/Eastern",
|
||||
"2028675309",
|
||||
"🐜,🐜",
|
||||
"🐝,🐝",
|
||||
"🦀",
|
||||
|
||||
Reference in New Issue
Block a user