Coverage for src/kwai/core/domain/value_objects/email_address.py: 100%
11 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module for an email address value object."""
3from dataclasses import dataclass
5from pyisemail import is_email
8class InvalidEmailException(Exception):
9 """Raised when the email address is not valid."""
12@dataclass(frozen=True, slots=True)
13class EmailAddress:
14 """A value object for an email address."""
16 email: str
18 def __post_init__(self):
19 """Check if the email address is valid."""
20 if not is_email(self.email):
21 raise InvalidEmailException(f"{self.email} is not a valid email address.")
23 def __str__(self):
24 """Return the string representation of an email address."""
25 return self.email