feat(backend): replace Selenium with Playwright

BREAKING CHANGE: backend now requires Python 3.12 or newer.
This commit is contained in:
2026-05-04 21:20:30 +08:00
parent fa07b340e7
commit d811c20932
15 changed files with 451 additions and 1570 deletions
+37
View File
@@ -0,0 +1,37 @@
from __future__ import annotations
from backend.workers.browser_automation import (
PlaywrightLaunchConfig,
extract_cookie_value,
extract_payload_header,
)
def test_payload_header_extraction_is_case_insensitive() -> None:
headers = {
"Accept": "application/json",
"X-API-Request-Payload": "live-signature",
}
assert extract_payload_header(headers) == "live-signature"
def test_payload_header_extraction_ignores_blank_values() -> None:
headers = {"x-api-request-payload": " "}
assert extract_payload_header(headers) is None
def test_cookie_value_extraction_finds_named_cookie() -> None:
cookies = [
{"name": "other", "value": "unused"},
{"name": "token", "value": "qq-token"},
]
assert extract_cookie_value(cookies, "token") == "qq-token"
def test_launch_config_uses_optional_executable_path() -> None:
config = PlaywrightLaunchConfig(executable_path="/usr/bin/chromium")
assert config.to_launch_kwargs()["executable_path"] == "/usr/bin/chromium"