46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
from app import app
|
|
|
|
|
|
def test_health() -> None:
|
|
client = TestClient(app)
|
|
response = client.get("/health")
|
|
assert response.status_code == 200
|
|
assert response.json() == {"status": "ok"}
|
|
|
|
|
|
def test_rejects_unsupported_type() -> None:
|
|
client = TestClient(app)
|
|
response = client.post(
|
|
"/gemini",
|
|
files={"image": ("input.txt", b"not-an-image", "text/plain")},
|
|
data={"prompt": "test", "generation_config": "{}"},
|
|
)
|
|
assert response.status_code == 415
|
|
|
|
|
|
def test_missing_key_returns_service_unavailable(monkeypatch) -> None:
|
|
monkeypatch.delenv("GEMINI_API_KEY", raising=False)
|
|
client = TestClient(app)
|
|
response = client.post(
|
|
"/gemini",
|
|
files={"image": ("input.png", b"not-an-image", "image/png")},
|
|
data={"prompt": "test", "generation_config": "{}"},
|
|
)
|
|
assert response.status_code == 503
|
|
|
|
|
|
def test_rejects_when_only_override_provided(monkeypatch) -> None:
|
|
monkeypatch.delenv("GEMINI_API_KEY", raising=False)
|
|
client = TestClient(app)
|
|
response = client.post(
|
|
"/gemini",
|
|
files={"image": ("input.png", b"not-an-image", "image/png")},
|
|
data={
|
|
"prompt": "test",
|
|
"generation_config": "{}",
|
|
"api_key_override": "manual-key",
|
|
},
|
|
)
|
|
assert response.status_code == 503 |