"""Shared fixtures, and one guarantee. The autouse fixture below is the important part: a suite for a service whose entire job is sending messages to real people must not be able to send one. Anything that reaches for a socket fails loudly instead of quietly costing money or waking someone up. """ from __future__ import annotations import urllib.request import pytest from fastapi.testclient import TestClient from app.config import Settings from app.main import create_app TOKEN = "test-token" @pytest.fixture(autouse=True) def no_network(monkeypatch: pytest.MonkeyPatch) -> None: def refuse(*args, **kwargs): raise AssertionError("a test tried to reach the network") monkeypatch.setattr(urllib.request, "urlopen", refuse) @pytest.fixture def settings() -> Settings: return Settings( token=TOKEN, sendgrid_key="sg-key", email_from="no-reply@example.test", twilio_sid="AC123", twilio_token="twilio-secret", twilio_from="+15550001111", timeout=1.0, ) @pytest.fixture def client(settings: Settings) -> TestClient: return TestClient(create_app(settings)) @pytest.fixture def auth() -> dict[str, str]: return {"Authorization": f"Bearer {TOKEN}"}