human hand off
This commit is contained in:
parent
d0fee5c8f7
commit
7af776196a
34 changed files with 2941 additions and 195 deletions
|
|
@ -1,7 +1,49 @@
|
|||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from app.services.mail_sender import build_message, send_via_smtp, sign_message
|
||||
import pytest
|
||||
|
||||
from app.services.mail_sender import build_message, deliver_email, send_via_smtp, sign_message
|
||||
|
||||
|
||||
def test_build_message_formats_named_sender_header():
|
||||
message = build_message(
|
||||
sender="suyash@gentic.email",
|
||||
sender_name="Suyash Dixit",
|
||||
recipients=["recipient@example.com"],
|
||||
cc=[],
|
||||
subject="Named sender",
|
||||
body_text="Hello",
|
||||
body_html=None,
|
||||
)
|
||||
|
||||
assert message["From"] == "Suyash Dixit <suyash@gentic.email>"
|
||||
|
||||
|
||||
def test_build_message_preserves_preformatted_transactional_sender():
|
||||
message = build_message(
|
||||
sender="aGentic Email <notifications@gentic.email>",
|
||||
recipients=["recipient@example.com"],
|
||||
cc=[],
|
||||
subject="Welcome",
|
||||
body_text="Hello",
|
||||
body_html=None,
|
||||
)
|
||||
|
||||
assert message["From"] == "aGentic Email <notifications@gentic.email>"
|
||||
|
||||
|
||||
def test_build_message_adds_safe_fallback_sender_name():
|
||||
message = build_message(
|
||||
sender="notifications@gentic.email",
|
||||
recipients=["recipient@example.com"],
|
||||
cc=[],
|
||||
subject="Notification",
|
||||
body_text="Hello",
|
||||
body_html=None,
|
||||
)
|
||||
|
||||
assert message["From"] == "aGentic Email <notifications@gentic.email>"
|
||||
|
||||
|
||||
def test_dkim_sign_uses_selector_before_domain():
|
||||
|
|
@ -29,6 +71,7 @@ def test_dkim_sign_uses_selector_before_domain():
|
|||
assert signer.call_args.args[2] == b"ritoesis.com"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_via_smtp_uses_configured_client_hostname():
|
||||
with patch(
|
||||
"app.services.mail_sender.aiosmtplib.send",
|
||||
|
|
@ -43,6 +86,38 @@ async def test_send_via_smtp_uses_configured_client_hostname():
|
|||
assert send_mock.await_args.kwargs["local_hostname"] == "backend.gentic.email"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_deliver_email_uses_bare_address_for_smtp_envelope():
|
||||
domain = SimpleNamespace(
|
||||
domain_name="gentic.email",
|
||||
dkim_selector="agmail",
|
||||
dkim_private_key="private-key",
|
||||
)
|
||||
with (
|
||||
patch(
|
||||
"app.services.mail_sender.sign_message",
|
||||
return_value=b"signed",
|
||||
),
|
||||
patch(
|
||||
"app.services.mail_sender.send_via_smtp",
|
||||
new_callable=AsyncMock,
|
||||
) as send_mock,
|
||||
):
|
||||
await deliver_email(
|
||||
sender="notifications@gentic.email",
|
||||
sender_name="aGentic Email",
|
||||
recipients=["user@example.com"],
|
||||
cc=[],
|
||||
bcc=[],
|
||||
subject="Welcome",
|
||||
body_text="Hello",
|
||||
body_html=None,
|
||||
domain=domain,
|
||||
)
|
||||
|
||||
assert send_mock.await_args.kwargs["sender"] == "notifications@gentic.email"
|
||||
|
||||
|
||||
def test_build_message_sets_in_reply_to_and_references():
|
||||
message = build_message(
|
||||
sender="suyash@gentic.email",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue