Coverage for src/kwai/modules/identity/user_invitations/user_invitation_mailer.py: 100%
17 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 that defines a mailer for a user invitation."""
3from kwai.core.domain.mailer_service import MailerService
4from kwai.core.mail.mailer import Mailer
5from kwai.core.mail.message import Message
6from kwai.core.mail.recipient import Recipient, Recipients
7from kwai.core.template.mail_template import MailTemplate
8from kwai.modules.identity.user_invitations.user_invitation import UserInvitationEntity
11class UserInvitationMailer(MailerService):
12 """Send a user invitation mail."""
14 def __init__(
15 self,
16 mailer: Mailer,
17 recipients: Recipients,
18 mail_template: MailTemplate,
19 user_invitation: UserInvitationEntity,
20 ):
21 self._mailer = mailer
22 self._recipients = recipients
23 self._mail_template = mail_template
24 self._user_invitation = user_invitation
26 def send(self) -> Message:
27 template_vars = {
28 "uuid": str(self._user_invitation.uuid),
29 "name": str(self._user_invitation.name),
30 "expires": 2,
31 }
33 mail = self._mail_template.create_mail(
34 self._recipients.with_to(
35 Recipient(
36 email=self._user_invitation.email,
37 name=str(self._user_invitation.user.name),
38 )
39 ),
40 "User invitation",
41 **template_vars,
42 )
44 self._mailer.send(mail)
46 return mail