Add required test suite and websocket fixes
This commit is contained in:
@@ -1,2 +1,37 @@
|
||||
def test_placeholder_ws_student():
|
||||
assert True
|
||||
import pytest
|
||||
from starlette.websockets import WebSocketDisconnect
|
||||
|
||||
from conftest import create_session, join_student
|
||||
|
||||
|
||||
def test_student_ws_requires_cookie(client, sample_pool):
|
||||
sid = create_session(client, sample_pool)
|
||||
with pytest.raises(WebSocketDisconnect) as exc:
|
||||
with client.websocket_connect(f"/ws/student/{sid}"):
|
||||
pass
|
||||
assert exc.value.code == 4001
|
||||
|
||||
|
||||
def test_student_ws_initial_state_submit_and_closed_reject(client, sample_pool):
|
||||
sid = create_session(client, sample_pool)
|
||||
join_student(client, sid, "s1", "Student One")
|
||||
with client.websocket_connect(f"/ws/student/{sid}") as ws:
|
||||
state = ws.receive_json()
|
||||
assert state["type"] == "state"
|
||||
assert state["state"] == "lobby"
|
||||
|
||||
rooms = client.app.state.rooms
|
||||
client.portal.call(rooms.open_question, sid, 0, 2)
|
||||
opened = ws.receive_json()
|
||||
assert opened["type"] == "question_open"
|
||||
ws.send_json({"type": "submit", "question_idx": 0, "answer": "B"})
|
||||
ack = ws.receive_json()
|
||||
assert ack["type"] == "submit_ack"
|
||||
assert ack["score"] > 0
|
||||
|
||||
client.portal.call(rooms.close_question, sid)
|
||||
closed = ws.receive_json()
|
||||
assert closed["type"] == "question_closed"
|
||||
ws.send_json({"type": "submit", "question_idx": 0, "answer": "B"})
|
||||
error = ws.receive_json()
|
||||
assert error["code"] == "not_open"
|
||||
|
||||
Reference in New Issue
Block a user