agentic.email/backend/tests/test_mail_sender.py
2026-10-05 21:34:12 +05:30

43 lines
1.2 KiB
Python

from types import SimpleNamespace
from unittest.mock import AsyncMock, patch
from app.services.mail_sender import build_message, send_via_smtp, sign_message
def test_dkim_sign_uses_selector_before_domain():
message = build_message(
sender="user@ritoesis.com",
recipients=["recipient@example.com"],
cc=[],
subject="Test",
body_text="Hello",
body_html=None,
)
domain = SimpleNamespace(
domain_name="ritoesis.com",
dkim_selector="agmail",
dkim_private_key="private-key",
)
with patch(
"app.services.mail_sender.dkim.sign",
return_value=b"DKIM-Signature: test\r\n",
) as signer:
sign_message(message, domain)
assert signer.call_args.args[1] == b"agmail"
assert signer.call_args.args[2] == b"ritoesis.com"
async def test_send_via_smtp_uses_configured_client_hostname():
with patch(
"app.services.mail_sender.aiosmtplib.send",
new_callable=AsyncMock,
) as send_mock:
await send_via_smtp(
b"raw",
sender="noreply@gentic.email",
recipients=["user@example.com"],
)
assert send_mock.await_args.kwargs["local_hostname"] == "backend.gentic.email"