Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai committed Sep 26, 2023
1 parent 8d62ea9 commit 78bb2ec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
9 changes: 6 additions & 3 deletions notifications_utils/recipients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
48 changes: 39 additions & 9 deletions tests/test_recipient_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ def _index_rows(rows):
),
(
"""
address courriel,name
adresse courriel,name
[email protected],test1
[email protected], test2
""",
"email",
[
[("address courriel", "[email protected]"), ("name", "test1")],
[("address courriel", "[email protected]"), ("name", "test2")],
[("email address", "[email protected]"), ("name", "test1")],
[("email address", "[email protected]"), ("name", "test2")],
],
"fr",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand Down Expand Up @@ -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
[email protected],
[email protected], My Name
[email protected],
""",
template_type="email",
placeholders=["name"],
max_errors_shown=3,
)

rows = recipients.get_rows()
for i in range(3):
assert next(rows).recipient == "[email protected]"

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")

Expand Down

0 comments on commit 78bb2ec

Please sign in to comment.