File size: 978 Bytes
6d20eab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_get_risk():
"""Endpoint returns 501 with a deprecation message."""
response = client.get(
"/api/v1/get_risk",
headers={
"X-API-Key": "test-key"})
assert response.status_code == 501
data = response.json()
assert "deprecated" in data.get("detail", "").lower()
def test_get_risk_internal_error(client, monkeypatch):
"""Force an internal error – the endpoint should return 500."""
import app.api.routes_risk
def mock_get_system_risk():
raise ValueError("test error")
monkeypatch.setattr(
app.api.routes_risk,
"get_system_risk",
mock_get_system_risk)
response = client.get(
"/api/v1/get_risk",
headers={
"X-API-Key": "test-key"})
assert response.status_code == 500
data = response.json()
assert "test error" in data.get("detail", "")
|