Fixed testcase due to email validation

This commit is contained in:
Jonas Linter
2025-10-14 09:27:39 +02:00
parent 99d1ed1732
commit 669cf00bbc
2 changed files with 9 additions and 20 deletions

View File

@@ -622,26 +622,12 @@ def create_res_notif_push_message(
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:
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:
# remove numbers from top-level domain (TLD) if any
email = re.sub(r"\.\d+", ".", email)
email_info = validate_email(email)
except EmailNotValidError as 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 []
)
# Validate and repair email address
email = _validate_and_repair_email(customer.email_address)
customer_data = CustomerData(
given_name=customer.given_name,
surname=customer.surname,
name_prefix=customer.name_prefix,
name_title=customer.name_title,
phone_numbers=phone_numbers,
email_address=customer.email_address,
email_address=email,
email_newsletter=customer.email_newsletter,
address_line=customer.address_line,
city_name=customer.city_name,

View File

@@ -66,7 +66,7 @@ def sample_customer():
contact_id="CONTACT-12345",
name_prefix="Mr.",
name_title="Jr.",
email_address="john.doe@example.com",
email_address="john.doe@gmail.com",
phone="+1234567890",
email_newsletter=True,
address_line="123 Main Street",
@@ -378,7 +378,7 @@ class TestXMLParsing:
# Verify customer data is present
assert "John" 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
# assert "RES-2024-001" in xml_output