fix: 凭据有效改为当场取到个人信息和本月学时

This commit is contained in:
Nixevol
2026-11-21 15:01:54 +08:00
parent a6306e8339
commit a5539405ca
3 changed files with 85 additions and 26 deletions
+37 -2
View File
@@ -582,7 +582,7 @@ def test_check_all_reports_each_saved_account(monkeypatch) -> None:
assert response.json() == [
{"employee_id": "a-user", "result": "有效"},
{"employee_id": "b-user", "result": "检查失败", "detail": "检查失败"},
{"employee_id": "kept-user", "result": "有效"},
{"employee_id": "kept-user", "result": "已失效"},
]
assert calls == ["a-user", "b-user", "kept-user"]
from euniv.study_window import month_key
@@ -595,7 +595,9 @@ def test_check_all_reports_each_saved_account(monkeypatch) -> None:
assert checked is not None and checked.user_name == "莫英达" and checked.company == "广州瀚信广州处"
assert checked.month_hours == "660"
assert checked.hours_month == month_key()
assert kept is not None and kept.month_hours == "12" and kept.hours_month == "2026-10"
assert kept is not None and kept.credential_valid is False
assert kept.user_name == "莫英达" and kept.company == "广州瀚信广州处"
assert kept.month_hours == "12" and kept.hours_month == "2026-10"
assert failed is not None and failed.credential_valid is None
assert failed.user_name == "" and failed.company == ""
assert failed.month_hours == ""
@@ -604,6 +606,39 @@ def test_check_all_reports_each_saved_account(monkeypatch) -> None:
assert untouched.user_name == "" and untouched.company == ""
def test_check_replaces_previous_valid_when_hours_cannot_be_read(monkeypatch) -> None:
import admin.users as users
_add_account("stale-user", valid=True)
with SessionLocal() as db:
account = db.get(Account, "stale-user")
assert account is not None
account.month_hours = "616"
account.official_month_hours = "321"
account.user_name = "旧名字"
db.commit()
class _InfoOnly(_Alive):
def month_hours(self) -> str:
raise RuntimeError("学时页面打不开")
monkeypatch.setattr(users, "build_client", lambda login_name, password, proxy=None: _InfoOnly(login_name, password))
api = _app()
client = TestClient(api.app)
assert client.post("/api/login", json={"employee_id": "admin", "password": INITIAL_PASSWORD}).status_code == 200
checked = client.post("/api/admin/users/stale-user/check")
assert checked.status_code == 200
assert checked.json()["result"] == "已失效"
with SessionLocal() as db:
account = db.get(Account, "stale-user")
assert account is not None
assert account.credential_valid is False
assert account.user_name == "莫英达"
assert account.company == "广州瀚信广州处"
assert account.month_hours == "616"
assert account.official_month_hours == "321"
def test_credentials_and_delete_user(monkeypatch) -> None:
import admin.users as users