-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated recipients.csv to accept both lang
- EN FR headings are now allowed for sms and email - Your error message will be in the language of your choice
- Loading branch information
Showing
2 changed files
with
156 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,18 +14,10 @@ def _index_rows(rows): | |
|
||
|
||
@pytest.mark.parametrize( | ||
"file_contents,template_type,expected", | ||
"file_contents,template_type,expected,user_language", | ||
[ | ||
( | ||
"", | ||
"sms", | ||
[], | ||
), | ||
( | ||
"phone number", | ||
"sms", | ||
[], | ||
), | ||
("", "sms", [], "en"), | ||
("phone number", "sms", [], "fr"), | ||
( | ||
""" | ||
phone number,name | ||
|
@@ -34,6 +26,7 @@ def _index_rows(rows): | |
""", | ||
"sms", | ||
[[("phone number", "+1 123"), ("name", "test1")], [("phone number", "+1 456"), ("name", "test2")]], | ||
"en", | ||
), | ||
( | ||
""" | ||
|
@@ -43,6 +36,7 @@ def _index_rows(rows): | |
""", | ||
"sms", | ||
[[("phone number", "+1 123"), ("name", None)], [("phone number", "+1 456"), ("name", None)]], | ||
"en", | ||
), | ||
( | ||
""" | ||
|
@@ -55,6 +49,7 @@ def _index_rows(rows): | |
[("email address", "[email protected]"), ("name", "test1")], | ||
[("email address", "[email protected]"), ("name", "test2")], | ||
], | ||
"en", | ||
), | ||
( | ||
""" | ||
|
@@ -67,6 +62,7 @@ def _index_rows(rows): | |
[("email address", "[email protected]"), (None, ["test1", "red"])], | ||
[("email address", "[email protected]"), (None, ["test2", "blue"])], | ||
], | ||
"en", | ||
), | ||
( | ||
""" | ||
|
@@ -81,6 +77,7 @@ def _index_rows(rows): | |
[("email address", "[email protected]"), ("name", "test2")], | ||
[("email address", "[email protected]"), ("name", "test3")], | ||
], | ||
"en", | ||
), | ||
( | ||
""" | ||
|
@@ -93,53 +90,70 @@ def _index_rows(rows): | |
[("email address", "[email protected]"), ("date", "Nov 28, 2016"), ("name", "test1")], | ||
[("email address", "[email protected]"), ("date", "Nov 29, 2016"), ("name", "test2")], | ||
], | ||
"en", | ||
), | ||
( | ||
""" | ||
address_line_1 | ||
Alice | ||
Bob | ||
phone number, list, list, list | ||
07900900001, cat, rat, gnat | ||
07900900002, dog, hog, frog | ||
07900900003, elephant | ||
""", | ||
"letter", | ||
[[("address_line_1", "Alice")], [("address_line_1", "Bob")]], | ||
"sms", | ||
[ | ||
[("phone number", "07900900001"), ("list", ["cat", "rat", "gnat"])], | ||
[("phone number", "07900900002"), ("list", ["dog", "hog", "frog"])], | ||
[("phone number", "07900900003"), ("list", ["elephant", None, None])], | ||
], | ||
"en", | ||
), | ||
( | ||
""" | ||
address line 1,address line 2,address line 5,address line 6,postcode,name,thing | ||
A. Name,,,,XM4 5HQ,example,example | ||
address courriel,name | ||
[email protected],test1 | ||
[email protected], test2 | ||
""", | ||
"letter", | ||
"email", | ||
[ | ||
[ | ||
("addressline1", "A. Name"), | ||
("addressline2", None), | ||
# optional address rows 3 and 4 not in file | ||
("addressline5", None), | ||
("addressline5", None), | ||
("postcode", "XM4 5HQ"), | ||
("name", "example"), | ||
("thing", "example"), | ||
] | ||
[("address courriel", "[email protected]"), ("name", "test1")], | ||
[("address courriel", "[email protected]"), ("name", "test2")], | ||
], | ||
"fr", | ||
), | ||
( | ||
""" | ||
phone number, list, list, list | ||
numéro de téléphone, list, list, list | ||
07900900001, cat, rat, gnat | ||
07900900002, dog, hog, frog | ||
07900900003, elephant | ||
""", | ||
"sms", | ||
[ | ||
[("phone number", "07900900001"), ("list", ["cat", "rat", "gnat"])], | ||
[("phone number", "07900900002"), ("list", ["dog", "hog", "frog"])], | ||
[("phone number", "07900900003"), ("list", ["elephant", None, None])], | ||
[("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])], | ||
], | ||
"fr", | ||
), | ||
( | ||
""" | ||
numéro de téléphone, list, list, list | ||
07900900001, cat, rat, gnat | ||
07900900002, dog, hog, frog | ||
07900900003, elephant | ||
""", | ||
"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])], | ||
], | ||
"en", | ||
), | ||
], | ||
) | ||
def test_get_rows(file_contents, template_type, expected): | ||
rows = list(RecipientCSV(file_contents, template_type=template_type).rows) | ||
def test_get_rows(file_contents, template_type, expected, user_language): | ||
rows = list(RecipientCSV(file_contents, template_type=template_type, user_language=user_language).rows) | ||
if not expected: | ||
assert rows == expected | ||
for index, row in enumerate(expected): | ||
|
@@ -399,35 +413,42 @@ def test_get_recipient_respects_order(file_contents, template_type, placeholders | |
|
||
|
||
@pytest.mark.parametrize( | ||
"file_contents,template_type,expected,expected_missing", | ||
"file_contents,template_type,expected,expected_missing, user_language", | ||
[ | ||
("", "sms", [], set(["phone number", "name"])), | ||
("", "sms", [], set(["phone number", "name"]), "en"), | ||
("", "email", [], set(["email address", "name"]), "en"), | ||
( | ||
""" | ||
phone number,name | ||
numéro de téléphone, name | ||
6502532222,test1 | ||
6502532222,test1 | ||
6502532222,test1 | ||
""", | ||
"sms", | ||
["phone number", "name"], | ||
["numéro de téléphone", "name"], | ||
set(), | ||
"fr", | ||
), | ||
( | ||
""" | ||
email address,name,colour | ||
phone number,name | ||
6502532222,test1 | ||
6502532222,test1 | ||
6502532222,test1 | ||
""", | ||
"email", | ||
["email address", "name", "colour"], | ||
"sms", | ||
["phone number", "name"], | ||
set(), | ||
"en", | ||
), | ||
( | ||
""" | ||
address_line_1, address_line_2, postcode, name | ||
email address,name,colour | ||
""", | ||
"letter", | ||
["address_line_1", "address_line_2", "postcode", "name"], | ||
"email", | ||
["email address", "name", "colour"], | ||
set(), | ||
"en", | ||
), | ||
( | ||
""" | ||
|
@@ -436,27 +457,42 @@ def test_get_recipient_respects_order(file_contents, template_type, placeholders | |
"email", | ||
["email address", "colour"], | ||
set(["name"]), | ||
"en", | ||
), | ||
( | ||
""" | ||
address_line_1, address_line_2, name | ||
phone number,list,list,name,list | ||
""", | ||
"letter", | ||
["address_line_1", "address_line_2", "name"], | ||
set(["postcode"]), | ||
"sms", | ||
["phone number", "list", "name"], | ||
set(), | ||
"en", | ||
), | ||
( | ||
""" | ||
phone number,list,list,name,list | ||
numéro de téléphone,list,list,name,list | ||
""", | ||
"sms", | ||
["phone number", "list", "name"], | ||
["numéro de téléphone", "list", "name"], | ||
set(), | ||
"en", | ||
), | ||
( | ||
""" | ||
list,list,name,list | ||
""", | ||
"sms", | ||
[ | ||
"list", | ||
"name", | ||
], | ||
set(["numéro de téléphone"]), | ||
"fr", | ||
), | ||
], | ||
) | ||
def test_column_headers(file_contents, template_type, expected, expected_missing): | ||
recipients = RecipientCSV(file_contents, template_type=template_type, placeholders=["name"]) | ||
def test_column_headers(file_contents, template_type, expected, expected_missing, user_language): | ||
recipients = RecipientCSV(file_contents, template_type=template_type, placeholders=["name"], user_language=user_language) | ||
assert recipients.column_headers == expected | ||
assert recipients.missing_column_headers == expected_missing | ||
assert recipients.has_errors == bool(expected_missing) | ||
|
@@ -469,20 +505,14 @@ def test_column_headers(file_contents, template_type, expected, expected_missing | |
pytest.param("", "sms", marks=pytest.mark.xfail), | ||
pytest.param("name", "sms", marks=pytest.mark.xfail), | ||
pytest.param("email address", "sms", marks=pytest.mark.xfail), | ||
pytest.param( | ||
# missing postcode | ||
"address_line_1, address_line_2, address_line_3, address_line_4, address_line_5", | ||
"letter", | ||
marks=pytest.mark.xfail, | ||
), | ||
("phone number", "sms"), | ||
("phone number,name", "sms"), | ||
("email address", "email"), | ||
("email address,name", "email"), | ||
("PHONENUMBER", "sms"), | ||
("email_address", "email"), | ||
("address_line_1, address_line_2, postcode", "letter"), | ||
("address_line_1, address_line_2, address_line_3, address_line_4, address_line_5, address_line_6, postcode", "letter"), | ||
("adresse courriel", "email"), | ||
("numéro de téléphone", "sms"), | ||
], | ||
) | ||
def test_recipient_column(placeholders, file_contents, template_type): | ||
|