36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
from conftest import create_session, join_student
|
|
|
|
|
|
def test_late_join_during_open_gets_reduced_remaining_and_can_score(client, sample_pool):
|
|
sid = create_session(client, sample_pool)
|
|
rooms = client.app.state.rooms
|
|
client.portal.call(rooms.open_question, sid, 0, 2)
|
|
|
|
late = TestClient(client.app)
|
|
with late:
|
|
join_student(late, sid, "late", "Late Student")
|
|
with late.websocket_connect(f"/ws/student/{sid}") as ws:
|
|
assert ws.receive_json()["state"] == "question_open"
|
|
opened = ws.receive_json()
|
|
assert opened["type"] == "question_open"
|
|
assert 0 < opened["remaining_ms"] <= 2000
|
|
ws.send_json({"type": "submit", "question_idx": 0, "answer": "B"})
|
|
assert ws.receive_json()["score"] > 0
|
|
|
|
|
|
def test_join_after_closed_gets_missed_row(client, sample_pool):
|
|
sid = create_session(client, sample_pool)
|
|
rooms = client.app.state.rooms
|
|
client.portal.call(rooms.open_question, sid, 0, 1)
|
|
client.portal.call(rooms.close_question, sid)
|
|
|
|
late = TestClient(client.app)
|
|
with late:
|
|
join_student(late, sid, "late", "Late Student")
|
|
me = late.get(f"/api/session/{sid}/me").json()
|
|
assert me["submissions"][0]["question_idx"] == 0
|
|
assert me["submissions"][0]["status"] == "missed"
|
|
assert me["submissions"][0]["score"] == 0
|