fix tests

This commit is contained in:
Kenneth Kehl
2023-09-22 10:05:50 -07:00
parent e3490691d3
commit 5bc752a826
3 changed files with 23 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
from flask import current_app
from notifications_utils.recipients import RecipientCSV from notifications_utils.recipients import RecipientCSV
from app.models.spreadsheet import Spreadsheet from app.models.spreadsheet import Spreadsheet
@@ -75,7 +76,7 @@ def generate_notifications_csv(**kwargs):
fieldnames = ( fieldnames = (
["Row number"] ["Row number"]
+ original_column_headers + original_column_headers
+ ["Template", "Type", "Job", "Status", "Time"] + ["Template", "Type", "Sent by", "Job", "Status", "Time"]
) )
else: else:
fieldnames = [ fieldnames = [
@@ -95,6 +96,7 @@ def generate_notifications_csv(**kwargs):
**kwargs **kwargs
) )
for notification in notifications_resp["notifications"]: for notification in notifications_resp["notifications"]:
current_app.logger.info(notification)
if kwargs.get("job_id"): if kwargs.get("job_id"):
values = ( values = (
[ [
@@ -107,6 +109,7 @@ def generate_notifications_csv(**kwargs):
+ [ + [
notification["template_name"], notification["template_name"],
notification["template_type"], notification["template_type"],
notification["created_by_name"],
notification["job_name"], notification["job_name"],
notification["status"], notification["status"],
notification["created_at"], notification["created_at"],

View File

@@ -517,7 +517,7 @@ def notification_json(
"notification_type": template_type, "notification_type": template_type,
"reply_to_text": reply_to_text, "reply_to_text": reply_to_text,
"client_reference": client_reference, "client_reference": client_reference,
"created_by_name": created_by_name, "created_by_name": None,
} }
for i in range(rows) for i in range(rows)
], ],

View File

@@ -19,8 +19,8 @@ def _get_notifications_csv(
rows=1, rows=1,
with_links=False, with_links=False,
job_id=fake_uuid, job_id=fake_uuid,
created_by_name=None, created_by_name="Fake Person",
created_by_email_address=None, created_by_email_address="FakePerson@fake.gov",
): ):
def _get( def _get(
service_id, service_id,
@@ -121,12 +121,22 @@ def test_generate_notifications_csv_without_job(
phone_number phone_number
2028675309 2028675309
""", """,
["Row number", "phone_number", "Template", "Type", "Job", "Status", "Time"], [
"Row number",
"phone_number",
"Template",
"Type",
"Sent by",
"Job",
"Status",
"Time",
],
[ [
"1", "1",
"2028675309", "2028675309",
"foo", "foo",
"sms", "sms",
"Fake Person",
"bar.csv", "bar.csv",
"Delivered", "Delivered",
"1943-04-19 12:00:00", "1943-04-19 12:00:00",
@@ -145,6 +155,7 @@ def test_generate_notifications_csv_without_job(
"c", "c",
"Template", "Template",
"Type", "Type",
"Sent by",
"Job", "Job",
"Status", "Status",
"Time", "Time",
@@ -157,6 +168,7 @@ def test_generate_notifications_csv_without_job(
"🦀", "🦀",
"foo", "foo",
"sms", "sms",
"Fake Person",
"bar.csv", "bar.csv",
"Delivered", "Delivered",
"1943-04-19 12:00:00", "1943-04-19 12:00:00",
@@ -175,6 +187,7 @@ def test_generate_notifications_csv_without_job(
"c", "c",
"Template", "Template",
"Type", "Type",
"Sent by",
"Job", "Job",
"Status", "Status",
"Time", "Time",
@@ -187,6 +200,7 @@ def test_generate_notifications_csv_without_job(
"🦀", "🦀",
"foo", "foo",
"sms", "sms",
"Fake Person",
"bar.csv", "bar.csv",
"Delivered", "Delivered",
"1943-04-19 12:00:00", "1943-04-19 12:00:00",
@@ -209,6 +223,7 @@ def test_generate_notifications_csv_returns_correct_csv_file(
csv_content = generate_notifications_csv( csv_content = generate_notifications_csv(
service_id="1234", job_id=fake_uuid, template_type="sms" service_id="1234", job_id=fake_uuid, template_type="sms"
) )
csv_file = DictReader(StringIO("\n".join(csv_content))) csv_file = DictReader(StringIO("\n".join(csv_content)))
assert csv_file.fieldnames == expected_column_headers assert csv_file.fieldnames == expected_column_headers
assert next(csv_file) == dict(zip(expected_column_headers, expected_1st_row)) assert next(csv_file) == dict(zip(expected_column_headers, expected_1st_row))