Files
pk-lab-server/tests/test_api.py
T
codex-bot 4d79c82695
Verify and deploy API / verify-deploy (push) Failing after 1m3s
feat: launch PK testing application
2026-09-18 21:50:25 +08:00

47 lines
1.6 KiB
Python

from fastapi.testclient import TestClient
from pk_lab_server.main import app
def test_health_and_seeded_tests():
with TestClient(app) as client:
assert client.get("/health").json() == {"status": "ok"}
tests = client.get("/api/v1/tests").json()
assert len(tests) == 7
rice = next(item for item in tests if item["slug"] == "rice")
assert rice["candidate_count"] == 48
def test_login_complete_and_read_result():
with TestClient(app) as client:
login = client.post(
"/api/v1/auth/xhs", json={"app_key": "rice", "code": "dev:user-one"}
)
assert login.status_code == 200
token = login.json()["token"]
headers = {"Authorization": f"Bearer {token}"}
detail = client.get("/api/v1/tests/rice").json()
left, right = detail["candidates"][:2]
created = client.post(
"/api/v1/tests/rice/runs",
headers=headers,
json={
"app_key": "rice",
"champion_id": left["id"],
"runner_up_id": right["id"],
"ranking_ids": [left["id"], right["id"]],
"decisions": [
{
"round": 1,
"left_id": left["id"],
"right_id": right["id"],
"winner_id": left["id"],
}
],
},
)
assert created.status_code == 201, created.text
history = client.get("/api/v1/me/results?test_slug=rice", headers=headers).json()
assert history[0]["champion_name"] == "蛋炒饭"