feat: 每月定时开始学习并改为本地计算心跳摘要
This commit is contained in:
@@ -447,6 +447,11 @@ def test_check_skips_empty_credential_and_updates_saved_one() -> None:
|
||||
"month_hours",
|
||||
"has_proxy",
|
||||
"proxy",
|
||||
"study_start",
|
||||
"study_start_day",
|
||||
"study_start_hour",
|
||||
"study_start_minute",
|
||||
"study_start_second",
|
||||
}
|
||||
assert saved["has_credential"] is True
|
||||
assert saved["refresh_paused"] is False
|
||||
@@ -690,3 +695,34 @@ def test_admin_can_set_and_clear_proxy_for_selected_users() -> None:
|
||||
detail = client.get("/api/admin/users/p1-user/proxy")
|
||||
assert detail.json()["has_password"] is False
|
||||
assert detail.json()["username"] == ""
|
||||
|
||||
|
||||
def test_admin_can_set_study_start_for_selected_users() -> None:
|
||||
_add_account("s1-user")
|
||||
_add_account("s2-user")
|
||||
api = _app()
|
||||
client = TestClient(api.app)
|
||||
assert client.post("/api/login", json={"employee_id": "admin", "password": INITIAL_PASSWORD}).status_code == 200
|
||||
saved = client.put(
|
||||
"/api/admin/users/study-start",
|
||||
json={"employee_ids": ["s1-user", "s2-user"], "day": 5, "hour": 16, "minute": 8, "second": 9},
|
||||
)
|
||||
assert saved.status_code == 200
|
||||
assert saved.json()["count"] == 2
|
||||
listed = client.get("/api/admin/users").json()
|
||||
one = next(item for item in listed if item["employee_id"] == "s1-user")
|
||||
two = next(item for item in listed if item["employee_id"] == "s2-user")
|
||||
assert one["study_start"] == "每月5日 16:08:09"
|
||||
assert two["study_start"] == "每月5日 16:08:09"
|
||||
one_only = client.put(
|
||||
"/api/admin/users/study-start",
|
||||
json={"employee_ids": ["s1-user"], "day": 20, "hour": 0, "minute": 0, "second": 0},
|
||||
)
|
||||
assert one_only.status_code == 200
|
||||
listed = client.get("/api/admin/users").json()
|
||||
one = next(item for item in listed if item["employee_id"] == "s1-user")
|
||||
two = next(item for item in listed if item["employee_id"] == "s2-user")
|
||||
assert one["study_start"] == "每月20日 00:00:00"
|
||||
assert two["study_start"] == "每月5日 16:08:09"
|
||||
detail = client.get("/api/admin/users/s1-user/study-start")
|
||||
assert detail.json()["day"] == 20
|
||||
|
||||
@@ -117,6 +117,10 @@ def test_login_stores_password_and_credential_only() -> None:
|
||||
"proxy_port",
|
||||
"proxy_username",
|
||||
"proxy_password_cipher",
|
||||
"study_start_day",
|
||||
"study_start_hour",
|
||||
"study_start_minute",
|
||||
"study_start_second",
|
||||
}
|
||||
|
||||
home = client.get("/api/home")
|
||||
@@ -488,6 +492,25 @@ def test_user_can_set_proxy_with_or_without_password() -> None:
|
||||
assert cleared.json()["enabled"] is False
|
||||
|
||||
|
||||
def test_user_can_set_monthly_study_start() -> 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
|
||||
empty = client.get("/api/settings/study-start")
|
||||
assert empty.status_code == 200
|
||||
assert empty.json() == {"day": 1, "hour": 0, "minute": 0, "second": 0, "label": "每月1日 00:00:00"}
|
||||
saved = client.put("/api/settings/study-start", json={"day": 5, "hour": 16, "minute": 0, "second": 7})
|
||||
assert saved.status_code == 200
|
||||
assert saved.json()["label"] == "每月5日 16:00:07"
|
||||
bad = client.put("/api/settings/study-start", json={"day": 32, "hour": 16, "minute": 0, "second": 0})
|
||||
assert bad.status_code == 400
|
||||
|
||||
|
||||
def test_exam_list_rejects_unrecognized_page() -> None:
|
||||
from euniv.client import EunivClient
|
||||
|
||||
|
||||
@@ -2,8 +2,12 @@ import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from euniv.autostudy import HoursWatcher, _parse_minutes, _study_video, wait_stop
|
||||
from euniv.client import study_encryption
|
||||
from euniv.proxy import ProxyError, build_proxy_url, parse_proxy
|
||||
from euniv.study_window import CN_TZ, StudyWindowError, validate_start, window_open
|
||||
|
||||
|
||||
def test_parse_proxy_accepts_http_and_socks() -> None:
|
||||
@@ -160,3 +164,57 @@ def test_video_skip_already_complete_does_not_refresh() -> None:
|
||||
assert not watcher.reached
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
|
||||
def test_study_encryption_matches_get_encrypt_request() -> None:
|
||||
import json
|
||||
|
||||
body = json.dumps(
|
||||
{
|
||||
"knowledgeId": "6d16a38ebdfe455fbb1e86ec0c0c35d7",
|
||||
"masterId": "",
|
||||
"masterType": "",
|
||||
"packageId": "",
|
||||
"pageSize": 1,
|
||||
"studySize": 1,
|
||||
"studyTime": 120,
|
||||
"type": 1,
|
||||
"offLine": False,
|
||||
"end": False,
|
||||
"care": True,
|
||||
"deviceId": "",
|
||||
"studyChapterIds": "",
|
||||
"viewSchedule": 1,
|
||||
},
|
||||
separators=(",", ":"),
|
||||
)
|
||||
assert study_encryption(body) == "ba119ee448648d9f8f046d11c426afa4"
|
||||
|
||||
|
||||
class _Start:
|
||||
def __init__(self, day: int, hour: int = 16, minute: int = 0, second: int = 0) -> None:
|
||||
self.study_start_day = day
|
||||
self.study_start_hour = hour
|
||||
self.study_start_minute = minute
|
||||
self.study_start_second = second
|
||||
|
||||
|
||||
def test_study_window_opens_after_configured_time() -> None:
|
||||
account = _Start(5, 16, 0, 0)
|
||||
assert window_open(account, datetime(2026, 11, 5, 15, 59, 59, tzinfo=CN_TZ)) is False
|
||||
assert window_open(account, datetime(2026, 11, 5, 16, 0, 0, tzinfo=CN_TZ)) is True
|
||||
assert window_open(account, datetime(2026, 11, 15, 1, 24, 0, tzinfo=CN_TZ)) is True
|
||||
assert window_open(account, datetime(2026, 12, 5, 15, 0, 0, tzinfo=CN_TZ)) is False
|
||||
|
||||
|
||||
def test_study_window_clamps_missing_day() -> None:
|
||||
account = _Start(31, 16, 0, 0)
|
||||
assert window_open(account, datetime(2026, 2, 28, 15, 59, 59, tzinfo=CN_TZ)) is False
|
||||
assert window_open(account, datetime(2026, 2, 28, 16, 0, 0, tzinfo=CN_TZ)) is True
|
||||
|
||||
|
||||
def test_study_window_rejects_invalid_parts() -> None:
|
||||
with pytest.raises(StudyWindowError):
|
||||
validate_start(32, 0, 0, 0)
|
||||
with pytest.raises(StudyWindowError):
|
||||
validate_start(1, 24, 0, 0)
|
||||
|
||||
Reference in New Issue
Block a user