feat: 学习状态改为内存快照,页面连接每秒自取并自动重连
This commit is contained in:
@@ -106,6 +106,38 @@ def test_socks4_uses_socks_transport_instead_of_httpx_proxy() -> None:
|
||||
assert "proxy" not in async_args
|
||||
|
||||
|
||||
def test_clients_share_one_tls_setup(monkeypatch) -> None:
|
||||
import ssl
|
||||
|
||||
from httpx_socks import AsyncProxyTransport, SyncProxyTransport
|
||||
|
||||
from euniv.proxy import async_httpx_client, shared_tls
|
||||
|
||||
context = shared_tls()
|
||||
assert shared_tls() is context
|
||||
assert isinstance(context, ssl.SSLContext)
|
||||
assert context.verify_mode == ssl.CERT_REQUIRED
|
||||
assert context.check_hostname is True
|
||||
seen: list[dict] = []
|
||||
|
||||
class Capture:
|
||||
def __init__(self, **kwargs) -> None:
|
||||
seen.append(kwargs)
|
||||
|
||||
monkeypatch.setattr(httpx, "Client", Capture)
|
||||
monkeypatch.setattr(httpx, "AsyncClient", Capture)
|
||||
sync_httpx_client()
|
||||
sync_httpx_client("http://127.0.0.1:8080")
|
||||
async_httpx_client()
|
||||
assert [kwargs["verify"] is context for kwargs in seen] == [True, True, True]
|
||||
socks: list[object] = []
|
||||
monkeypatch.setattr(SyncProxyTransport, "from_url", classmethod(lambda cls, url, **kw: socks.append(kw.get("verify"))))
|
||||
monkeypatch.setattr(AsyncProxyTransport, "from_url", classmethod(lambda cls, url, **kw: socks.append(kw.get("verify"))))
|
||||
client_proxy_args("socks5://127.0.0.1:1080")
|
||||
client_proxy_args("socks5://127.0.0.1:1080", asynchronous=True)
|
||||
assert socks == [context, context]
|
||||
|
||||
|
||||
def test_parse_minutes() -> None:
|
||||
assert _parse_minutes("") == 0
|
||||
assert _parse_minutes("600") == 600
|
||||
@@ -1416,3 +1448,46 @@ def test_saved_interval_is_kept_in_memory_for_running_courses() -> None:
|
||||
assert _course_plan("video", intervals, auto, {"submitProTimes": 30})[:2] == (0, 30)
|
||||
assert _course_plan("document", intervals, auto, {"validtimeSpan": 120, "submitIsOpen": "1"})[:2] == (4, 120)
|
||||
assert _course_plan("document", intervals, True, {"submitProTimes": 30, "submitIsOpen": "1"})[:2] == (30, 30)
|
||||
|
||||
|
||||
def test_course_list_is_shared_in_memory_until_the_table_changes() -> None:
|
||||
from euniv.autostudy import shared_courses
|
||||
from euniv.db import SessionLocal
|
||||
from euniv.models import Course
|
||||
|
||||
with SessionLocal() as db:
|
||||
db.add(Course(path="/kng/view/video/a.html", title="甲", kind="视频"))
|
||||
db.commit()
|
||||
with SessionLocal() as db:
|
||||
first = shared_courses(db)
|
||||
second = shared_courses(db)
|
||||
assert first is second
|
||||
assert [title for _path, title, _kind in first] == ["甲"]
|
||||
with SessionLocal() as db:
|
||||
db.add(Course(path="/kng/view/document/b.html", title="乙", kind="文档"))
|
||||
db.flush()
|
||||
db.rollback()
|
||||
with SessionLocal() as db:
|
||||
assert shared_courses(db) is first
|
||||
db.add(Course(path="/kng/view/document/b.html", title="乙", kind="文档"))
|
||||
db.commit()
|
||||
with SessionLocal() as db:
|
||||
third = shared_courses(db)
|
||||
assert third is not first
|
||||
assert [title for _path, title, _kind in third] == ["甲", "乙"]
|
||||
|
||||
|
||||
def test_progress_updates_do_not_call_into_the_page_connections(monkeypatch) -> None:
|
||||
from euniv.autostudy import WorkerView, halt_work
|
||||
|
||||
seen: list[tuple[str | None, bool]] = []
|
||||
monkeypatch.setattr("euniv.study_push.notify", lambda eid=None, urgent=False: seen.append((eid, urgent)))
|
||||
_clear_user_status("u-quiet")
|
||||
view = WorkerView("u-quiet", 1)
|
||||
view.update(course="甲", knowledge_id="k-quiet", progress=1)
|
||||
view.adopt({"studyschedule": 5, "actualstudyhours": 1, "standardstudyhours": 20}, ok=True)
|
||||
_set_user_status("u-quiet", state="学习中")
|
||||
assert seen == []
|
||||
halt_work("u-quiet")
|
||||
assert seen == [("u-quiet", True)]
|
||||
_clear_user_status("u-quiet")
|
||||
|
||||
Reference in New Issue
Block a user