feat: 增加公告栏并让用户自选学时判断

This commit is contained in:
Nixevol
2026-11-19 04:08:30 +08:00
parent 3fe6d4c111
commit 4d4fe224bc
20 changed files with 789 additions and 64 deletions
+34
View File
@@ -996,3 +996,37 @@ def test_admin_can_switch_hours_source() -> None:
bad = client.put("/api/admin/settings", json=_settings_body(hours_source="other"))
assert bad.status_code == 400
assert bad.json()["detail"] == "学时达标依据须为 api 或 history"
def test_admin_can_publish_notices() -> None:
api = _app()
client = TestClient(api.app)
assert client.post("/api/login", json={"employee_id": "admin", "password": INITIAL_PASSWORD}).status_code == 200
created = client.post(
"/api/admin/notices",
json={
"title": "维护",
"body": "今晚更新",
"link_url": "https://euniv.asio.asia",
"published_at": "2026-11-19T04:00:00+08:00",
},
)
assert created.status_code == 200
assert created.json()["title"] == "维护"
assert created.json()["published_at"].startswith("2026-11-19T04:00")
listed = client.get("/api/admin/notices")
assert listed.status_code == 200
assert listed.json()[0]["link_url"] == "https://euniv.asio.asia"
bad = client.post(
"/api/admin/notices",
json={
"title": "坏链接",
"body": "正文",
"link_url": "javascript:alert(1)",
"published_at": "2026-11-19T04:00:00+08:00",
},
)
assert bad.status_code == 400
notice_id = created.json()["id"]
assert client.delete(f"/api/admin/notices/{notice_id}").status_code == 200
assert client.get("/api/admin/notices").json() == []
+5 -1
View File
@@ -172,6 +172,7 @@ def test_login_stores_password_and_credential_only(monkeypatch) -> None:
"study_opened_at",
"study_schedule_enabled",
"heartbeat_mode",
"hours_source",
"heartbeat_video_seconds",
"heartbeat_document_seconds",
"heartbeat_scorm_seconds",
@@ -593,7 +594,7 @@ def test_period_page_is_not_fetched_twice() -> None:
return Response()
client.client = HTTP()
assert client._period_minutes() == {"year": "34", "month": "12"}
assert client._period_minutes() == {"year": "34", "month": "12", "total": ""}
assert len(calls) == 1
@@ -1108,6 +1109,9 @@ def _set_hours_source(value: str) -> None:
with SessionLocal() as db:
row = load_config(db)
row.hours_source = value
account = db.get(Account, "6650000146")
if account is not None:
account.hours_source = value
db.commit()
+4 -4
View File
@@ -386,7 +386,7 @@ class _HourSession:
def test_hours_watcher_stops_when_target_reached(monkeypatch) -> None:
saved: list[tuple[str, str]] = []
monkeypatch.setattr("euniv.autostudy._update_month_hours", lambda eid, hours: saved.append((eid, hours)))
monkeypatch.setattr("euniv.autostudy._update_month_hours", lambda eid, hours, official="": saved.append((eid, hours)))
async def main() -> None:
session = _HourSession("600")
@@ -402,15 +402,15 @@ def test_hours_watcher_stops_when_target_reached(monkeypatch) -> None:
def test_hours_watcher_history_source_uses_month_history(monkeypatch) -> None:
saved: list[tuple[str, str]] = []
monkeypatch.setattr("euniv.autostudy._update_month_hours", lambda eid, hours: saved.append((eid, hours)))
monkeypatch.setattr("admin.settings.hours_source_of", lambda: "history")
monkeypatch.setattr("euniv.autostudy._update_month_hours", lambda eid, hours, official="": saved.append((eid, hours)))
monkeypatch.setattr("admin.settings.source_for_employee", lambda _employee_id: "history")
class _HistorySession:
async def month_history_minutes(self) -> int:
return 600
async def month_hours_text(self) -> str:
raise AssertionError("history 模式不应读接口本月学时")
return "126"
async def main() -> None:
user_stop = asyncio.Event()