Coverage for kwai/modules/identity/user_invitations/user_invitation_mailer.py: 100%
17 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module that defines a mailer for a user invitation."""
2from kwai.core.domain.mailer_service import MailerService
3from kwai.core.mail.mailer import Mailer
4from kwai.core.mail.message import Message
5from kwai.core.mail.recipient import Recipient, Recipients
6from kwai.core.template.mail_template import MailTemplate
7from kwai.modules.identity.user_invitations.user_invitation import UserInvitationEntity
10class UserInvitationMailer(MailerService):
11 """Send a user invitation mail."""
13 def __init__(
14 self,
15 mailer: Mailer,
16 recipients: Recipients,
17 mail_template: MailTemplate,
18 user_invitation: UserInvitationEntity,
19 ):
20 self._mailer = mailer
21 self._recipients = recipients
22 self._mail_template = mail_template
23 self._user_invitation = user_invitation
25 def send(self) -> Message:
26 template_vars = {
27 "uuid": str(self._user_invitation.uuid),
28 "name": str(self._user_invitation.name),
29 "expires": 2,
30 }
32 mail = self._mail_template.create_mail(
33 self._recipients.with_to(
34 Recipient(
35 email=self._user_invitation.email,
36 name=str(self._user_invitation.user.name),
37 )
38 ),
39 "User invitation",
40 **template_vars,
41 )
43 self._mailer.send(mail)
45 return mail