feat: implement brand-specific configuration and update management for Agravity Bridge
This commit is contained in:
parent
baf56e040f
commit
b988532aaa
9 changed files with 461 additions and 48 deletions
|
|
@ -12,14 +12,26 @@ def clear_env():
|
|||
"""Clear environment variables before each test to avoid persistence."""
|
||||
# Save current env
|
||||
saved_env = os.environ.copy()
|
||||
|
||||
|
||||
# Clear relevant variables
|
||||
for key in list(os.environ.keys()):
|
||||
if key.startswith(('APP_', 'LOG_', 'ALLOWED_', 'WEBAPP_', 'WINDOW_', 'ENABLE_')):
|
||||
if key.startswith(
|
||||
(
|
||||
"APP_",
|
||||
"LOG_",
|
||||
"ALLOWED_",
|
||||
"WEBAPP_",
|
||||
"WINDOW_",
|
||||
"ENABLE_",
|
||||
"BRAND_",
|
||||
"UPDATE_",
|
||||
"LANGUAGE",
|
||||
)
|
||||
):
|
||||
del os.environ[key]
|
||||
|
||||
|
||||
yield
|
||||
|
||||
|
||||
# Restore env (cleanup)
|
||||
os.environ.clear()
|
||||
os.environ.update(saved_env)
|
||||
|
|
@ -64,6 +76,28 @@ class TestConfigFromEnv:
|
|||
assert config.window_width == 1200
|
||||
assert config.window_height == 800
|
||||
|
||||
def test_from_env_with_branding_values(self, tmp_path):
|
||||
"""Test loading branding and update metadata from environment."""
|
||||
env_file = tmp_path / ".env"
|
||||
root1 = tmp_path / "root1"
|
||||
root1.mkdir()
|
||||
env_file.write_text(
|
||||
f"BRAND_ID=agravity\n"
|
||||
f"APP_CONFIG_DIR_NAME=agravity_bridge\n"
|
||||
f"UPDATE_REPO=HIM-public/webdrop-bridge\n"
|
||||
f"UPDATE_CHANNEL=stable\n"
|
||||
f"UPDATE_MANIFEST_NAME=release-manifest.json\n"
|
||||
f"ALLOWED_ROOTS={root1}\n"
|
||||
)
|
||||
|
||||
config = Config.from_env(str(env_file))
|
||||
|
||||
assert config.brand_id == "agravity"
|
||||
assert config.config_dir_name == "agravity_bridge"
|
||||
assert config.update_repo == "HIM-public/webdrop-bridge"
|
||||
assert config.update_channel == "stable"
|
||||
assert config.update_manifest_name == "release-manifest.json"
|
||||
|
||||
def test_from_env_with_defaults(self, tmp_path):
|
||||
"""Test loading config uses defaults when env vars not set."""
|
||||
# Create empty .env file
|
||||
|
|
@ -73,8 +107,11 @@ class TestConfigFromEnv:
|
|||
config = Config.from_env(str(env_file))
|
||||
|
||||
assert config.app_name == "WebDrop Bridge"
|
||||
assert config.brand_id == "webdrop_bridge"
|
||||
assert config.config_dir_name == "webdrop_bridge"
|
||||
# Version should come from __init__.py (dynamic, not hardcoded)
|
||||
from webdrop_bridge import __version__
|
||||
|
||||
assert config.app_version == __version__
|
||||
assert config.log_level == "INFO"
|
||||
assert config.window_width == 1024
|
||||
|
|
@ -187,3 +224,11 @@ class TestConfigValidation:
|
|||
config = Config.from_env(str(env_file))
|
||||
|
||||
assert config.allowed_urls == ["example.com", "test.org"]
|
||||
|
||||
def test_brand_specific_default_paths(self):
|
||||
"""Test brand-specific config and log directories."""
|
||||
config_path = Config.get_default_config_path("agravity_bridge")
|
||||
log_path = Config.get_default_log_path("agravity_bridge")
|
||||
|
||||
assert config_path.parts[-2:] == ("agravity_bridge", "config.json")
|
||||
assert log_path.parts[-2:] == ("logs", "agravity_bridge.log")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue