feat: wire SendGridEmailBackend with from_email/reply_to settings

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-08 12:12:05 -07:00
co-authored by Claude Sonnet 4.6
parent 63ad306a61
commit 5a41402644
3 changed files with 63 additions and 8 deletions
+40
View File
@@ -0,0 +1,40 @@
"""Unit tests for SendGridEmailBackend — no Postgres needed."""
import pytest
def test_sendgrid_send_calls_api(monkeypatch):
calls = []
class FakeResponse:
status_code = 202
body = b""
class FakeClient:
def send(self, msg):
calls.append(msg)
return FakeResponse()
monkeypatch.setattr("app.services.email.SendGridAPIClient", lambda _key: FakeClient())
from app.services.email import SendGridEmailBackend
backend = SendGridEmailBackend()
backend.send(to="to@example.com", subject="Hello", html="<p>Hi</p>")
assert len(calls) == 1
def test_sendgrid_raises_on_4xx(monkeypatch):
class FakeResponse:
status_code = 400
body = b"bad request"
class FakeClient:
def send(self, msg):
return FakeResponse()
monkeypatch.setattr("app.services.email.SendGridAPIClient", lambda _key: FakeClient())
from app.services.email import SendGridEmailBackend
backend = SendGridEmailBackend()
with pytest.raises(RuntimeError, match="400"):
backend.send(to="to@example.com", subject="Hello", html="<p>Hi</p>")