46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
from conftest import create_session, join_student
|
|
|
|
|
|
def test_full_lifecycle_with_three_students(client, sample_pool):
|
|
sid = create_session(client, sample_pool)
|
|
rooms = client.app.state.rooms
|
|
sockets = []
|
|
for idx in range(3):
|
|
join_student(client, sid, f"s{idx}", f"Student {idx}")
|
|
ws = client.websocket_connect(f"/ws/student/{sid}").__enter__()
|
|
sockets.append(ws)
|
|
assert ws.receive_json()["state"] == "lobby"
|
|
|
|
try:
|
|
client.portal.call(rooms.open_question, sid, 0, 2)
|
|
for ws in sockets:
|
|
assert ws.receive_json()["type"] == "question_open"
|
|
for idx, ws in enumerate(sockets):
|
|
ws.send_json({"type": "submit", "question_idx": 0, "answer": "B" if idx < 2 else "A"})
|
|
assert ws.receive_json()["type"] == "submit_ack"
|
|
|
|
client.portal.call(rooms.close_question, sid)
|
|
for ws in sockets:
|
|
assert ws.receive_json()["type"] == "question_closed"
|
|
session = client.portal.call(rooms.get_session, sid)
|
|
assert session["state"] == "question_closed"
|
|
|
|
client.portal.call(rooms.next_question, sid)
|
|
for ws in sockets:
|
|
assert ws.receive_json()["type"] == "between_questions"
|
|
assert client.portal.call(rooms.get_session, sid)["state"] == "between_questions"
|
|
|
|
client.portal.call(rooms.open_question, sid, 1, 2)
|
|
for ws in sockets:
|
|
assert ws.receive_json()["type"] == "question_open"
|
|
client.portal.call(rooms.end_session, sid)
|
|
for ws in sockets:
|
|
message = ws.receive_json()
|
|
assert message["type"] in {"question_closed", "session_ended"}
|
|
if message["type"] == "question_closed":
|
|
assert ws.receive_json()["type"] == "session_ended"
|
|
assert client.portal.call(rooms.get_session, sid)["state"] == "finished"
|
|
finally:
|
|
for ws in locals().get("sockets", []):
|
|
ws.__exit__(None, None, None)
|