Coverage for kwai/core/template/mail_template.py: 100%
14 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 template for creating HTML/Text mails."""
2from typing import Any
4from kwai.core.mail.mail import Mail
5from kwai.core.mail.recipient import Recipients
7from .template import Template
10class MailTemplate:
11 """Defines a wrapper around template to generate an HTML and text mail."""
13 def __init__(self, html_template: Template, text_template: Template):
14 self._html_template = html_template
15 self._text_template = text_template
17 def render_html(self, **kwargs: dict[str, Any]) -> str:
18 """Render the HTML template."""
19 return self._html_template.render(**kwargs)
21 def render_text(self, **kwargs: dict[str, Any]) -> str:
22 """Render the text template."""
23 return self._text_template.render(**kwargs)
25 def create_mail(self, recipients: Recipients, subject: str, **kwargs):
26 """Create the mail with HTML and text template."""
27 return Mail(
28 recipients,
29 subject,
30 self.render_text(**kwargs),
31 self.render_html(**kwargs),
32 )