"""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="Hola Bob", ) assert msg.from_addr == "alice@example.com" assert msg.subject == "Hola" assert msg.body_html == "Hola Bob" 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", "

html

") 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