From 78bb2ec88e817c49c1f026be1c6cf3495937ff1b Mon Sep 17 00:00:00 2001 From: Jumana Bahrainwala Date: Tue, 26 Sep 2023 16:08:25 -0400 Subject: [PATCH] fix --- notifications_utils/recipients.py | 9 ++++-- tests/test_recipient_csv.py | 48 +++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/notifications_utils/recipients.py b/notifications_utils/recipients.py index a141a30d..b50a1b04 100644 --- a/notifications_utils/recipients.py +++ b/notifications_utils/recipients.py @@ -138,6 +138,9 @@ def placeholders(self, value): self.recipient_column_headers_as_column_keys = [ Columns.make_key(placeholder) for placeholder in self.recipient_column_headers ] + self.recipient_column_headers_lang_check_as_column_keys = [ + Columns.make_key(placeholder) for placeholder in self.recipient_column_headers_lang_check + ] @property def template_type(self): @@ -198,9 +201,9 @@ def get_rows(self): for column_name, column_value in zip(column_headers, row): column_value = strip_and_remove_obscure_whitespace(column_value) - - if Columns.make_key(column_name) in self.recipient_column_headers_as_column_keys: - output_dict[column_name] = column_value or None + if Columns.make_key(column_name) in self.recipient_column_headers_lang_check_as_column_keys: + english_name = first_column_headings["en"][self.template_type][0] + output_dict[english_name] = column_value or None else: insert_or_append_to_dict(output_dict, column_name, column_value or None) diff --git a/tests/test_recipient_csv.py b/tests/test_recipient_csv.py index cdd218af..98fc2550 100644 --- a/tests/test_recipient_csv.py +++ b/tests/test_recipient_csv.py @@ -109,14 +109,14 @@ def _index_rows(rows): ), ( """ - address courriel,name + adresse courriel,name test@example.com,test1 test2@example.com, test2 """, "email", [ - [("address courriel", "test@example.com"), ("name", "test1")], - [("address courriel", "test2@example.com"), ("name", "test2")], + [("email address", "test@example.com"), ("name", "test1")], + [("email address", "test2@example.com"), ("name", "test2")], ], "fr", ), @@ -129,9 +129,9 @@ def _index_rows(rows): """, "sms", [ - [("numéro de téléphone", "07900900001"), ("list", ["cat", "rat", "gnat"])], - [("numéro de téléphone", "07900900002"), ("list", ["dog", "hog", "frog"])], - [("numéro de téléphone", "07900900003"), ("list", ["elephant", None, None])], + [("phone number", "07900900001"), ("list", ["cat", "rat", "gnat"])], + [("phone number", "07900900002"), ("list", ["dog", "hog", "frog"])], + [("phone number", "07900900003"), ("list", ["elephant", None, None])], ], "fr", ), @@ -144,9 +144,9 @@ def _index_rows(rows): """, "sms", [ - [("numéro de téléphone", "07900900001"), ("list", ["cat", "rat", "gnat"])], - [("numéro de téléphone", "07900900002"), ("list", ["dog", "hog", "frog"])], - [("numéro de téléphone", "07900900003"), ("list", ["elephant", None, None])], + [("phone number", "07900900001"), ("list", ["cat", "rat", "gnat"])], + [("phone number", "07900900002"), ("list", ["dog", "hog", "frog"])], + [("phone number", "07900900003"), ("list", ["elephant", None, None])], ], "en", ), @@ -192,6 +192,36 @@ def test_get_rows_does_no_error_checking_of_rows_or_cells(mocker): assert cell_recipient_error_mock.called is False +def test_get_rows_does_no_error_checking_of_rows_or_cells_fr(mocker): + has_error_mock = mocker.patch.object(Row, "has_error") + has_bad_recipient_mock = mocker.patch.object(Row, "has_bad_recipient") + has_missing_data_mock = mocker.patch.object(Row, "has_missing_data") + cell_recipient_error_mock = mocker.patch.object(Cell, "recipient_error") + + recipients = RecipientCSV( + """ + adresse courriel, name + a@b.com, + a@b.com, My Name + a@b.com, + + + """, + template_type="email", + placeholders=["name"], + max_errors_shown=3, + ) + + rows = recipients.get_rows() + for i in range(3): + assert next(rows).recipient == "a@b.com" + + assert has_error_mock.called is False + assert has_bad_recipient_mock.called is False + assert has_missing_data_mock.called is False + assert cell_recipient_error_mock.called is False + + def test_get_rows_only_iterates_over_file_once(mocker): row_mock = mocker.patch("notifications_utils.recipients.Row")