feat: add collaborative math board and draw guess mode

This commit is contained in:
2026-08-10 00:47:03 +08:00
parent 40e9462842
commit b8916180a9
16 changed files with 890 additions and 36 deletions
+54
View File
@@ -1,5 +1,8 @@
import pytest
from accounts.models import User
from toolbox.models import BoardSession
@pytest.mark.django_db
def test_calculator_api_公开访问并返回精确值(client):
@@ -23,3 +26,54 @@ def test_calculator_api_危险表达式返回四百(client):
assert response.status_code == 400
assert "error" in response.json()
@pytest.mark.django_db
def test_board_api_联机码加入你画我猜并服务端计分(client):
host = User.objects.create_user(
username="board_host",
password="StrongPass_2026",
nickname="画板房主",
)
guest = User.objects.create_user(
username="board_guest",
password="StrongPass_2026",
nickname="猜题玩家",
)
client.force_login(host)
created = client.post(
"/api/v1/toolbox/boards/",
{"mode": "draw_guess"},
content_type="application/json",
)
target = created.json()["target"]
code = created.json()["code"]
session_id = created.json()["session_id"]
client.force_login(guest)
joined = client.post(
"/api/v1/toolbox/boards/join/",
{"code": code.lower()},
content_type="application/json",
)
wrong = client.post(
f"/api/v1/toolbox/boards/{session_id}/guess/",
{"guess": "不是答案"},
content_type="application/json",
)
correct = client.post(
f"/api/v1/toolbox/boards/{session_id}/guess/",
{"guess": target},
content_type="application/json",
)
assert created.status_code == 201
assert created.json()["role"] == "host"
assert target
assert joined.status_code == 200
assert joined.json()["target"] is None
assert joined.json()["status"] == BoardSession.Status.ACTIVE
assert wrong.json()["correct"] is False
assert correct.json()["correct"] is True
assert correct.json()["guest_score"] == 1
assert correct.json()["status"] == BoardSession.Status.COMPLETED