feat: 账号可设置同时学习课程数并支持关闭代理

This commit is contained in:
2026-11-15 01:48:39 +08:00
parent ecd774507f
commit aa26d00c60
14 changed files with 564 additions and 119 deletions
+54 -2
View File
@@ -4,8 +4,9 @@ import pytest
from datetime import datetime
from euniv.autostudy import HoursWatcher, _parse_minutes, _study_video, wait_stop
from euniv.proxy import ProxyError, build_proxy_url, parse_proxy
from euniv.autostudy import CourseCursor, HoursWatcher, _parse_minutes, _study_video, wait_stop
from euniv.course_workers import CourseWorkersError, of as workers_of, validate as validate_workers
from euniv.proxy import ProxyError, apply as apply_proxy, build_proxy_url, parse_proxy, view_of as proxy_view
from euniv.study_window import CN_TZ, StudyWindowError, validate_start, window_open
@@ -192,3 +193,54 @@ def test_study_window_rejects_invalid_parts() -> None:
validate_start(32, 0, 0, 0)
with pytest.raises(StudyWindowError):
validate_start(1, 24, 0, 0)
def test_course_workers_default_and_range() -> None:
class Account:
course_workers = 1
assert workers_of(Account()) == 1
assert validate_workers(8) == 8
with pytest.raises(CourseWorkersError):
validate_workers(0)
with pytest.raises(CourseWorkersError):
validate_workers(9)
def test_course_cursor_hands_each_item_once() -> None:
async def main() -> None:
cursor = CourseCursor([("a", "A", "视频"), ("b", "B", "文档"), ("c", "C", "课程")])
seen: list[str] = []
async def worker() -> None:
while True:
item = await cursor.take()
if item is None:
return
seen.append(item[0])
await asyncio.sleep(0)
await asyncio.gather(worker(), worker(), worker())
assert sorted(seen) == ["a", "b", "c"]
asyncio.run(main())
class _ProxyAccount:
def __init__(self) -> None:
self.proxy_scheme = "http"
self.proxy_host = "10.0.0.1"
self.proxy_port = 8080
self.proxy_username = "u"
self.proxy_password_cipher = "cipher"
def test_proxy_off_scheme_clears_settings() -> None:
account = _ProxyAccount()
apply_proxy(account, "off")
view = proxy_view(account)
assert view["enabled"] is False
assert view["scheme"] == "off"
assert account.proxy_scheme == ""
assert account.proxy_host == ""
assert account.proxy_port is None