Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Unit tests for the legacy pywebview desktop bridge."""
|
|
|
|
import io
|
|
import types
|
|
import urllib.request
|
|
|
|
from qwenpaw.cli import desktop_cmd
|
|
|
|
|
|
class _Response(io.BytesIO):
|
|
def __enter__(self) -> "_Response":
|
|
return self
|
|
|
|
def __exit__(self, *_args: object) -> None:
|
|
self.close()
|
|
|
|
|
|
def test_save_file_passes_headers_to_download_request(
|
|
monkeypatch,
|
|
tmp_path,
|
|
) -> None:
|
|
destination = tmp_path / "backup.zip"
|
|
monkeypatch.setattr(
|
|
desktop_cmd,
|
|
"webview",
|
|
types.SimpleNamespace(
|
|
SAVE_DIALOG=1,
|
|
windows=[
|
|
types.SimpleNamespace(
|
|
create_file_dialog=lambda *_args, **_kwargs: str(
|
|
destination,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
|
|
captured_url = ""
|
|
captured_headers: dict[str, str] = {}
|
|
|
|
def fake_urlopen(request: urllib.request.Request) -> _Response:
|
|
nonlocal captured_headers, captured_url
|
|
captured_url = request.full_url
|
|
captured_headers = {
|
|
key.lower(): value for key, value in request.header_items()
|
|
}
|
|
return _Response(b"zip")
|
|
|
|
monkeypatch.setattr(urllib.request, "urlopen", fake_urlopen)
|
|
|
|
saved = desktop_cmd.WebViewAPI().save_file(
|
|
"http://127.0.0.1:43123/api/backups/abc/export",
|
|
"backup.zip",
|
|
{"Authorization": "Bearer tok", "X-Agent-Id": "agent-a"},
|
|
)
|
|
|
|
assert saved is True
|
|
assert destination.read_bytes() == b"zip"
|
|
assert captured_url == "http://127.0.0.1:43123/api/backups/abc/export"
|
|
assert captured_headers["authorization"] == "Bearer tok"
|
|
assert captured_headers["x-agent-id"] == "agent-a"
|