spelunkai/labeling/backend/tests/test_frames.py
Jonas 4c9deda66a Implement labeling backend: FastAPI + SQLAlchemy data model and CRUD API
Add the core labeling data model (label sets, ad-hoc Main->Sub class
hierarchy, frames, bounding-box labels, per-frame/per-set label
status) behind a FastAPI app, with SQLite as the default swappable
DATABASE_URL. Multi-user support is attribution-only for now
(get-or-create by username, no login flow yet). Dataset
versioning/promotion is intentionally deferred - it needs its own
design pass around snapshot semantics.

Each test gets a fully isolated app+DB via create_app(database_url=...)
rather than relying on process-global state. 13/13 tests pass; also
verified live end-to-end against a running uvicorn instance.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-16 11:24:57 +02:00

33 lines
1.1 KiB
Python

def test_create_and_list_frames(client):
payload = {
"session_name": "run01",
"frame_index": 0,
"image_path": "run01_frames/frame_000000.png",
"width": 1280,
"height": 720,
}
resp = client.post("/frames", json=payload)
assert resp.status_code == 201
frame_id = resp.json()["id"]
resp = client.post("/frames", json=payload)
assert resp.status_code == 201
assert resp.json()["id"] == frame_id
resp = client.get("/frames", params={"session_name": "run01"})
assert resp.status_code == 200
assert len(resp.json()) == 1
def test_list_frames_filters_by_session(client):
client.post("/frames", json={"session_name": "run01", "frame_index": 0, "image_path": "a.png", "width": 1, "height": 1})
client.post("/frames", json={"session_name": "run02", "frame_index": 0, "image_path": "b.png", "width": 1, "height": 1})
resp = client.get("/frames", params={"session_name": "run02"})
assert [f["image_path"] for f in resp.json()] == ["b.png"]
def test_get_missing_frame(client):
resp = client.get("/frames/999")
assert resp.status_code == 404