feat: 每月定时开始学习并改为本地计算心跳摘要

This commit is contained in:
2026-11-15 01:30:24 +08:00
parent e9a1e9b315
commit caa79d79b7
14 changed files with 510 additions and 35 deletions
+58
View File
@@ -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)