Coverage for src/kwai/core/mail/recipient.py: 96%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that defines a recipient.""" 

2 

3from dataclasses import dataclass, field 

4 

5from kwai.core.domain.value_objects.email_address import EmailAddress 

6 

7 

8@dataclass(kw_only=True, frozen=True) 

9class Recipient: 

10 """Defines a recipient.""" 

11 

12 email: EmailAddress 

13 name: str 

14 

15 

16@dataclass(frozen=True) 

17class Recipients: 

18 """Defines all recipients for an email. 

19 

20 All methods are immutable. 

21 """ 

22 

23 from_: Recipient 

24 to: list[Recipient] = field(default_factory=list) 

25 cc: list[Recipient] = field(default_factory=list) 

26 bcc: list[Recipient] = field(default_factory=list) 

27 

28 def with_from(self, from_) -> "Recipients": 

29 """Clone the recipients and set the sender.""" 

30 return Recipients(from_, self.to, self.cc, self.bcc) 

31 

32 def with_to(self, *to: Recipient) -> "Recipients": 

33 """Clone the recipients and set the receiver(s).""" 

34 return Recipients(self.from_, list(to), self.cc, self.bcc) 

35 

36 def add_to(self, *to: Recipient) -> "Recipients": 

37 """Clone the recipients and add a receiver.""" 

38 return Recipients(self.from_, self.to + list(to), self.cc, self.bcc) 

39 

40 def with_cc(self, *cc: Recipient) -> "Recipients": 

41 """Clone the recipients and set the copy recipient.""" 

42 return Recipients(self.from_, self.to, list(cc), self.bcc) 

43 

44 def add_cc(self, *cc: Recipient) -> "Recipients": 

45 """Clone the recipients and add a copy recipient.""" 

46 return Recipients(self.from_, self.to, self.cc + list(cc), self.bcc) 

47 

48 def with_bcc(self, *bcc: Recipient) -> "Recipients": 

49 """Clone the recipients and set the blind copy recipient.""" 

50 return Recipients(self.from_, self.to, self.cc, list(bcc)) 

51 

52 def add_bcc(self, *bcc: Recipient) -> "Recipients": 

53 """Clone the recipients and add a blind copy recipient.""" 

54 return Recipients(self.from_, self.to, self.cc, self.bcc + list(bcc))