Public Access
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:
@@ -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>")
|
||||
Reference in New Issue
Block a user