feat: 每门课用独立会话学习,间隔改动即时生效,间隔为 0 时不显示倒计时

This commit is contained in:
2026-11-17 17:06:19 +08:00
parent e98cc13061
commit 42b29fb4d6
6 changed files with 424 additions and 53 deletions
+35
View File
@@ -694,6 +694,9 @@ def test_heartbeat_interval_belongs_to_the_user(monkeypatch) -> None:
assert omitted.json()["heartbeat_video_seconds"] == 1
current = client.get("/api/settings/heartbeat")
assert current.json()["heartbeat_mode"] == "manual"
from euniv.autostudy import _pace_of
assert _pace_of("6650000146") == ({"video": 1, "document": 2, "scorm": 3}, False)
intervals, auto = _current_intervals("6650000146")
assert auto is False
assert intervals == {"video": 1, "document": 2, "scorm": 3}
@@ -882,6 +885,38 @@ def test_start_saves_the_settings_sent_with_it(monkeypatch) -> None:
assert work_running("6650000146") is False
def test_changing_the_course_count_restarts_a_running_study(monkeypatch) -> None:
import euniv.api as api_module
import euniv.autostudy as autostudy_module
import euniv.service as service_module
monkeypatch.setattr(
api_module,
"login_and_store",
lambda db, employee_id, password, manual=False, auto_attempts=3: service_module.login_and_store(
db, employee_id, password, FakeClient, manual=manual, auto_attempts=auto_attempts
),
)
restarted: list[str] = []
original = autostudy_module.restart_work
def record(employee_id: str) -> None:
restarted.append(employee_id)
original(employee_id)
monkeypatch.setattr(autostudy_module, "restart_work", record)
client = TestClient(api_module.app)
_freeze_beijing(monkeypatch, 2026, 11, 15)
assert client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"}).status_code == 200
started = client.post("/api/settings/study-control", json={"action": "start", "settings": _study_body(workers=2)})
assert started.status_code == 200
assert client.put("/api/settings/study", json=_study_body(workers=2, monthly_target=700)).status_code == 200
assert restarted == []
assert client.put("/api/settings/study", json=_study_body(workers=3, monthly_target=700)).status_code == 200
assert restarted == ["6650000146"]
assert autostudy_module.work_running("6650000146") is True
def test_study_control_stays_stopped_when_month_hours_met(monkeypatch) -> None:
import euniv.api as api_module
import euniv.service as service_module