Backend API: auth, projects/images/annotations, R2 presign, tracing, thumbnails, pagination, tests, docs
This commit is contained in:
parent
5c5deed2f5
commit
f8ed08b854
49 changed files with 2626 additions and 0 deletions
42
tests/test_tracing.py
Normal file
42
tests/test_tracing.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""Trace layer: session echo, trace minting, client-event ingest."""
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from src.main import app
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client():
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
|
||||
def test_trace_headers_echo_session(client):
|
||||
r = client.get("/", headers={"X-Session-ID": "sess-1", "X-User-Id": "u1"})
|
||||
assert r.status_code == 200
|
||||
assert r.headers["X-Session-ID"] == "sess-1"
|
||||
assert len(r.headers["X-Trace-ID"]) == 16
|
||||
|
||||
|
||||
def test_trace_headers_mint_session_when_missing(client):
|
||||
r = client.get("/")
|
||||
assert r.status_code == 200
|
||||
assert r.headers["X-Session-ID"]
|
||||
assert r.headers["X-Trace-ID"]
|
||||
|
||||
|
||||
def test_events_reject_missing_session(client):
|
||||
r = client.post("/api/v1/events", json={"session_id": " ", "events": []})
|
||||
assert r.status_code in (400, 422)
|
||||
|
||||
|
||||
def test_events_accept_batch(client):
|
||||
sid = f"sess-{uuid.uuid4().hex[:8]}"
|
||||
r = client.post("/api/v1/events", json={
|
||||
"session_id": sid,
|
||||
"events": [{"action": "image.next", "project_id": "p1", "payload": {"dir": 1}}],
|
||||
})
|
||||
assert r.status_code == 202
|
||||
assert r.json() == {"accepted": 1}
|
||||
Loading…
Add table
Add a link
Reference in a new issue