Skip to content

Commit

Permalink
fixing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai committed Sep 20, 2023
1 parent 91f0227 commit 35c3df0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions notifications_utils/recipients.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
},
"email": ["email address"], # left this for backwards compatibility
"sms": ["phone number"], # left this for backwards compatibility
"email_both": ["email address", "adresse courriel"],
"sms_both": ["phone number", "numéro de téléphone"],
"letter": [
"address line 1",
"address line 2",
Expand All @@ -55,6 +57,7 @@
}



class RecipientCSV:
def __init__(
self,
Expand All @@ -70,6 +73,7 @@ def __init__(
max_rows=50000,
user_language="en",
):
self.user_language = user_language
self.file_data = strip_whitespace(file_data, extra_characters=",")
self.template_type = template_type
self.placeholders = placeholders
Expand All @@ -81,7 +85,6 @@ def __init__(
self.remaining_messages = remaining_messages
self.rows_as_list = None
self.max_rows = max_rows
self.user_language = user_language

def __len__(self):
if not hasattr(self, "_len"):
Expand Down Expand Up @@ -125,6 +128,7 @@ def template_type(self):
def template_type(self, value):
self._template_type = value
self.recipient_column_headers = first_column_headings[self.user_language][self.template_type]
self.recipient_column_headers_lang_check = first_column_headings["email_both"] if self.template_type == "email" else first_column_headings["sms_both"]

@property
def has_errors(self):
Expand Down Expand Up @@ -276,7 +280,7 @@ def missing_column_headers(self):
return set(
key
for key in self.placeholders
if (Columns.make_key(key) not in self.column_headers_as_column_keys and not self.is_optional_address_column(key))
if (Columns.make_key(key) not in self.column_headers_as_column_keys and not self.is_optional_address_column(key) and key not in self.recipient_column_headers_lang_check)
)

@property
Expand All @@ -300,13 +304,12 @@ def is_optional_address_column(self, key):

@property
def has_recipient_columns(self):
return (
return set(self.column_headers_as_column_keys).issubset(
set(
Columns.make_key(recipient_column)
for recipient_column in self.recipient_column_headers
for recipient_column in self.recipient_column_headers_lang_check
if not self.is_optional_address_column(recipient_column)
)
<= self.column_headers_as_column_keys
)

def _get_error_for_field(self, key, value): # noqa: C901
Expand Down

0 comments on commit 35c3df0

Please sign in to comment.