"""
Tests for the email reminder template consistency fixes:
- Part D: NotificationService.send_email auto-wraps plain-text in branded template
- Part A: dept-champion notification uses email= (not recipient=) kwarg
- Part B/C: branded reminder templates render with the expected context
"""
from unittest.mock import patch
from django.template.loader import render_to_string
from django.test import TestCase
from apps.notifications.services import NotificationService
class AutoWrapBrandedTemplateTests(TestCase):
"""Part D — plain-text messages are auto-wrapped in the branded template."""
@patch("apps.notifications.services.send_mail")
def test_plain_text_gets_branded_html(self, mock_send_mail):
NotificationService.send_email(
email="patient@example.com",
subject="Test Subject",
message="Line one.\n\nLine two.\nLine three.",
)
# send_mail was called with an html_message
_, kwargs = mock_send_mail.call_args
self.assertIsNotNone(kwargs.get("html_message"))
html = kwargs["html_message"]
# The branded template contributes these structural markers
self.assertIn("email-container", html) # the 600px card from base_email_template
self.assertIn("", html) # single newline ->
self.assertIn("
", html) # double newline -> new paragraph @patch("apps.notifications.services.send_mail") def test_explicit_html_message_is_not_overwritten(self, mock_send_mail): """Callers that already provide html_message keep it as-is (no double-wrapping).""" custom_html = "