74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
"""Tests for runtime branding template management."""
|
|
|
|
from webdrop_bridge.config import Config
|
|
from webdrop_bridge.core.branding_manager import BrandingManager
|
|
|
|
|
|
def test_builtin_brandings_are_available(tmp_path):
|
|
"""Built-in default and Agravity templates should always be available."""
|
|
manager = BrandingManager(base_dir=tmp_path)
|
|
|
|
brandings = manager.list_templates()
|
|
template_ids = [template.template_id for template in brandings]
|
|
|
|
assert "default" in template_ids
|
|
assert "agravity" in template_ids
|
|
|
|
|
|
def test_active_branding_persists_across_manager_instances(tmp_path):
|
|
"""Selected active branding should persist on disk."""
|
|
manager = BrandingManager(base_dir=tmp_path)
|
|
manager.set_active_branding_id("agravity")
|
|
|
|
reloaded_manager = BrandingManager(base_dir=tmp_path)
|
|
|
|
assert reloaded_manager.get_active_branding_id() == "agravity"
|
|
|
|
|
|
def test_apply_branding_updates_cosmetic_fields_only(tmp_path):
|
|
"""Applying a branding template should not overwrite setup-specific values."""
|
|
allowed_root = tmp_path / "allowed"
|
|
allowed_root.mkdir()
|
|
|
|
config = Config(
|
|
app_name="WebDrop Bridge",
|
|
app_version="1.0.0",
|
|
log_level="INFO",
|
|
log_file=None,
|
|
allowed_roots=[allowed_root],
|
|
allowed_urls=["example.com"],
|
|
webapp_url="http://localhost:8080",
|
|
window_width=1024,
|
|
window_height=768,
|
|
enable_logging=True,
|
|
active_branding_id="agravity",
|
|
)
|
|
|
|
manager = BrandingManager(base_dir=tmp_path)
|
|
manager.apply_to_config(config)
|
|
|
|
assert config.active_branding_id == "agravity"
|
|
assert config.app_name == "Agravity Bridge"
|
|
assert config.webapp_url == "http://localhost:8080"
|
|
assert config.allowed_roots == [allowed_root]
|
|
assert config.toolbar_icon_home.endswith("home.ico")
|
|
|
|
|
|
def test_config_from_env_uses_persisted_active_branding(tmp_path, monkeypatch):
|
|
"""Config loading should apply the persisted active branding automatically."""
|
|
branding_dir = tmp_path / "branding-state"
|
|
manager = BrandingManager(base_dir=branding_dir)
|
|
manager.set_active_branding_id("agravity")
|
|
|
|
monkeypatch.setenv("WEBDROP_BRANDING_DIR", str(branding_dir))
|
|
|
|
root = tmp_path / "root"
|
|
root.mkdir()
|
|
env_file = tmp_path / ".env"
|
|
env_file.write_text(f"ALLOWED_ROOTS={root}\n", encoding="utf-8")
|
|
|
|
config = Config.from_env(str(env_file))
|
|
|
|
assert config.active_branding_id == "agravity"
|
|
assert config.app_name == "Agravity Bridge"
|
|
assert config.get_config_path().name == "config.json"
|