-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to display FR column headings in reports CSVs (#1681)
* Add support to display FR column headings in reports csvs - Converts email_address to Email address - Converts phone_number to Phone number * Translate template_type and status values to FR * Fix incorrect translation, fix failing tests * Add proper French translations - Fetch translations using fr.csv * Add UTF-8 BOM to CSV for compatability with MS excel * Fix tests that broke when adding the UTF-8 BOM to CSVs * Remove 'name' from the translation mapping dict
- Loading branch information
Showing
4 changed files
with
139 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,14 +180,14 @@ def test_spreadsheet_checks_for_bad_arguments(args, kwargs): | |
( | ||
None, | ||
[ | ||
"Recipient,Template,Type,Sent by,Sent by email,Job,Status,Time\n", | ||
"Recipient,Template,Type,Sent by,Sent by email,Job,Status,Sent Time\n", | ||
"[email protected],foo,sms,,[email protected],,Delivered,1943-04-19 12:00:00\r\n", | ||
], | ||
), | ||
( | ||
"Anne Example", | ||
[ | ||
"Recipient,Template,Type,Sent by,Sent by email,Job,Status,Time\n", | ||
"Recipient,Template,Type,Sent by,Sent by email,Job,Status,Sent Time\n", | ||
"[email protected],foo,sms,Anne Example,[email protected],,Delivered,1943-04-19 12:00:00\r\n", | ||
], | ||
), | ||
|
@@ -199,16 +199,18 @@ def test_generate_notifications_csv_without_job( | |
created_by_name, | ||
expected_content, | ||
): | ||
mocker.patch( | ||
"app.notification_api_client.get_notifications_for_service", | ||
side_effect=_get_notifications_csv( | ||
created_by_name=created_by_name, | ||
created_by_email_address="[email protected]", | ||
job_id=None, | ||
job_name=None, | ||
), | ||
) | ||
assert list(generate_notifications_csv(service_id=fake_uuid)) == expected_content | ||
with app_.test_request_context(): | ||
mocker.patch.dict("app.current_app.config", values={"LANGUAGES": ["en", "fr"]}) | ||
mocker.patch( | ||
"app.notification_api_client.get_notifications_for_service", | ||
side_effect=_get_notifications_csv( | ||
created_by_name=created_by_name, | ||
created_by_email_address="[email protected]", | ||
job_id=None, | ||
job_name=None, | ||
), | ||
) | ||
assert list(generate_notifications_csv(service_id=fake_uuid))[1::] == expected_content | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -219,7 +221,7 @@ def test_generate_notifications_csv_without_job( | |
phone_number | ||
07700900123 | ||
""", | ||
["Row number", "phone_number", "Template", "Type", "Job", "Status", "Time"], | ||
["Row number", "Phone number", "Template", "Type", "Job", "Status", "Sent Time"], | ||
[ | ||
"1", | ||
"07700900123", | ||
|
@@ -234,18 +236,18 @@ def test_generate_notifications_csv_without_job( | |
""" | ||
phone_number, a, b, c | ||
07700900123, 🐜,🐝,🦀 | ||
""", | ||
""", | ||
[ | ||
"Row number", | ||
"phone_number", | ||
"Phone number", | ||
"a", | ||
"b", | ||
"c", | ||
"Template", | ||
"Type", | ||
"Job", | ||
"Status", | ||
"Time", | ||
"Sent Time", | ||
], | ||
[ | ||
"1", | ||
|
@@ -267,15 +269,15 @@ def test_generate_notifications_csv_without_job( | |
""", | ||
[ | ||
"Row number", | ||
"phone_number", | ||
"Phone number", | ||
"a", | ||
"b", | ||
"c", | ||
"Template", | ||
"Type", | ||
"Job", | ||
"Status", | ||
"Time", | ||
"Sent Time", | ||
], | ||
[ | ||
"1", | ||
|
@@ -300,23 +302,29 @@ def test_generate_notifications_csv_returns_correct_csv_file( | |
expected_column_headers, | ||
expected_1st_row, | ||
): | ||
mocker.patch( | ||
"app.s3_client.s3_csv_client.s3download", | ||
return_value=original_file_contents, | ||
) | ||
csv_content = generate_notifications_csv(service_id="1234", job_id=fake_uuid, template_type="sms") | ||
csv_file = DictReader(StringIO("\n".join(csv_content))) | ||
assert csv_file.fieldnames == expected_column_headers | ||
assert next(csv_file) == dict(zip(expected_column_headers, expected_1st_row)) | ||
with app_.test_request_context(): | ||
mocker.patch.dict("app.current_app.config", values={"LANGUAGES": ["en", "fr"]}) | ||
mocker.patch( | ||
"app.s3_client.s3_csv_client.s3download", | ||
return_value=original_file_contents, | ||
) | ||
# Remove encoded BOM bytes before parsing | ||
csv_content = list(generate_notifications_csv(service_id="1234", job_id=fake_uuid, template_type="sms"))[1::] | ||
csv_file = DictReader(StringIO("\n".join(csv_content))) | ||
assert csv_file.fieldnames == expected_column_headers | ||
assert next(csv_file) == dict(zip(expected_column_headers, expected_1st_row)) | ||
|
||
|
||
def test_generate_notifications_csv_only_calls_once_if_no_next_link( | ||
app_, | ||
mocker, | ||
_get_notifications_csv_mock, | ||
): | ||
list(generate_notifications_csv(service_id="1234")) | ||
with app_.test_request_context(): | ||
mocker.patch.dict("app.current_app.config", values={"LANGUAGES": ["en", "fr"]}) | ||
list(generate_notifications_csv(service_id="1234")) | ||
|
||
assert _get_notifications_csv_mock.call_count == 1 | ||
assert _get_notifications_csv_mock.call_count == 1 | ||
|
||
|
||
@pytest.mark.parametrize("job_id", ["some", None]) | ||
|
@@ -325,49 +333,55 @@ def test_generate_notifications_csv_calls_twice_if_next_link( | |
mocker, | ||
job_id, | ||
): | ||
mocker.patch( | ||
"app.s3_client.s3_csv_client.s3download", | ||
return_value=""" | ||
phone_number | ||
07700900000 | ||
07700900001 | ||
07700900002 | ||
07700900003 | ||
07700900004 | ||
07700900005 | ||
07700900006 | ||
07700900007 | ||
07700900008 | ||
07700900009 | ||
""", | ||
) | ||
with app_.test_request_context(): | ||
mocker.patch.dict("app.current_app.config", values={"LANGUAGES": ["en", "fr"]}) | ||
|
||
mocker.patch( | ||
"app.s3_client.s3_csv_client.s3download", | ||
return_value=""" | ||
phone_number | ||
07700900000 | ||
07700900001 | ||
07700900002 | ||
07700900003 | ||
07700900004 | ||
07700900005 | ||
07700900006 | ||
07700900007 | ||
07700900008 | ||
07700900009 | ||
""", | ||
) | ||
|
||
service_id = "1234" | ||
response_with_links = _get_notifications_csv(rows=7, with_links=True) | ||
response_with_no_links = _get_notifications_csv(rows=3, row_number=8, with_links=False) | ||
service_id = "1234" | ||
response_with_links = _get_notifications_csv(rows=7, with_links=True) | ||
response_with_no_links = _get_notifications_csv(rows=3, row_number=8, with_links=False) | ||
|
||
mock_get_notifications = mocker.patch( | ||
"app.notification_api_client.get_notifications_for_service", | ||
side_effect=[ | ||
response_with_links(service_id), | ||
response_with_no_links(service_id), | ||
], | ||
) | ||
mock_get_notifications = mocker.patch( | ||
"app.notification_api_client.get_notifications_for_service", | ||
side_effect=[ | ||
response_with_links(service_id), | ||
response_with_no_links(service_id), | ||
], | ||
) | ||
|
||
csv_content = generate_notifications_csv( | ||
service_id=service_id, | ||
job_id=job_id or fake_uuid, | ||
template_type="sms", | ||
) | ||
csv = list(DictReader(StringIO("\n".join(csv_content)))) | ||
|
||
assert len(csv) == 10 | ||
assert csv[0]["phone_number"] == "07700900000" | ||
assert csv[9]["phone_number"] == "07700900009" | ||
assert mock_get_notifications.call_count == 2 | ||
# mock_calls[0][2] is the kwargs from first call | ||
assert mock_get_notifications.mock_calls[0][2]["page"] == 1 | ||
assert mock_get_notifications.mock_calls[1][2]["page"] == 2 | ||
# Remove encoded BOM bytes before parsing | ||
csv_content = list( | ||
generate_notifications_csv( | ||
service_id=service_id, | ||
job_id=job_id or fake_uuid, | ||
template_type="sms", | ||
) | ||
)[1::] | ||
csv = list(DictReader(StringIO("\n".join(csv_content)))) | ||
|
||
assert len(csv) == 10 | ||
assert csv[0]["Phone number"] == "07700900000" | ||
assert csv[9]["Phone number"] == "07700900009" | ||
assert mock_get_notifications.call_count == 2 | ||
# mock_calls[0][2] is the kwargs from first call | ||
assert mock_get_notifications.mock_calls[0][2]["page"] == 1 | ||
assert mock_get_notifications.mock_calls[1][2]["page"] == 2 | ||
|
||
|
||
def test_get_cdn_domain_on_localhost(client, mocker): | ||
|