feat: add collaborative math board and draw guess mode
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user