mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-05-20 06:38:53 +01:00
ba8c49935b
* Rename addon→app in docstrings and comments Updates all docstrings and inline comments across supervisor/ and tests/ to use the new app/apps terminology. No runtime behaviour is changed by this commit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename addon→app in code (variables, args, class names, functions) Renames all internal Python identifiers from addon/addons to app/apps: - Variable and argument names - Function and method names - Class names (Addon→App, AddonManager→AppManager, DockerAddon→DockerApp, all exception, check, and fixup classes, etc.) - String literals used as Python identifiers (pytest fixtures, parametrize param names, patch.object attribute strings, URL route match_info keys) External API contracts are preserved: JSON keys, error codes, discovery protocol fields, TypedDict/attr.s field names. Import module paths (supervisor/addons/) are also unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix partial backup/restore API to remap addons key to apps The external API accepts `addons` as the request body key (since ATTR_APPS = "addons"), but do_backup_partial and do_restore_partial now take an `apps` parameter after the rename. The **body expansion in both endpoints would pass `addons=...` causing a TypeError. Remap the key before expansion in both backup_partial and restore_partial: if ATTR_APPS in body: body["apps"] = body.pop(ATTR_APPS) Also adds test_restore_partial_with_addons_key to verify the restore path correctly receives apps= when addons is passed in the request body. This path had no existing test coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix merge error * Adjust AppLoggerAdapter to use app_name Co-authored-by: Stefan Agner <stefan@agner.ch> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Stefan Agner <stefan@agner.ch>
100 lines
3.5 KiB
Python
100 lines
3.5 KiB
Python
"""Mock test."""
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from supervisor.backups.backup import BackupLocation
|
|
from supervisor.backups.const import LOCATION_CLOUD_BACKUP, LOCATION_TYPE, BackupType
|
|
from supervisor.backups.validate import ALL_FOLDERS
|
|
from supervisor.coresys import CoreSys
|
|
from supervisor.mounts.mount import Mount
|
|
|
|
from tests.const import TEST_ADDON_SLUG
|
|
|
|
|
|
@pytest.fixture(name="backup_mock")
|
|
def fixture_backup_mock():
|
|
"""Backup class mock."""
|
|
with patch("supervisor.backups.manager.Backup") as backup_mock:
|
|
backup_instance = MagicMock()
|
|
backup_mock.return_value = backup_instance
|
|
|
|
backup_instance.store_apps = AsyncMock(return_value=None)
|
|
backup_instance.store_folders = AsyncMock(return_value=None)
|
|
backup_instance.store_homeassistant = AsyncMock(return_value=None)
|
|
backup_instance.store_apps = AsyncMock(return_value=None)
|
|
backup_instance.store_supervisor_config = AsyncMock(return_value=None)
|
|
backup_instance.restore_folders = AsyncMock(return_value=True)
|
|
backup_instance.restore_homeassistant = AsyncMock(return_value=None)
|
|
backup_instance.restore_apps = AsyncMock(return_value=(True, []))
|
|
backup_instance.restore_repositories = AsyncMock(return_value=None)
|
|
backup_instance.restore_supervisor_config = AsyncMock(return_value=(True, []))
|
|
backup_instance.remove_delta_apps = AsyncMock(return_value=True)
|
|
|
|
yield backup_mock
|
|
|
|
|
|
@pytest.fixture
|
|
def partial_backup_mock(backup_mock):
|
|
"""Partial backup mock."""
|
|
backup_instance = backup_mock.return_value
|
|
backup_instance.sys_type = BackupType.PARTIAL
|
|
backup_instance.folders = []
|
|
backup_instance.app_list = [TEST_ADDON_SLUG]
|
|
backup_instance.supervisor_version = "9999.09.9.dev9999"
|
|
backup_instance.location = None
|
|
backup_instance.all_locations = {
|
|
None: BackupLocation(path=Path("/"), protected=False, size_bytes=0)
|
|
}
|
|
backup_instance.validate_backup = AsyncMock()
|
|
yield backup_mock
|
|
|
|
|
|
@pytest.fixture
|
|
def full_backup_mock(backup_mock):
|
|
"""Full backup mock."""
|
|
backup_instance = backup_mock.return_value
|
|
backup_instance.sys_type = BackupType.FULL
|
|
backup_instance.folders = ALL_FOLDERS
|
|
backup_instance.app_list = [TEST_ADDON_SLUG]
|
|
backup_instance.supervisor_version = "9999.09.9.dev9999"
|
|
backup_instance.location = None
|
|
backup_instance.all_locations = {
|
|
None: BackupLocation(path=Path("/"), protected=False, size_bytes=0)
|
|
}
|
|
backup_instance.validate_backup = AsyncMock()
|
|
yield backup_mock
|
|
|
|
|
|
@pytest.fixture(name="backup_locations")
|
|
async def fixture_backup_locations(
|
|
request: pytest.FixtureRequest, coresys: CoreSys, mount_propagation, mock_is_mount
|
|
) -> list[LOCATION_TYPE]:
|
|
"""Return a list of prcoessed backup locations."""
|
|
locations: list[LOCATION_TYPE] = []
|
|
loaded = False
|
|
for location in request.param:
|
|
if location in {None, LOCATION_CLOUD_BACKUP}:
|
|
locations.append(location)
|
|
else:
|
|
if not loaded:
|
|
await coresys.mounts.load()
|
|
|
|
await coresys.mounts.create_mount(
|
|
Mount.from_dict(
|
|
coresys,
|
|
{
|
|
"name": location,
|
|
"usage": "backup",
|
|
"type": "cifs",
|
|
"server": "test.local",
|
|
"share": "test",
|
|
},
|
|
)
|
|
)
|
|
locations.append(coresys.mounts.get(location))
|
|
|
|
return locations
|