feat: 首页拆分独立加载、骨架动画和手动刷新
This commit is contained in:
@@ -24,6 +24,8 @@ def fresh_database():
|
||||
connection.execute(text("DROP TABLE IF EXISTS accounts"))
|
||||
connection.execute(text("DROP TABLE IF EXISTS schedules"))
|
||||
connection.execute(text("DROP TABLE IF EXISTS system_config"))
|
||||
connection.execute(text("DROP TABLE IF EXISTS courses"))
|
||||
connection.execute(text("DROP TABLE IF EXISTS course_sync"))
|
||||
connection.execute(text("DROP TABLE IF EXISTS alembic_version"))
|
||||
init_db()
|
||||
ensure_admin_seed()
|
||||
|
||||
@@ -96,6 +96,9 @@ def test_admin_login_succeeds_and_wrong_password_skips_euniv() -> None:
|
||||
assert COOKIE_NAME not in client.cookies
|
||||
assert client.get("/api/session").json() == {"role": "admin", "username": "admin"}
|
||||
assert client.get("/api/home").status_code == 403
|
||||
assert client.get("/api/home/summary").status_code == 403
|
||||
assert client.get("/api/home/exams").status_code == 403
|
||||
assert client.get("/api/home/trainings").status_code == 403
|
||||
assert client.get("/api/exam", params={"path": "/exam/x"}).status_code == 403
|
||||
assert client.get("/api/training", params={"path": "/plan/x"}).status_code == 403
|
||||
assert calls == []
|
||||
@@ -302,6 +305,9 @@ class _Alive:
|
||||
def credential_alive(self) -> bool:
|
||||
return True
|
||||
|
||||
def month_hours(self) -> str:
|
||||
return "660"
|
||||
|
||||
def export_credential(self) -> dict:
|
||||
return dict(CREDENTIAL)
|
||||
|
||||
@@ -355,6 +361,7 @@ def test_refresh_records_outcome_and_skips_paused_accounts() -> None:
|
||||
empty = db.get(Account, "empty-user")
|
||||
assert alive is not None and failed is not None and paused is not None and empty is not None
|
||||
assert alive.credential_valid is True
|
||||
assert alive.month_hours == "660"
|
||||
assert alive.last_refresh_at is not None
|
||||
assert decrypt_secret(alive.password_cipher) == "secret-pass"
|
||||
assert json.loads(decrypt_secret(alive.credential_cipher))["yxt_token"] == "yxt-1"
|
||||
@@ -436,10 +443,12 @@ def test_check_skips_empty_credential_and_updates_saved_one() -> None:
|
||||
"refresh_paused",
|
||||
"last_refresh_at",
|
||||
"credential_valid",
|
||||
"month_hours",
|
||||
}
|
||||
assert saved["has_credential"] is True
|
||||
assert saved["refresh_paused"] is False
|
||||
assert saved["credential_valid"] is True
|
||||
assert saved["month_hours"] == ""
|
||||
assert isinstance(saved["last_refresh_at"], str)
|
||||
calls.clear()
|
||||
again = client.get("/api/admin/users")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from euniv.client import JigsawRejected, ManualJigsaw
|
||||
@@ -108,6 +109,7 @@ def test_login_stores_password_and_credential_only() -> None:
|
||||
"refresh_paused",
|
||||
"last_refresh_at",
|
||||
"credential_valid",
|
||||
"month_hours",
|
||||
}
|
||||
|
||||
home = client.get("/api/home")
|
||||
@@ -390,3 +392,64 @@ def test_exam_and_training_details() -> None:
|
||||
"score": "0/5.2",
|
||||
"hours": "52/52",
|
||||
}
|
||||
|
||||
|
||||
def test_home_sections_are_separate() -> 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_home_summary = lambda db, employee_id: {"name": "分段"}
|
||||
api_module.fetch_home_exams = lambda db, employee_id: {"exams": [{"name": "一门考试"}]}
|
||||
api_module.fetch_home_trainings = lambda db, employee_id: {"trainings": [{"name": "一门培训"}]}
|
||||
client = TestClient(api_module.app)
|
||||
response = client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"})
|
||||
assert response.status_code == 200
|
||||
assert client.get("/api/home/summary").json()["name"] == "分段"
|
||||
assert client.get("/api/home/exams").json()["exams"] == [{"name": "一门考试"}]
|
||||
assert client.get("/api/home/trainings").json()["trainings"] == [{"name": "一门培训"}]
|
||||
|
||||
|
||||
def test_period_page_is_not_fetched_twice() -> None:
|
||||
from euniv.client import EunivClient
|
||||
|
||||
client = EunivClient.__new__(EunivClient)
|
||||
client._profile = {"token": "t", "accountId": "a"}
|
||||
client._site_ready = False
|
||||
calls: list[str] = []
|
||||
|
||||
class Response:
|
||||
text = '<span id="spAnnualPeriod" title="34分钟"></span><span id="spMonthlyPeriod" title="12分钟"></span>'
|
||||
|
||||
class HTTP:
|
||||
def get(self, url: str, headers=None):
|
||||
calls.append(url)
|
||||
return Response()
|
||||
|
||||
client.client = HTTP()
|
||||
assert client._period_minutes() == {"year": "34", "month": "12"}
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
def test_exam_list_rejects_unrecognized_page() -> None:
|
||||
from euniv.client import EunivClient
|
||||
|
||||
client = EunivClient.__new__(EunivClient)
|
||||
client._profile = {"token": "t", "accountId": "a"}
|
||||
client._site_ready = True
|
||||
|
||||
class Response:
|
||||
text = "<html>login</html>"
|
||||
|
||||
class HTTP:
|
||||
def get(self, url: str, headers=None):
|
||||
return Response()
|
||||
|
||||
def post(self, url: str, data=None, headers=None):
|
||||
return Response()
|
||||
|
||||
client.client = HTTP()
|
||||
with pytest.raises(RuntimeError, match="考试列表没有获取到"):
|
||||
client.my_exams()
|
||||
|
||||
Reference in New Issue
Block a user