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