Add cookie file upload

This commit is contained in:
2026-05-22 20:47:21 +01:00
parent a25a60f217
commit 75522ede50
3 changed files with 67 additions and 8 deletions

View File

@@ -5,7 +5,13 @@ from __future__ import annotations
import sys
import web_app
from web_app import build_pipeline_command, create_app, load_translation_settings, save_translation_settings
from web_app import (
_stage_uploaded_cookies,
build_pipeline_command,
create_app,
load_translation_settings,
save_translation_settings,
)
def test_build_pipeline_command_uses_cli_parser_defaults():
@@ -91,3 +97,29 @@ def test_load_translation_settings_uses_env_defaults(tmp_path, monkeypatch):
"api_key": "env-key",
"model": "env-model",
}
def test_stage_uploaded_cookies_copies_to_upload_dir(tmp_path, monkeypatch):
upload_dir = tmp_path / "uploads"
source_file = tmp_path / "cookies.txt"
source_file.write_text("# Netscape HTTP Cookie File\n", encoding="utf-8")
monkeypatch.setattr(web_app, "UPLOAD_DIR", upload_dir)
staged_path = _stage_uploaded_cookies(str(source_file))
assert staged_path.endswith(".txt")
assert staged_path != str(source_file)
assert upload_dir in web_app.Path(staged_path).parents
assert web_app.Path(staged_path).read_text(encoding="utf-8") == "# Netscape HTTP Cookie File\n"
def test_stage_uploaded_cookies_rejects_unsupported_extension(tmp_path):
source_file = tmp_path / "cookies.json"
source_file.write_text("{}", encoding="utf-8")
try:
_stage_uploaded_cookies(str(source_file))
except ValueError as exc:
assert "Expected one of" in str(exc)
else:
raise AssertionError("Expected ValueError for unsupported cookie upload")