Persist web UI translation settings

This commit is contained in:
2026-05-22 20:33:00 +01:00
parent 82d5c3c173
commit 665ea41c65
3 changed files with 133 additions and 7 deletions

View File

@@ -4,7 +4,8 @@ from __future__ import annotations
import sys
from web_app import build_pipeline_command, create_app
import web_app
from web_app import build_pipeline_command, create_app, load_translation_settings, save_translation_settings
def test_build_pipeline_command_uses_cli_parser_defaults():
@@ -42,3 +43,37 @@ def test_create_app_builds_gradio_blocks():
app = create_app()
assert app.title == "Gradio YouTube Auto Dub"
def test_save_and_load_translation_settings(tmp_path, monkeypatch):
settings_file = tmp_path / "web_settings.json"
monkeypatch.setattr(web_app, "SETTINGS_FILE", settings_file)
base_url, api_key, model, message = save_translation_settings(
"http://openai-compatible.local:8080/v1",
"secret-key",
"custom-model",
)
assert base_url == "http://openai-compatible.local:8080/v1"
assert api_key == "secret-key"
assert model == "custom-model"
assert str(settings_file) in message
assert load_translation_settings() == {
"base_url": "http://openai-compatible.local:8080/v1",
"api_key": "secret-key",
"model": "custom-model",
}
def test_load_translation_settings_uses_env_defaults(tmp_path, monkeypatch):
monkeypatch.setattr(web_app, "SETTINGS_FILE", tmp_path / "missing.json")
monkeypatch.setenv("LM_STUDIO_BASE_URL", "http://env-host:1234/v1")
monkeypatch.setenv("LM_STUDIO_API_KEY", "env-key")
monkeypatch.setenv("LM_STUDIO_MODEL", "env-model")
assert load_translation_settings() == {
"base_url": "http://env-host:1234/v1",
"api_key": "env-key",
"model": "env-model",
}