35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""Smoke test for the application factory."""
|
|
|
|
from unittest.mock import AsyncMock, Mock
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.config import Settings
|
|
from app.main import create_app
|
|
|
|
|
|
def test_health_reports_mode() -> None:
|
|
client = TestClient(create_app())
|
|
response = client.get("/api/health")
|
|
assert response.status_code == 200
|
|
assert response.json()["mode"] in ("live", "demo")
|
|
|
|
|
|
def test_anthropic_client_uses_configured_timeout(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
anthropic_client = Mock()
|
|
anthropic_client.close = AsyncMock()
|
|
constructor = Mock(return_value=anthropic_client)
|
|
monkeypatch.setattr("app.main.AsyncAnthropic", constructor)
|
|
|
|
live_settings = Settings(
|
|
app_mode="live",
|
|
spotify_client_id="client-id",
|
|
anthropic_api_key="api-key",
|
|
llm_timeout_seconds=42.0,
|
|
)
|
|
with TestClient(create_app(live_settings)) as client:
|
|
response = client.get("/api/health")
|
|
|
|
assert response.status_code == 200
|
|
constructor.assert_called_once_with(api_key="api-key", timeout=42.0, http_client=None)
|