Simulation: a bypass to start it on all the test's material when nothing is practiced yet
Browse files- mathly2/realtests.py +3 -2
- mathly2/static/quiz.js +3 -2
- mathly2/static/student.js +8 -4
- mathly2/tests/test_home_browser.py +13 -0
- mathly2/tests/test_realtests_api.py +11 -0
mathly2/realtests.py
CHANGED
|
@@ -339,7 +339,8 @@ def start_exercise(test_id: int, number: int, request: Request, user: dict = Dep
|
|
| 339 |
|
| 340 |
|
| 341 |
@router.post("/tests/{test_id}/simulation/start")
|
| 342 |
-
def start_simulation(test_id: int, request: Request, user: dict = Depends(learner)
|
|
|
|
| 343 |
test = _student_test(request, user, test_id)
|
| 344 |
today = clock.school_day()
|
| 345 |
p = plan_for(test)
|
|
@@ -347,4 +348,4 @@ def start_simulation(test_id: int, request: Request, user: dict = Depends(learne
|
|
| 347 |
if not existing and not countdown.sim_open(( test["date"] - today).days, p):
|
| 348 |
opens = test["date"] - timedelta(days=p["sim"])
|
| 349 |
raise HTTPException(409, f"诪讘讞谉 讛住讬诪讜诇爪讬讛 讬讬驻转讞 讘志{opens.day}.{opens.month}" if today < opens else "诪讘讞谉 讛住讬诪讜诇爪讬讛 谞住讙专")
|
| 350 |
-
return _start(request, user, test, "simulation", str(test_id), 0.0)
|
|
|
|
| 339 |
|
| 340 |
|
| 341 |
@router.post("/tests/{test_id}/simulation/start")
|
| 342 |
+
def start_simulation(test_id: int, request: Request, user: dict = Depends(learner),
|
| 343 |
+
all_skills: bool = Query(False, description="a bypass: every skill of the test's lessons, started or not")) -> dict:
|
| 344 |
test = _student_test(request, user, test_id)
|
| 345 |
today = clock.school_day()
|
| 346 |
p = plan_for(test)
|
|
|
|
| 348 |
if not existing and not countdown.sim_open(( test["date"] - today).days, p):
|
| 349 |
opens = test["date"] - timedelta(days=p["sim"])
|
| 350 |
raise HTTPException(409, f"诪讘讞谉 讛住讬诪讜诇爪讬讛 讬讬驻转讞 讘志{opens.day}.{opens.month}" if today < opens else "诪讘讞谉 讛住讬诪讜诇爪讬讛 谞住讙专")
|
| 351 |
+
return _start(request, user, test, "simulation", str(test_id), 0.0, all_skills)
|
mathly2/static/quiz.js
CHANGED
|
@@ -38,8 +38,9 @@ export async function startExam(testId, number, allSkills = false) {
|
|
| 38 |
location.replace(`#/exam/${encodeURIComponent(testId)}/${encodeURIComponent(number)}/${encodeURIComponent(data.id)}`);
|
| 39 |
}
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
location.replace(`#/sim/${encodeURIComponent(testId)}/${encodeURIComponent(data.id)}`);
|
| 44 |
}
|
| 45 |
|
|
|
|
| 38 |
location.replace(`#/exam/${encodeURIComponent(testId)}/${encodeURIComponent(number)}/${encodeURIComponent(data.id)}`);
|
| 39 |
}
|
| 40 |
|
| 41 |
+
/** `allSkills` (address `#/sim/<test>/all`): the bypass when no skill of the test is started yet, drawn from all the material. */
|
| 42 |
+
export async function startSimulation(testId, allSkills = false) {
|
| 43 |
+
const data = await api(`/api/tests/${encodeURIComponent(testId)}/simulation/start${allSkills ? "?all_skills=true" : ""}`, { method: "POST" });
|
| 44 |
location.replace(`#/sim/${encodeURIComponent(testId)}/${encodeURIComponent(data.id)}`);
|
| 45 |
}
|
| 46 |
|
mathly2/static/student.js
CHANGED
|
@@ -58,12 +58,12 @@ export async function show(me, view) {
|
|
| 58 |
exercise.close();
|
| 59 |
const [kind, ...rest] = where.slice(1).split("/").map(decodeURIComponent);
|
| 60 |
const [test, second, third] = rest;
|
| 61 |
-
const allSkills = kind === "exam"
|
| 62 |
-
const attempt = kind === "exam" ?
|
| 63 |
if (!document.getElementById("path") && !document.getElementById("test-card")) await (await import("./testcard.js")).show(view, test); // a link or a reload: the test's card first
|
| 64 |
if (attempt) await quiz.open(attempt);
|
| 65 |
else if (kind === "exam") await quiz.startExam(test, second, allSkills);
|
| 66 |
-
else await quiz.startSimulation(test);
|
| 67 |
} else if (where.startsWith("/test/")) {
|
| 68 |
exercise.close(); quiz.close();
|
| 69 |
await (await import("./testcard.js")).show(view, decodeURIComponent(where.slice(6)));
|
|
@@ -93,7 +93,11 @@ export async function show(me, view) {
|
|
| 93 |
}
|
| 94 |
} catch (error) {
|
| 95 |
if (error.status === 401) throw error;
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
if (!where.startsWith("/skill/") && !exercise.isOpen()) { /* the path scrolls itself */ }
|
| 99 |
}
|
|
|
|
| 58 |
exercise.close();
|
| 59 |
const [kind, ...rest] = where.slice(1).split("/").map(decodeURIComponent);
|
| 60 |
const [test, second, third] = rest;
|
| 61 |
+
const allSkills = kind === "exam" ? third === "all" : second === "all"; // "/exam/<test>/<n>/all", "/sim/<test>/all": not an attempt id
|
| 62 |
+
const attempt = allSkills ? undefined : kind === "exam" ? third : second;
|
| 63 |
if (!document.getElementById("path") && !document.getElementById("test-card")) await (await import("./testcard.js")).show(view, test); // a link or a reload: the test's card first
|
| 64 |
if (attempt) await quiz.open(attempt);
|
| 65 |
else if (kind === "exam") await quiz.startExam(test, second, allSkills);
|
| 66 |
+
else await quiz.startSimulation(test, allSkills);
|
| 67 |
} else if (where.startsWith("/test/")) {
|
| 68 |
exercise.close(); quiz.close();
|
| 69 |
await (await import("./testcard.js")).show(view, decodeURIComponent(where.slice(6)));
|
|
|
|
| 93 |
}
|
| 94 |
} catch (error) {
|
| 95 |
if (error.status === 401) throw error;
|
| 96 |
+
const sim = where.match(/^\/sim\/([^/]+)$/); // the simulation with nothing started yet: a bypass on all the material
|
| 97 |
+
const bypass = sim && error.status === 409 && /注讜讚 诇讗 讛转讞诇转诐/.test(error.message || "")
|
| 98 |
+
? `<p><a class="button primary" id="sim-bypass" href="#/sim/${sim[1]}/all">诇讛转讞讬诇 讘讻诇 讝讗转, 注诇 讻诇 讛讞讜诪专</a></p>
|
| 99 |
+
<p class="muted">诪讘讞谉 住讬诪讜诇爪讬讛 注讜砖讬诐 驻注诐 讗讞转, 讜讛爪讬讜谉 谞砖诪专.</p>` : "";
|
| 100 |
+
view(`<section class="card"><p class="error" role="alert">${esc(error.message || "诪砖讛讜 讛砖转讘砖")}</p>${bypass}</section>`);
|
| 101 |
}
|
| 102 |
if (!where.startsWith("/skill/") && !exercise.isOpen()) { /* the path scrolls itself */ }
|
| 103 |
}
|
mathly2/tests/test_home_browser.py
CHANGED
|
@@ -361,6 +361,19 @@ def test_the_simulation_before_its_window_says_when_it_opens_and_does_not_start(
|
|
| 361 |
assert store.attempts_of(KID_ID, "simulation") == []
|
| 362 |
|
| 363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
# --- 3.5 the grades screen has exercise tests and simulations ---
|
| 365 |
|
| 366 |
def test_exercise_tests_and_the_simulation_appear_on_the_grades_screen(browser, bank):
|
|
|
|
| 361 |
assert store.attempts_of(KID_ID, "simulation") == []
|
| 362 |
|
| 363 |
|
| 364 |
+
def test_the_simulation_with_nothing_practiced_offers_a_bypass_on_all_the_material(browser, bank):
|
| 365 |
+
app, store, klass, lessons = world(bank)
|
| 366 |
+
test = add_test(store, klass, lessons, 2, questions=6, minutes=45) # two days left, nothing started
|
| 367 |
+
with running(app) as url:
|
| 368 |
+
page = sign_in(browser, url, f"#/sim/{test['id']}")
|
| 369 |
+
page.wait_for_selector("#sim-bypass")
|
| 370 |
+
assert "注讜讚 诇讗 讛转讞诇转诐" in page.inner_text("[role=alert]") and store.attempts_of(KID_ID, "simulation") == []
|
| 371 |
+
page.click("#sim-bypass")
|
| 372 |
+
page.wait_for_selector("#qz-q")
|
| 373 |
+
assert "诪讘讞谉 住讬诪讜诇爪讬讛" in page.inner_text(".mx-sheet") and page.locator(".qz-dot").count() == 6
|
| 374 |
+
assert len(store.attempts_of(KID_ID, "simulation")) == 1
|
| 375 |
+
|
| 376 |
+
|
| 377 |
# --- 3.5 the grades screen has exercise tests and simulations ---
|
| 378 |
|
| 379 |
def test_exercise_tests_and_the_simulation_appear_on_the_grades_screen(browser, bank):
|
mathly2/tests/test_realtests_api.py
CHANGED
|
@@ -363,6 +363,17 @@ def test_the_simulation_is_refused_8_days_before_with_its_opening_date(world):
|
|
| 363 |
assert store.attempts_of(uid(KID), "simulation") == [] # nothing was started
|
| 364 |
|
| 365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
def test_the_simulation_has_the_tests_length_can_be_taken_once_and_shows_its_result_again(world):
|
| 367 |
client, store, lessons = world
|
| 368 |
test = set_test(client, lessons, days=14).json() # 12 questions, 45 minutes
|
|
|
|
| 363 |
assert store.attempts_of(uid(KID), "simulation") == [] # nothing was started
|
| 364 |
|
| 365 |
|
| 366 |
+
def test_the_simulation_with_nothing_started_is_refused_and_all_skills_is_the_bypass(world):
|
| 367 |
+
client, store, lessons = world
|
| 368 |
+
test = set_test(client, lessons, days=14).json()
|
| 369 |
+
client.set_time(MON + 12 * DAY) # two days left: open, and nothing practiced
|
| 370 |
+
refused = start_sim(client, test["id"])
|
| 371 |
+
assert refused.status_code == 409 and "注讜讚 诇讗 讛转讞诇转诐" in refused.json()["detail"]
|
| 372 |
+
got = client.post(f"/api/tests/{test['id']}/simulation/start?all_skills=true", headers=auth(KID))
|
| 373 |
+
assert got.status_code == 200 and got.json()["kind"] == "simulation" and len(got.json()["questions"]) == 12
|
| 374 |
+
assert start_sim(client, test["id"]).json()["id"] == got.json()["id"] # then it resumes like any simulation
|
| 375 |
+
|
| 376 |
+
|
| 377 |
def test_the_simulation_has_the_tests_length_can_be_taken_once_and_shows_its_result_again(world):
|
| 378 |
client, store, lessons = world
|
| 379 |
test = set_test(client, lessons, days=14).json() # 12 questions, 45 minutes
|