File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from typing import ClassVar
1+ from typing import Any , ClassVar
22
33from core .external_apis .smtp_email import EmailClient , email_client
44from django .db import models
@@ -17,6 +17,12 @@ class EmailNotificationTemplate(NotificationTemplateBase):
1717class EmailNotificationHistorySentTo (NotificationHistorySentToBase ):
1818 history = models .ForeignKey ("EmailNotificationHistory" , on_delete = models .PROTECT , related_name = "sent_to_list" )
1919
20+ @property
21+ def payload (self ) -> dict [str , Any ]:
22+ rendered = self .render ()
23+ rendered ["body" ] = self .render_as_html ()
24+ return rendered
25+
2026
2127class EmailNotificationHistoryQuerySet (
2228 NotificationHistoryQuerySet ["EmailNotificationHistory" , EmailNotificationTemplate ],
Original file line number Diff line number Diff line change @@ -126,6 +126,30 @@ def test_history_send_parameters_uses_rendered_payload(system_user):
126126 assert params ["template_code" ] == "render"
127127
128128
129+ @pytest .mark .django_db
130+ def test_email_payload_body_is_html_rendered (system_user ):
131+ # 이메일 발송 시 payload["body"]는 HTML 템플릿으로 렌더링된 결과여야 함.
132+ tpl = EmailNotificationTemplate .objects .create (
133+ code = "html-body" ,
134+ title = "t" ,
135+ sent_from = "a@b.c" ,
136+ data = '{"title":"안녕 {{ name }}","body":"본문 {{ name }}"}' ,
137+ created_by = system_user ,
138+ updated_by = system_user ,
139+ )
140+ history = _create_history (tpl , context = {"name" : "길동" })
141+ sent_to = history .sent_to_list .get ()
142+ payload = sent_to .payload
143+
144+ # title은 plain text
145+ assert payload ["title" ] == "안녕 길동"
146+ assert not payload ["title" ].strip ().startswith ("<" )
147+
148+ # body는 HTML 렌더링 결과
149+ assert payload ["body" ].strip ().startswith ("<" )
150+ assert "길동" in payload ["body" ]
151+
152+
129153@pytest .mark .django_db
130154def test_history_template_code_property_returns_template_code (email_template ):
131155 history = _create_history (email_template )
You can’t perform that action at this time.
0 commit comments