Coverage for kwai/modules/identity/user_recoveries/user_recovery_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 recovery email."""
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_recoveries.user_recovery import UserRecoveryEntity
10class UserRecoveryMailer(MailerService):
11 """Sends a user recovery mail."""
13 def __init__(
14 self,
15 mailer: Mailer,
16 recipients: Recipients,
17 mail_template: MailTemplate,
18 user_recovery: UserRecoveryEntity,
19 ):
20 self._mailer = mailer
21 self._recipients = recipients
22 self._mail_template = mail_template
23 self._user_recovery = user_recovery
25 def send(self) -> Message:
26 template_vars = {
27 "uuid": str(self._user_recovery.uuid),
28 "name": str(self._user_recovery.user.name),
29 "expires": 2,
30 }
32 mail = self._mail_template.create_mail(
33 self._recipients.with_to(
34 Recipient(
35 email=self._user_recovery.user.email,
36 name=str(self._user_recovery.user.name),
37 )
38 ),
39 "User recovery",
40 **template_vars,
41 )
43 self._mailer.send(mail)
45 return mail