Files
fn_registry/python/functions/infra/email_build_html_test.py
T
egutierrez be081c68f2 feat: funciones email SMTP en Python (infra)
smtp_send: conecta+envia+cierra en un paso via smtplib (TLS/STARTTLS/plain).
email_build_html: construye EmailMessagePy frozen dataclass con cuerpo HTML.
Solo stdlib Python: smtplib, email.mime. Tests con mock SMTP server threading.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 02:03:12 +02:00

45 lines
1.3 KiB
Python

"""Tests para email_build_html."""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from infra.email_build_html import email_build_html, EmailMessagePy
def test_construye_mensaje_html_con_campos_correctos():
msg = email_build_html(
from_addr="alice@example.com",
to=["bob@example.com"],
subject="Hola",
body_html="<b>Hola Bob</b>",
)
assert msg.from_addr == "alice@example.com"
assert msg.subject == "Hola"
assert msg.body_html == "<b>Hola Bob</b>"
assert "bob@example.com" in msg.to
def test_convierte_lista_to_a_tupla_inmutable():
to_list = ["a@example.com", "b@example.com"]
msg = email_build_html("f@x.com", to_list, "s", "h")
assert isinstance(msg.to, tuple)
# Mutating the original list must not affect the message
to_list[0] = "mutated@example.com"
assert msg.to[0] == "a@example.com"
def test_body_text_queda_vacio():
msg = email_build_html("f@x.com", ["t@x.com"], "s", "<p>html</p>")
assert msg.body_text == ""
def test_mensaje_es_inmutable():
msg = email_build_html("f@x.com", ["t@x.com"], "s", "h")
try:
msg.subject = "changed"
assert False, "Should have raised FrozenInstanceError"
except Exception:
pass # frozen dataclass raises FrozenInstanceError