This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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"] == "蛋炒饭"
|
||||
|
||||
Reference in New Issue
Block a user