feat: 增加公告栏并让用户自选学时判断
This commit is contained in:
@@ -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() == []
|
||||
|
||||
Reference in New Issue
Block a user