feat: 首页显示全部线上培训和我的考试,并按离现在更近的时间排序

This commit is contained in:
2026-10-27 05:13:44 +08:00
parent 7bbb80ee9c
commit 41ae8b4f88
3 changed files with 228 additions and 48 deletions
+58 -3
View File
@@ -78,8 +78,9 @@ class FakeClient:
"total_score": "3.00",
"today_hours": "1",
"today_score": "0.10",
"pending_exam_count": 1,
"pending_exams": [{"name": "安全考试", "deadline": ""}],
"month_hours": "60",
"exams": [{"name": "安全考试", "status": "已完成", "start": "2026-05-20 00:01:00"}],
"trainings": [],
}
@@ -116,7 +117,7 @@ def test_login_stores_password_and_credential_only() -> None:
assert home.status_code == 200
body = home.json()
assert body["name"] == "测试用户"
assert body["pending_exams"] == [{"name": "安全考试", "deadline": ""}]
assert body["exams"] == [{"name": "安全考试", "status": "已完成", "start": "2026-05-20 00:01:00"}]
with SessionLocal() as db:
account = db.get(Account, "6650000146")
assert account is not None
@@ -260,3 +261,57 @@ def test_browser_session_logout_and_revoke() -> None:
assert account is not None
assert account.credential_cipher == ""
assert decrypt_secret(account.password_cipher) == "secret-pass"
def test_parse_training_cards_keeps_status() -> None:
from euniv.client import parse_training_cards
html = """
<li class='el-plan-li-3' id="contentitem1" onclick='learningKnowledge("/plan/a.html")'>
<div class="el-plan-circle-progress p5" progress="100" id="demo1"></div>
<div class="font-size-16 text-color6 ellipsis">
租赁人员数据保护合规培训-2026</div>
<span class="mr10">
Jiang Mingjun</span><span data-localizeph="sty_lbl_assignedtime"><span>&nbsp;194 天</span></span>
<span data-localizeph='sty_lbl_getcredits' class='el-plan-time'><span>1</span></span>
</li>
"""
rows = parse_training_cards(html, "已完成")
assert rows == [{
"name": "租赁人员数据保护合规培训-2026",
"status": "已完成",
"progress": 100,
"owner": "Jiang Mingjun",
"assigned": "194 天",
"credits": "1",
"sort_days": 194.0,
}]
def test_lists_put_the_nearest_time_first() -> None:
from euniv.client import _by_closeness, parse_exam_cards
html = """
<li name="userExam">
<a class="my-exam-title ellipsis">较远的考试</a>
<input type="button" class="btn btn-smd btn-primary my-exam-btn btn-primary" onclick="" value="已完成" />
<span data-localize="sty_lbl_teststarttime"></span>:2020-01-01 00:00:00&nbsp;
</li>
<li name="userExam">
<a class="my-exam-title ellipsis">较近的考试</a>
<input type="button" class="btn btn-smd btn-primary my-exam-btn btn-primary" onclick="" value="已过期" />
<span data-localize="sty_lbl_teststarttime"></span>:2026-10-20 00:01:00&nbsp;
</li>
"""
rows = _by_closeness(parse_exam_cards(html), "sort_at")
assert [item["name"] for item in rows] == ["较近的考试", "较远的考试"]
assert rows[0]["status"] == "已过期"
assert "sort_at" not in rows[0]
trainings = _by_closeness(
[
{"name": "很久以前", "sort_days": 741.0},
{"name": "刚指派", "sort_days": 5.0},
],
"sort_days",
)
assert [item["name"] for item in trainings] == ["刚指派", "很久以前"]