feat: 立即开始停止学习并整理学时历史与界面
This commit is contained in:
@@ -65,6 +65,16 @@ class FakeClient:
|
||||
"unionId": credential["ucs_union_id"],
|
||||
}
|
||||
|
||||
def study_history(self) -> list[dict]:
|
||||
return [
|
||||
{
|
||||
"title": "ZXCTN-A-CH-EVPN原理及配置介绍(IPRAN)",
|
||||
"minutes": 2,
|
||||
"studied_at": "2026-11-14 23:55",
|
||||
"path": "/kng/view/document/125c7576c22e4ae7be92ce005171facb.html",
|
||||
}
|
||||
]
|
||||
|
||||
def home_snapshot(self) -> dict:
|
||||
if self._token == "yxt-1":
|
||||
self._token = "yxt-2"
|
||||
@@ -123,6 +133,8 @@ def test_login_stores_password_and_credential_only() -> None:
|
||||
"study_start_second",
|
||||
"course_workers",
|
||||
"use_proxy_pool",
|
||||
"study_paused",
|
||||
"study_ignore_window",
|
||||
}
|
||||
|
||||
home = client.get("/api/home")
|
||||
@@ -538,6 +550,82 @@ def test_user_can_set_monthly_study_start() -> None:
|
||||
assert bad.status_code == 400
|
||||
|
||||
|
||||
def test_user_can_start_and_stop_study_immediately() -> None:
|
||||
import euniv.api as api_module
|
||||
import euniv.service as service_module
|
||||
|
||||
api_module.login_and_store = lambda db, employee_id, password, manual=False, auto_attempts=3: service_module.login_and_store(
|
||||
db, employee_id, password, FakeClient, manual=manual, auto_attempts=auto_attempts
|
||||
)
|
||||
client = TestClient(api_module.app)
|
||||
assert client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"}).status_code == 200
|
||||
client.put("/api/settings/study-start", json={"day": 31, "hour": 23, "minute": 59, "second": 59})
|
||||
idle = client.get("/api/settings/study-control")
|
||||
assert idle.status_code == 200
|
||||
started = client.post("/api/settings/study-control", json={"action": "start"})
|
||||
assert started.status_code == 200
|
||||
assert started.json()["started"] is True
|
||||
assert started.json()["ignore_window"] is True
|
||||
assert started.json()["paused"] is False
|
||||
stopped = client.post("/api/settings/study-control", json={"action": "stop"})
|
||||
assert stopped.status_code == 200
|
||||
assert stopped.json()["started"] is False
|
||||
assert stopped.json()["paused"] is True
|
||||
assert stopped.json()["ignore_window"] is False
|
||||
bad = client.post("/api/settings/study-control", json={"action": "pause"})
|
||||
assert bad.status_code == 400
|
||||
|
||||
|
||||
def test_user_can_read_study_history() -> None:
|
||||
import euniv.api as api_module
|
||||
import euniv.service as service_module
|
||||
|
||||
api_module.login_and_store = lambda db, employee_id, password, manual=False, auto_attempts=3: service_module.login_and_store(
|
||||
db, employee_id, password, FakeClient, manual=manual, auto_attempts=auto_attempts
|
||||
)
|
||||
api_module.fetch_study_history = lambda db, employee_id: service_module.fetch_study_history(
|
||||
db, employee_id, FakeClient
|
||||
)
|
||||
client = TestClient(api_module.app)
|
||||
assert client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"}).status_code == 200
|
||||
history = client.get("/api/home/history")
|
||||
assert history.status_code == 200
|
||||
body = history.json()
|
||||
assert body["total"] == 1
|
||||
assert body["items"][0]["title"].startswith("ZXCTN")
|
||||
assert body["items"][0]["minutes"] == 2
|
||||
|
||||
|
||||
def test_study_history_parses_period_table() -> None:
|
||||
from euniv.client import EunivClient
|
||||
|
||||
html = """
|
||||
<table class="table mt5 mb10">
|
||||
<tr><th>来源</th><th>学时</th><th>日期</th></tr>
|
||||
<tr class="alter">
|
||||
<td class="text-left" title="ZXCTN-A-CH-EVPN原理及配置介绍(IPRAN)">
|
||||
ZXCTN-A-CH-EVPN原理及配置介绍(IPRAN)
|
||||
<span onclick="GoToSource('/kng/view/document/125c7576c22e4ae7be92ce005171facb.html','SingleStudy','125c7576-c22e-4ae7-be92-ce005171facb')"
|
||||
class='text-info hand '>[详情]</span>
|
||||
</td>
|
||||
<td class="text-center">2</td>
|
||||
<td class="text-center">2026-11-14 23:55</td>
|
||||
</tr>
|
||||
</table>
|
||||
"""
|
||||
client = EunivClient.__new__(EunivClient)
|
||||
client._study_period_page = lambda: html # type: ignore[method-assign]
|
||||
rows = client._study_history_page()
|
||||
assert rows == [
|
||||
{
|
||||
"title": "ZXCTN-A-CH-EVPN原理及配置介绍(IPRAN)",
|
||||
"minutes": 2,
|
||||
"studied_at": "2026-11-14 23:55",
|
||||
"path": "/kng/view/document/125c7576c22e4ae7be92ce005171facb.html",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_exam_list_rejects_unrecognized_page() -> None:
|
||||
from euniv.client import EunivClient
|
||||
|
||||
|
||||
Reference in New Issue
Block a user