From 35c3df059c358e7f48ac28f34bdd7880d1a47c70 Mon Sep 17 00:00:00 2001 From: Jumana Bahrainwala Date: Wed, 20 Sep 2023 17:03:04 -0400 Subject: [PATCH] fixing checks --- notifications_utils/recipients.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/notifications_utils/recipients.py b/notifications_utils/recipients.py index 825bdd28..75779e83 100644 --- a/notifications_utils/recipients.py +++ b/notifications_utils/recipients.py @@ -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", @@ -55,6 +57,7 @@ } + class RecipientCSV: def __init__( self, @@ -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 @@ -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"): @@ -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): @@ -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 @@ -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