1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-05-20 14:48:54 +01:00
Files
supervisor/tests/resolution/check/test_check_detached_addon_missing.py
T
Mike Degatano ba8c49935b Refactor internal addon references to app/apps (#6717)
* 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>
2026-04-14 16:47:20 +02:00

83 lines
3.1 KiB
Python

"""Test check for detached apps due to repo missing."""
from unittest.mock import patch
from supervisor.addons.addon import App
from supervisor.const import CoreState
from supervisor.coresys import CoreSys
from supervisor.resolution.checks.detached_addon_missing import CheckDetachedAppMissing
from supervisor.resolution.const import ContextType, IssueType
async def test_base(coresys: CoreSys):
"""Test check basics."""
detached_app_missing = CheckDetachedAppMissing(coresys)
assert detached_app_missing.slug == "detached_addon_missing"
assert detached_app_missing.enabled
async def test_check(coresys: CoreSys, install_app_ssh: App):
"""Test check for detached apps."""
detached_app_missing = CheckDetachedAppMissing(coresys)
await coresys.core.set_state(CoreState.SETUP)
await detached_app_missing()
assert len(coresys.resolution.issues) == 0
# Mock test app was been installed from a now non-existent store
install_app_ssh.slug = "abc123_ssh"
coresys.apps.data.system["abc123_ssh"] = coresys.apps.data.system["local_ssh"]
coresys.apps.local["abc123_ssh"] = coresys.apps.local["local_ssh"]
install_app_ssh.data["repository"] = "abc123"
await detached_app_missing()
assert len(coresys.resolution.issues) == 1
assert coresys.resolution.issues[0].type is IssueType.DETACHED_ADDON_MISSING
assert coresys.resolution.issues[0].context is ContextType.ADDON
assert coresys.resolution.issues[0].reference == install_app_ssh.slug
assert len(coresys.resolution.suggestions) == 0
async def test_approve(coresys: CoreSys, install_app_ssh: App):
"""Test approve existing detached app issues."""
detached_app_missing = CheckDetachedAppMissing(coresys)
await coresys.core.set_state(CoreState.SETUP)
assert (
await detached_app_missing.approve_check(reference=install_app_ssh.slug)
is False
)
# Mock test app was been installed from a now non-existent store
install_app_ssh.slug = "abc123_ssh"
coresys.apps.data.system["abc123_ssh"] = coresys.apps.data.system["local_ssh"]
coresys.apps.local["abc123_ssh"] = coresys.apps.local["local_ssh"]
install_app_ssh.data["repository"] = "abc123"
assert (
await detached_app_missing.approve_check(reference=install_app_ssh.slug) is True
)
async def test_did_run(coresys: CoreSys):
"""Test that the check ran as expected."""
detached_app_missing = CheckDetachedAppMissing(coresys)
should_run = detached_app_missing.states
should_not_run = [state for state in CoreState if state not in should_run]
assert should_run == [CoreState.SETUP]
assert len(should_not_run) != 0
with patch.object(CheckDetachedAppMissing, "run_check", return_value=None) as check:
for state in should_run:
await coresys.core.set_state(state)
await detached_app_missing()
check.assert_called_once()
check.reset_mock()
for state in should_not_run:
await coresys.core.set_state(state)
await detached_app_missing()
check.assert_not_called()
check.reset_mock()