Spaces:
Sleeping
Sleeping
Download code/tests/test_api.py from acra-thesis/acra-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/acra-thesis/acra-backend/resolve/main/code/tests/test_api.py
- Command line
-
hf download hf://spaces/acra-thesis/acra-backend/code/tests/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/acra-thesis/acra-backend/resolve/main/code/tests/test_api.py
1.42 kB
| import io | |
| import pytest | |
| fastapi = pytest.importorskip("fastapi") | |
| from fastapi.testclient import TestClient | |
| from PIL import Image | |
| 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"] | |