Preserve masked secrets on settings save, tolerate malformed background add requests, escape background catalog values, and skip terminal clearing when TERM is unset. Tested: rtk docker compose run --rm testpull/2550/head
parent
6c37d42e43
commit
d3fdd4145b
@ -0,0 +1,30 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from GUI import app
|
||||
|
||||
|
||||
def test_background_add_handles_missing_form_fields():
|
||||
app.testing = False
|
||||
|
||||
response = app.test_client().post("/background/add", data={})
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.headers["Location"].endswith("/backgrounds")
|
||||
|
||||
|
||||
def test_background_add_passes_empty_defaults_for_missing_optional_fields():
|
||||
app.testing = True
|
||||
|
||||
with patch("GUI.gui.add_background") as add_background:
|
||||
response = app.test_client().post(
|
||||
"/background/add",
|
||||
data={"youtube_uri": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"},
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
add_background.assert_called_once_with(
|
||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
)
|
||||
@ -0,0 +1,34 @@
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
import main
|
||||
|
||||
|
||||
def test_clear_screen_skips_clear_without_term(monkeypatch):
|
||||
monkeypatch.delenv("TERM", raising=False)
|
||||
monkeypatch.setattr(main, "name", "posix")
|
||||
|
||||
with patch("main.subprocess.run") as run:
|
||||
main.clear_screen()
|
||||
|
||||
run.assert_not_called()
|
||||
|
||||
|
||||
def test_clear_screen_runs_when_term_is_set(monkeypatch):
|
||||
monkeypatch.setenv("TERM", "xterm")
|
||||
monkeypatch.setattr(main, "name", "posix")
|
||||
|
||||
with patch("main.subprocess.run") as run:
|
||||
main.clear_screen()
|
||||
|
||||
run.assert_called_once_with(["clear"], shell=False)
|
||||
|
||||
|
||||
def test_clear_screen_runs_windows_command(monkeypatch):
|
||||
monkeypatch.delenv("TERM", raising=False)
|
||||
monkeypatch.setattr(main, "name", "nt")
|
||||
|
||||
with patch("main.subprocess.run") as run:
|
||||
main.clear_screen()
|
||||
|
||||
run.assert_called_once_with(["cls"], shell=True)
|
||||
@ -0,0 +1,10 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_backgrounds_template_escapes_catalog_values_before_inner_html():
|
||||
template = Path("GUI/backgrounds.html").read_text(encoding="utf-8")
|
||||
|
||||
assert "function h(str)" in template
|
||||
assert "title=\"${h(key)}\"" in template
|
||||
assert "${h(key)}" in template
|
||||
assert "${h(value[2])}" in template
|
||||
Loading…
Reference in new issue