feat: 管理端定时日扩到1至28号,学时顺带写回列表

This commit is contained in:
Nixevol
2026-11-17 22:45:47 +08:00
parent 305d458334
commit 7c498ebaf7
12 changed files with 196 additions and 53 deletions
+18
View File
@@ -804,6 +804,24 @@ def test_admin_can_set_study_start_for_selected_users() -> None:
assert one["study_start"] == "每月20日 00:00:00"
assert two["study_start"] == "每月5日 16:08:09"
assert one["study_start_day"] == 20
edges = client.put(
"/api/admin/users/study-settings",
json={"employee_ids": ["s1-user"], "day": 1, "hour": 0, "minute": 0, "second": 0},
)
assert edges.status_code == 200
late = client.put(
"/api/admin/users/study-settings",
json={"employee_ids": ["s1-user"], "day": 28, "hour": 23, "minute": 59, "second": 59},
)
assert late.status_code == 200
listed = client.get("/api/admin/users").json()
one = next(item for item in listed if item["employee_id"] == "s1-user")
assert one["study_start"] == "每月28日 23:59:59"
rejected = client.put(
"/api/admin/users/study-settings",
json={"employee_ids": ["s1-user"], "day": 29, "hour": 0, "minute": 0, "second": 0},
)
assert rejected.status_code == 400
def test_admin_can_set_course_workers_for_selected_users() -> None:
+14
View File
@@ -743,6 +743,16 @@ def test_user_can_set_monthly_study_start(monkeypatch) -> None:
assert bad.status_code == 400
too_late = client.put("/api/settings/study-start", json={"day": 26, "hour": 16, "minute": 0, "second": 0})
assert too_late.status_code == 400
with SessionLocal() as db:
account = db.get(Account, "6650000146")
assert account is not None
account.study_start_day = 1
db.commit()
kept = client.put("/api/settings/study-start", json={"day": 1, "hour": 7, "minute": 0, "second": 0, "enabled": True})
assert kept.status_code == 200
assert kept.json()["label"] == "每月1日 07:00:00"
changed = client.put("/api/settings/study-start", json={"day": 2, "hour": 7, "minute": 0, "second": 0})
assert changed.status_code == 400
def _freeze_beijing(monkeypatch, year: int, month: int, day: int) -> None:
@@ -1051,6 +1061,10 @@ def test_user_can_read_study_history(monkeypatch) -> None:
assert body["items"][0]["minutes"] == 2
assert body["hours_source"] == "api"
assert body["month_hours"] == "60"
with SessionLocal() as db:
account = db.get(Account, "6650000146")
assert account is not None
assert account.month_hours == "60"
assert body["year_hours"] == "100"
assert body["today_hours"] == 1
assert body["total_hours"] == "10"
+16 -2
View File
@@ -606,8 +606,9 @@ def test_study_window_clamps_day_into_allowed_range() -> None:
assert window_open(account, datetime(2026, 2, 8, 15, 59, 59, tzinfo=CN_TZ)) is False
assert window_open(account, datetime(2026, 2, 8, 16, 0, 0, tzinfo=CN_TZ)) is True
early = _Start(1, 16, 0, 0)
assert window_open(early, datetime(2026, 11, 8, 15, 59, 59, tzinfo=CN_TZ)) is False
assert window_open(early, datetime(2026, 11, 8, 16, 0, 0, tzinfo=CN_TZ)) is True
assert window_open(early, datetime(2026, 11, 1, 15, 59, 59, tzinfo=CN_TZ)) is False
assert window_open(early, datetime(2026, 11, 1, 16, 0, 0, tzinfo=CN_TZ)) is True
assert window_open(early, datetime(2026, 11, 8, 15, 59, 59, tzinfo=CN_TZ)) is True
def test_immediate_start_skips_monthly_window() -> None:
@@ -899,6 +900,19 @@ def test_study_window_rejects_invalid_parts() -> None:
validate_start(8, 24, 0, 0)
assert validate_start(5, 0, 0, 0) == (5, 0, 0, 0)
assert validate_start(25, 23, 59, 59) == (25, 23, 59, 59)
assert validate_start(1, 0, 0, 0, day_min=1, day_max=28) == (1, 0, 0, 0)
assert validate_start(28, 8, 0, 0, day_min=1, day_max=28) == (28, 8, 0, 0)
def test_stored_start_keeps_admin_days_outside_the_user_range() -> None:
from types import SimpleNamespace
from euniv.study_window import stored_start
early = SimpleNamespace(study_start_day=1, study_start_hour=6, study_start_minute=0, study_start_second=0)
late = SimpleNamespace(study_start_day=28, study_start_hour=0, study_start_minute=0, study_start_second=0)
assert stored_start(early) == (1, 6, 0, 0)
assert stored_start(late) == (28, 0, 0, 0)
def test_course_workers_default_and_range() -> None: