Spaces:
Running on Zero
Running on Zero
File size: 2,171 Bytes
36333c5 eb808a5 ba7acda eb808a5 ba7acda eb808a5 0287e4e 993f563 ba7acda 993f563 0287e4e 993f563 36333c5 | 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 60 61 62 63 64 65 66 67 68 69 70 | """FastAPI contracts that do not download model weights."""
from pathlib import Path
from fastapi.testclient import TestClient
from app import create_app
from config import Settings
from core.loader import ModelLoader
def make_app(tmp_path: Path):
ModelLoader.reset_instance()
settings = Settings(
output_folder=tmp_path / "output",
tmp_folder=tmp_path / "tmp",
static_folder=tmp_path / "static",
device="cpu",
)
return create_app(settings)
def test_health_does_not_load_a_model(tmp_path: Path) -> None:
application = make_app(tmp_path)
with TestClient(application) as client:
response = client.get("/health")
assert response.status_code == 200
assert response.json()["status"] == "ok"
assert response.json()["active_model"] is None
def test_root_redirects_to_gradio_ui(tmp_path: Path) -> None:
application = make_app(tmp_path)
with TestClient(application) as client:
response = client.get("/?__theme=dark", follow_redirects=False)
direct_response = client.get("/ui", follow_redirects=False)
assert response.status_code == 307
assert response.headers["location"] == "/ui/?__theme=dark"
assert direct_response.status_code == 307
assert direct_response.headers["location"] == "/ui/"
def test_mounted_gradio_ui_runtime_options(tmp_path: Path) -> None:
application = make_app(tmp_path)
mount = next(
route
for route in application.routes
if route.path == "/ui" and hasattr(route.app, "get_blocks")
)
blocks = mount.app.get_blocks()
assert blocks.ssr_mode is False
assert blocks.mcp_server is True
def test_validation_errors_have_stable_shape(tmp_path: Path) -> None:
application = make_app(tmp_path)
with TestClient(application) as client:
response = client.post(
"/api/image",
json={"prompt": "city", "width": 257, "height": 768, "steps": 4, "seed": 1},
)
assert response.status_code == 400
assert response.json()["success"] is False
assert response.json()["code"] == "invalid_dimensions"
assert response.headers["X-Request-ID"]
|