fix: 清掉清单里剩下的死代码、重复样式和评论解析
This commit is contained in:
@@ -696,8 +696,7 @@ def test_settings_do_not_expose_process_switches() -> None:
|
||||
"hours_source",
|
||||
}
|
||||
assert body["hours_source"] == "api"
|
||||
assert identity.password_cipher()
|
||||
assert verify_password(identity.password_cipher(), INITIAL_PASSWORD)
|
||||
assert identity.password_ok(INITIAL_PASSWORD)
|
||||
|
||||
|
||||
def test_admin_can_set_and_clear_proxy_for_selected_users() -> None:
|
||||
|
||||
@@ -33,7 +33,6 @@ def test_parse_course_page_reads_a_catalog_row() -> None:
|
||||
"learners": "1513",
|
||||
"released_on": "2026-10-16",
|
||||
"updated_on": "2026-10-16",
|
||||
"comments": "5",
|
||||
}]
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import asyncio
|
||||
import inspect
|
||||
|
||||
import httpx
|
||||
|
||||
from euniv import autostudy as autostudy_mod
|
||||
from euniv import client as client_mod
|
||||
from euniv.encrypt import (
|
||||
encrypt_path_from_js,
|
||||
encrypt_payload,
|
||||
fetch_encryption,
|
||||
note_play_html,
|
||||
parse_encrypt_response,
|
||||
reset_encrypt_config,
|
||||
)
|
||||
from euniv import encrypt as encrypt_mod
|
||||
from euniv.encrypt import encrypt_path_from_js, encrypt_payload, fetch_encryption_async, note_play_html, parse_encrypt_response
|
||||
|
||||
|
||||
def _reset_encrypt() -> None:
|
||||
with encrypt_mod._lock:
|
||||
encrypt_mod._config["path"] = encrypt_mod.DEFAULT_ENCRYPT_PATH
|
||||
encrypt_mod._config["js_url"] = encrypt_mod.DEFAULT_JS_URL
|
||||
encrypt_mod._config["loaded_at"] = 0.0
|
||||
encrypt_mod._config["retry_at"] = 0.0
|
||||
|
||||
|
||||
def test_short_secret_is_rejected(monkeypatch) -> None:
|
||||
@@ -54,7 +57,7 @@ def test_parse_encrypt_response_accepts_wcf_shapes() -> None:
|
||||
|
||||
|
||||
def test_note_play_html_and_js_path() -> None:
|
||||
reset_encrypt_config()
|
||||
_reset_encrypt()
|
||||
html = (
|
||||
'<script src="https://staticbdc1.yunxuetang.cn/SystemFiles/Js/'
|
||||
'kng_studytrack_rw.js?v=10.11.45"></script>'
|
||||
@@ -68,7 +71,7 @@ def test_note_play_html_and_js_path() -> None:
|
||||
|
||||
|
||||
def test_fetch_encryption_posts_player_body() -> None:
|
||||
reset_encrypt_config()
|
||||
_reset_encrypt()
|
||||
seen: dict[str, bytes] = {}
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
@@ -81,14 +84,18 @@ def test_fetch_encryption_posts_player_body() -> None:
|
||||
seen["body"] = request.content
|
||||
return httpx.Response(200, json={"Status": "OK", "Data": "b" * 32})
|
||||
|
||||
with httpx.Client(transport=httpx.MockTransport(handler)) as client:
|
||||
digest = fetch_encryption(
|
||||
client,
|
||||
'{"knowledgeId":"k1"}',
|
||||
origin="https://euniv.zte.com.cn",
|
||||
user_agent="UA",
|
||||
)
|
||||
assert digest == "b" * 32
|
||||
async def main() -> None:
|
||||
transport = httpx.MockTransport(handler)
|
||||
async with httpx.AsyncClient(transport=transport) as client:
|
||||
digest = await fetch_encryption_async(
|
||||
client,
|
||||
'{"knowledgeId":"k1"}',
|
||||
origin="https://euniv.zte.com.cn",
|
||||
user_agent="UA",
|
||||
)
|
||||
assert digest == "b" * 32
|
||||
|
||||
asyncio.run(main())
|
||||
assert seen["content_type"] == b"text/json"
|
||||
assert seen["body"] == b'{"body":"{\\"knowledgeId\\":\\"k1\\"}"}'
|
||||
|
||||
|
||||
@@ -15,6 +15,15 @@ class _Socket:
|
||||
self.payloads.append(payload)
|
||||
|
||||
|
||||
async def _until(done) -> None:
|
||||
loop = asyncio.get_running_loop()
|
||||
deadline = loop.time() + 1
|
||||
while not done():
|
||||
if loop.time() >= deadline:
|
||||
raise AssertionError("等待条件没有达成")
|
||||
await asyncio.sleep(0)
|
||||
|
||||
|
||||
def test_study_push_throttles_and_only_sends_latest(monkeypatch) -> None:
|
||||
socket = _Socket()
|
||||
monkeypatch.setattr("euniv.study_control.payload_for", lambda eid: {"eid": eid, "n": len(socket.payloads)})
|
||||
@@ -30,14 +39,13 @@ def test_study_push_throttles_and_only_sends_latest(monkeypatch) -> None:
|
||||
study_push.register("u1", socket)
|
||||
try:
|
||||
study_push.notify("u1")
|
||||
await asyncio.sleep(0.05)
|
||||
assert len(socket.payloads) == 1
|
||||
await _until(lambda: len(socket.payloads) == 1)
|
||||
study_push.notify("u1")
|
||||
await asyncio.sleep(0.05)
|
||||
await _until(lambda: "u1" in study_push._pending or len(socket.payloads) > 1)
|
||||
assert len(socket.payloads) == 1
|
||||
assert "u1" in study_push._pending
|
||||
study_push.notify("u1", urgent=True)
|
||||
await asyncio.sleep(0.05)
|
||||
assert len(socket.payloads) == 2
|
||||
await _until(lambda: len(socket.payloads) == 2)
|
||||
assert socket.payloads[-1]["eid"] == "u1"
|
||||
finally:
|
||||
for handle in list(study_push._pending.values()):
|
||||
|
||||
Reference in New Issue
Block a user