feat: add unified contest pool and realtime game modes
This commit is contained in:
@@ -203,3 +203,54 @@ def test_challenge_api_已使用联机码返回具体原因(realtime_api_setup):
|
||||
|
||||
assert response.status_code == 400
|
||||
assert response.json()["error"]["message"] == "联机码已失效或已被使用"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_challenge_api_24点竞速完整闭环(realtime_api_setup):
|
||||
contest, first_client, second_client = realtime_api_setup
|
||||
created = first_client.post(
|
||||
f"/api/v1/contests/{contest.slug}/challenges/",
|
||||
{"game_kind": "twenty_four"},
|
||||
content_type="application/json",
|
||||
)
|
||||
joined = second_client.post(
|
||||
"/api/v1/contests/challenges/join/",
|
||||
{"challenge_code": created.json()["challenge_code"]},
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
assert joined.status_code == 200
|
||||
assert joined.json()["game_kind"] == "twenty_four"
|
||||
assert created.json()["attempt"] is None
|
||||
first_state = first_client.get(
|
||||
f"/api/v1/contests/matches/{joined.json()['match_id']}/"
|
||||
).json()
|
||||
assert first_state["attempt"]["puzzle"] == joined.json()["attempt"]["puzzle"]
|
||||
|
||||
solutions = {
|
||||
(2, 3, 4, 9): "(2/3)*4*9",
|
||||
(3, 5, 7, 13): "(7+5*13)/3",
|
||||
(4, 7, 8, 8): "8*(4+7-8)",
|
||||
}
|
||||
expression = solutions[
|
||||
tuple(sorted(joined.json()["attempt"]["puzzle"]["numbers"]))
|
||||
]
|
||||
first_submit = first_client.post(
|
||||
f"/api/v1/contests/games/attempts/{first_state['attempt']['attempt_id']}/submit/",
|
||||
{"expression": expression},
|
||||
content_type="application/json",
|
||||
HTTP_IDEMPOTENCY_KEY="api-game-first",
|
||||
)
|
||||
second_submit = second_client.post(
|
||||
f"/api/v1/contests/games/attempts/{joined.json()['attempt']['attempt_id']}/submit/",
|
||||
{"expression": expression},
|
||||
content_type="application/json",
|
||||
HTTP_IDEMPOTENCY_KEY="api-game-second",
|
||||
)
|
||||
|
||||
assert first_submit.status_code == 200
|
||||
assert first_submit.json()["status"] == "active"
|
||||
assert first_submit.json()["attempt"]["status"] == "completed"
|
||||
assert second_submit.status_code == 200
|
||||
assert second_submit.json()["status"] == "completed"
|
||||
assert second_submit.json()["result"]["winner"] in {"self", "opponent", "draw"}
|
||||
|
||||
Reference in New Issue
Block a user