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

1"""Module for an email address value object.""" 

2 

3from dataclasses import dataclass 

4 

5from pyisemail import is_email 

6 

7 

8class InvalidEmailException(Exception): 

9 """Raised when the email address is not valid.""" 

10 

11 

12@dataclass(frozen=True, slots=True) 

13class EmailAddress: 

14 """A value object for an email address.""" 

15 

16 email: str 

17 

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.") 

22 

23 def __str__(self): 

24 """Return the string representation of an email address.""" 

25 return self.email