feat: 检查全部时刷新本月学时
This commit is contained in:
@@ -544,12 +544,25 @@ def test_check_all_reports_each_saved_account(monkeypatch) -> None:
|
||||
_add_account("a-user")
|
||||
_add_account("b-user")
|
||||
_add_account("c-user", credential=None)
|
||||
_add_account("kept-user")
|
||||
with SessionLocal() as db:
|
||||
kept = db.get(Account, "kept-user")
|
||||
assert kept is not None
|
||||
kept.month_hours = "12"
|
||||
kept.hours_month = "2026-10"
|
||||
db.commit()
|
||||
calls = []
|
||||
|
||||
class _NoHours(_Alive):
|
||||
def month_hours(self) -> str:
|
||||
return ""
|
||||
|
||||
def factory(login_name: str, password: str, proxy: str | None = None):
|
||||
calls.append(login_name)
|
||||
if login_name == "b-user":
|
||||
raise RuntimeError("网络失败")
|
||||
if login_name == "kept-user":
|
||||
return _NoHours(login_name, password)
|
||||
return _Alive(login_name, password)
|
||||
|
||||
monkeypatch.setattr(users, "build_client", factory)
|
||||
@@ -561,15 +574,23 @@ 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": "有效"},
|
||||
]
|
||||
assert calls == ["a-user", "b-user"]
|
||||
assert calls == ["a-user", "b-user", "kept-user"]
|
||||
from euniv.study_window import month_key
|
||||
|
||||
with SessionLocal() as db:
|
||||
failed = db.get(Account, "b-user")
|
||||
untouched = db.get(Account, "c-user")
|
||||
checked = db.get(Account, "a-user")
|
||||
kept = db.get(Account, "kept-user")
|
||||
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 failed is not None and failed.credential_valid is None
|
||||
assert failed.user_name == "" and failed.company == ""
|
||||
assert failed.month_hours == ""
|
||||
assert failed.last_refresh_at is not None
|
||||
assert untouched is not None and untouched.last_refresh_at is None
|
||||
assert untouched.user_name == "" and untouched.company == ""
|
||||
|
||||
Reference in New Issue
Block a user