feat: 心跳间隔改由每个用户自己设置
This commit is contained in:
@@ -167,6 +167,10 @@ def test_login_stores_password_and_credential_only(monkeypatch) -> None:
|
||||
"study_stop_month",
|
||||
"study_ignore_window",
|
||||
"study_schedule_enabled",
|
||||
"heartbeat_mode",
|
||||
"heartbeat_video_seconds",
|
||||
"heartbeat_document_seconds",
|
||||
"heartbeat_scorm_seconds",
|
||||
"sessions_valid_after",
|
||||
"password_login_at",
|
||||
}
|
||||
@@ -638,6 +642,71 @@ def test_user_can_set_course_workers(monkeypatch) -> None:
|
||||
assert bad.status_code == 400
|
||||
|
||||
|
||||
def _study_body(**extra: object) -> dict:
|
||||
body = {
|
||||
"monthly_target": 600,
|
||||
"day": 8,
|
||||
"hour": 0,
|
||||
"minute": 0,
|
||||
"second": 0,
|
||||
"enabled": True,
|
||||
"workers": 1,
|
||||
}
|
||||
body.update(extra)
|
||||
return body
|
||||
|
||||
|
||||
def test_heartbeat_interval_belongs_to_the_user(monkeypatch) -> None:
|
||||
import euniv.api as api_module
|
||||
import euniv.service as service_module
|
||||
from euniv.autostudy import _current_intervals
|
||||
|
||||
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
|
||||
),
|
||||
)
|
||||
client = TestClient(api_module.app)
|
||||
assert client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"}).status_code == 200
|
||||
initial = client.get("/api/settings/heartbeat")
|
||||
assert initial.status_code == 200
|
||||
assert initial.json()["heartbeat_mode"] == "auto"
|
||||
assert initial.json()["heartbeat_video_seconds"] == 30
|
||||
kept = client.put("/api/settings/study", json=_study_body())
|
||||
assert kept.status_code == 200
|
||||
assert kept.json()["heartbeat_mode"] == "auto"
|
||||
manual = client.put("/api/settings/study", json=_study_body(
|
||||
heartbeat_mode="manual",
|
||||
heartbeat_video_seconds=1,
|
||||
heartbeat_document_seconds=2,
|
||||
heartbeat_scorm_seconds=3,
|
||||
))
|
||||
assert manual.status_code == 200
|
||||
assert manual.json()["heartbeat_video_seconds"] == 1
|
||||
assert manual.json()["heartbeat_document_seconds"] == 2
|
||||
assert manual.json()["heartbeat_scorm_seconds"] == 3
|
||||
omitted = client.put("/api/settings/study", json=_study_body(workers=2))
|
||||
assert omitted.status_code == 200
|
||||
assert omitted.json()["workers"] == 2
|
||||
assert omitted.json()["heartbeat_mode"] == "manual"
|
||||
assert omitted.json()["heartbeat_video_seconds"] == 1
|
||||
current = client.get("/api/settings/heartbeat")
|
||||
assert current.json()["heartbeat_mode"] == "manual"
|
||||
intervals, auto = _current_intervals("6650000146")
|
||||
assert auto is False
|
||||
assert intervals == {"video": 1, "document": 2, "scorm": 3}
|
||||
fallback, fallback_auto = _current_intervals("nobody")
|
||||
assert fallback_auto is True
|
||||
assert fallback == {"video": 30, "document": 120, "scorm": 120}
|
||||
rejected = client.put("/api/settings/study", json=_study_body(heartbeat_mode="fast"))
|
||||
assert rejected.status_code == 400
|
||||
too_fast = client.put("/api/settings/study", json=_study_body(heartbeat_video_seconds=301))
|
||||
assert too_fast.status_code == 400
|
||||
assert too_fast.json()["detail"] == "视频心跳间隔须为 0 到 300 的整数"
|
||||
|
||||
|
||||
def test_user_can_set_monthly_study_start(monkeypatch) -> None:
|
||||
import euniv.api as api_module
|
||||
import euniv.service as service_module
|
||||
|
||||
Reference in New Issue
Block a user