Spaces:
Sleeping
Sleeping
File size: 1,421 Bytes
78661be | 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import io
import pytest
fastapi = pytest.importorskip("fastapi")
from fastapi.testclient import TestClient
from PIL import Image
@pytest.fixture(scope="module")
def client():
from main import app
with TestClient(app) as test_client:
yield test_client
def _png_bytes(size=(16, 16), color=(255, 0, 0)):
buf = io.BytesIO()
Image.new("RGB", size, color).save(buf, format="PNG")
buf.seek(0)
return buf
def _png_bytes(size=(16, 16), color=(255, 0, 0)):
buf = io.BytesIO()
Image.new("RGB", size, color).save(buf, format="PNG")
buf.seek(0)
return buf
def test_health(client):
response = client.get("/health")
assert response.status_code == 200
body = response.json()
assert body["status"] == "ok"
assert "model_loaded" in body
def test_process_rejects_missing_image(client):
response = client.post("/process", data={
"cvd_type": "deutan",
"severity": "0.8",
"conf_threshold": "0.3",
})
assert response.status_code == 422
def test_process_rejects_invalid_cvd_type(client):
response = client.post(
"/process",
data={
"cvd_type": "tritan",
"severity": "0.8",
"conf_threshold": "0.3",
},
files={"image": ("swatch.png", _png_bytes(), "image/png")},
)
assert response.status_code == 400
assert "cvd_type" in response.json()["detail"]
|