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")
|
||||
|
|
|
|||
|
|
@ -16,6 +16,17 @@ def update_manager(tmp_path):
|
|||
return UpdateManager(current_version="0.0.1", config_dir=tmp_path)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def agravity_update_manager(tmp_path):
|
||||
"""Create a brand-aware UpdateManager instance for Agravity Bridge."""
|
||||
return UpdateManager(
|
||||
current_version="0.0.1",
|
||||
config_dir=tmp_path,
|
||||
brand_id="agravity",
|
||||
update_channel="stable",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_release():
|
||||
"""Sample release data from API."""
|
||||
|
|
@ -252,6 +263,109 @@ class TestDownloading:
|
|||
|
||||
assert result is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_download_update_uses_release_manifest(self, agravity_update_manager, tmp_path):
|
||||
"""Test branded download selection from a shared release manifest."""
|
||||
release = Release(
|
||||
tag_name="v0.0.2",
|
||||
name="WebDropBridge v0.0.2",
|
||||
version="0.0.2",
|
||||
body="Release notes",
|
||||
assets=[
|
||||
{
|
||||
"name": "AgravityBridge-0.0.2-win-x64.msi",
|
||||
"browser_download_url": "https://example.com/AgravityBridge-0.0.2-win-x64.msi",
|
||||
},
|
||||
{
|
||||
"name": "AgravityBridge-0.0.2-win-x64.msi.sha256",
|
||||
"browser_download_url": "https://example.com/AgravityBridge-0.0.2-win-x64.msi.sha256",
|
||||
},
|
||||
{
|
||||
"name": "OtherBridge-0.0.2-win-x64.msi",
|
||||
"browser_download_url": "https://example.com/OtherBridge-0.0.2-win-x64.msi",
|
||||
},
|
||||
{
|
||||
"name": "release-manifest.json",
|
||||
"browser_download_url": "https://example.com/release-manifest.json",
|
||||
},
|
||||
],
|
||||
published_at="2026-01-29T10:00:00Z",
|
||||
)
|
||||
|
||||
manifest = {
|
||||
"version": "0.0.2",
|
||||
"channel": "stable",
|
||||
"brands": {
|
||||
"agravity": {
|
||||
"windows-x64": {
|
||||
"installer": "AgravityBridge-0.0.2-win-x64.msi",
|
||||
"checksum": "AgravityBridge-0.0.2-win-x64.msi.sha256",
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
with (
|
||||
patch.object(UpdateManager, "_download_json_asset", return_value=manifest),
|
||||
patch.object(UpdateManager, "_download_file", return_value=True) as mock_download,
|
||||
):
|
||||
result = await agravity_update_manager.download_update(release, tmp_path)
|
||||
|
||||
assert result is not None
|
||||
assert result.name == "AgravityBridge-0.0.2-win-x64.msi"
|
||||
mock_download.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_verify_checksum_uses_release_manifest(self, agravity_update_manager, tmp_path):
|
||||
"""Test branded checksum selection from a shared release manifest."""
|
||||
test_file = tmp_path / "AgravityBridge-0.0.2-win-x64.msi"
|
||||
test_file.write_bytes(b"test content")
|
||||
|
||||
import hashlib
|
||||
|
||||
checksum = hashlib.sha256(b"test content").hexdigest()
|
||||
release = Release(
|
||||
tag_name="v0.0.2",
|
||||
name="WebDropBridge v0.0.2",
|
||||
version="0.0.2",
|
||||
body="Release notes",
|
||||
assets=[
|
||||
{
|
||||
"name": "AgravityBridge-0.0.2-win-x64.msi",
|
||||
"browser_download_url": "https://example.com/AgravityBridge-0.0.2-win-x64.msi",
|
||||
},
|
||||
{
|
||||
"name": "AgravityBridge-0.0.2-win-x64.msi.sha256",
|
||||
"browser_download_url": "https://example.com/AgravityBridge-0.0.2-win-x64.msi.sha256",
|
||||
},
|
||||
{
|
||||
"name": "release-manifest.json",
|
||||
"browser_download_url": "https://example.com/release-manifest.json",
|
||||
},
|
||||
],
|
||||
published_at="2026-01-29T10:00:00Z",
|
||||
)
|
||||
manifest = {
|
||||
"version": "0.0.2",
|
||||
"channel": "stable",
|
||||
"brands": {
|
||||
"agravity": {
|
||||
"windows-x64": {
|
||||
"installer": "AgravityBridge-0.0.2-win-x64.msi",
|
||||
"checksum": "AgravityBridge-0.0.2-win-x64.msi.sha256",
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
with (
|
||||
patch.object(UpdateManager, "_download_json_asset", return_value=manifest),
|
||||
patch.object(UpdateManager, "_download_checksum", return_value=checksum),
|
||||
):
|
||||
result = await agravity_update_manager.verify_checksum(test_file, release)
|
||||
|
||||
assert result is True
|
||||
|
||||
|
||||
class TestChecksumVerification:
|
||||
"""Test checksum verification."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue