Fixed testcase due to email validation
This commit is contained in:
@@ -622,26 +622,12 @@ def create_res_notif_push_message(
|
|||||||
|
|
||||||
|
|
||||||
def _validate_and_repair_email(email: str | None) -> str | None:
|
def _validate_and_repair_email(email: str | None) -> str | None:
|
||||||
"""Validate and repair email addresses with common typos.
|
|
||||||
|
|
||||||
Attempts to fix trailing digits in TLDs (e.g., .de1 -> .de)
|
|
||||||
before validation. If the email is still invalid, returns None
|
|
||||||
instead of raising an exception.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
email: Email address to validate and repair
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Normalized email address or None if invalid
|
|
||||||
"""
|
|
||||||
if email is None:
|
if email is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Remove trailing digits from TLD (e.g., .de1 -> .de, .com2 -> .com)
|
|
||||||
# This matches a dot followed by letters, then trailing digits at the end
|
|
||||||
email = re.sub(r'(\.[a-zA-Z]+)\d+$', r'\1', email)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# remove numbers from top-level domain (TLD) if any
|
||||||
|
email = re.sub(r"\.\d+", ".", email)
|
||||||
|
|
||||||
email_info = validate_email(email)
|
email_info = validate_email(email)
|
||||||
except EmailNotValidError as e:
|
except EmailNotValidError as e:
|
||||||
_LOGGER.warning("invalid email address: %s", e)
|
_LOGGER.warning("invalid email address: %s", e)
|
||||||
@@ -659,13 +645,16 @@ def _process_single_reservation(
|
|||||||
[(customer.phone, PhoneTechType.MOBILE)] if customer.phone is not None else []
|
[(customer.phone, PhoneTechType.MOBILE)] if customer.phone is not None else []
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Validate and repair email address
|
||||||
|
email = _validate_and_repair_email(customer.email_address)
|
||||||
|
|
||||||
customer_data = CustomerData(
|
customer_data = CustomerData(
|
||||||
given_name=customer.given_name,
|
given_name=customer.given_name,
|
||||||
surname=customer.surname,
|
surname=customer.surname,
|
||||||
name_prefix=customer.name_prefix,
|
name_prefix=customer.name_prefix,
|
||||||
name_title=customer.name_title,
|
name_title=customer.name_title,
|
||||||
phone_numbers=phone_numbers,
|
phone_numbers=phone_numbers,
|
||||||
email_address=customer.email_address,
|
email_address=email,
|
||||||
email_newsletter=customer.email_newsletter,
|
email_newsletter=customer.email_newsletter,
|
||||||
address_line=customer.address_line,
|
address_line=customer.address_line,
|
||||||
city_name=customer.city_name,
|
city_name=customer.city_name,
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ def sample_customer():
|
|||||||
contact_id="CONTACT-12345",
|
contact_id="CONTACT-12345",
|
||||||
name_prefix="Mr.",
|
name_prefix="Mr.",
|
||||||
name_title="Jr.",
|
name_title="Jr.",
|
||||||
email_address="john.doe@example.com",
|
email_address="john.doe@gmail.com",
|
||||||
phone="+1234567890",
|
phone="+1234567890",
|
||||||
email_newsletter=True,
|
email_newsletter=True,
|
||||||
address_line="123 Main Street",
|
address_line="123 Main Street",
|
||||||
@@ -378,7 +378,7 @@ class TestXMLParsing:
|
|||||||
# Verify customer data is present
|
# Verify customer data is present
|
||||||
assert "John" in xml_output
|
assert "John" in xml_output
|
||||||
assert "Doe" in xml_output
|
assert "Doe" in xml_output
|
||||||
assert "john.doe@example.com" in xml_output
|
assert "john.doe@gmail.com" in xml_output
|
||||||
|
|
||||||
# Verify reservation data is present
|
# Verify reservation data is present
|
||||||
# assert "RES-2024-001" in xml_output
|
# assert "RES-2024-001" in xml_output
|
||||||
|
|||||||
Reference in New Issue
Block a user