mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-24 12:29:08 +00:00
Create repair issue when user has deprecated add-on installed (#6110)
* Initial plan * Add deprecated addon repair issue check Co-authored-by: agners <34061+agners@users.noreply.github.com> * Apply ruff format * Add remove suggestion Co-authored-by: Mike Degatano <michael.degatano@gmail.com> * Update tests/resolution/check/test_check_deprecated_addon.py Co-authored-by: Mike Degatano <michael.degatano@gmail.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: agners <34061+agners@users.noreply.github.com> Co-authored-by: Stefan Agner <stefan@agner.ch> Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
This commit is contained in:
75
tests/resolution/check/test_check_deprecated_addon.py
Normal file
75
tests/resolution/check/test_check_deprecated_addon.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""Test check for deprecated addons."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from supervisor.addons.addon import Addon
|
||||
from supervisor.const import AddonStage, CoreState
|
||||
from supervisor.coresys import CoreSys
|
||||
from supervisor.resolution.checks.deprecated_addon import CheckDeprecatedAddon
|
||||
from supervisor.resolution.const import ContextType, IssueType
|
||||
|
||||
|
||||
async def test_base(coresys: CoreSys):
|
||||
"""Test check basics."""
|
||||
deprecated_addon = CheckDeprecatedAddon(coresys)
|
||||
assert deprecated_addon.slug == "deprecated_addon"
|
||||
assert deprecated_addon.enabled
|
||||
|
||||
|
||||
async def test_check(coresys: CoreSys, install_addon_ssh: Addon):
|
||||
"""Test check for deprecated addons."""
|
||||
deprecated_addon = CheckDeprecatedAddon(coresys)
|
||||
await coresys.core.set_state(CoreState.SETUP)
|
||||
|
||||
await deprecated_addon()
|
||||
assert len(coresys.resolution.issues) == 0
|
||||
|
||||
# Mock test addon as deprecated
|
||||
install_addon_ssh.data["stage"] = AddonStage.DEPRECATED
|
||||
|
||||
await deprecated_addon()
|
||||
|
||||
assert len(coresys.resolution.issues) == 1
|
||||
assert coresys.resolution.issues[0].type is IssueType.DEPRECATED_ADDON
|
||||
assert coresys.resolution.issues[0].context is ContextType.ADDON
|
||||
assert coresys.resolution.issues[0].reference == install_addon_ssh.slug
|
||||
assert len(coresys.resolution.suggestions) == 1
|
||||
|
||||
|
||||
async def test_approve(coresys: CoreSys, install_addon_ssh: Addon):
|
||||
"""Test approve existing deprecated addon issues."""
|
||||
deprecated_addon = CheckDeprecatedAddon(coresys)
|
||||
await coresys.core.set_state(CoreState.SETUP)
|
||||
|
||||
assert (
|
||||
await deprecated_addon.approve_check(reference=install_addon_ssh.slug) is False
|
||||
)
|
||||
|
||||
# Mock test addon as deprecated
|
||||
install_addon_ssh.data["stage"] = AddonStage.DEPRECATED
|
||||
|
||||
assert (
|
||||
await deprecated_addon.approve_check(reference=install_addon_ssh.slug) is True
|
||||
)
|
||||
|
||||
|
||||
async def test_did_run(coresys: CoreSys):
|
||||
"""Test that the check ran as expected."""
|
||||
deprecated_addon = CheckDeprecatedAddon(coresys)
|
||||
should_run = deprecated_addon.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(CheckDeprecatedAddon, "run_check", return_value=None) as check:
|
||||
for state in should_run:
|
||||
await coresys.core.set_state(state)
|
||||
await deprecated_addon()
|
||||
check.assert_called_once()
|
||||
check.reset_mock()
|
||||
|
||||
for state in should_not_run:
|
||||
await coresys.core.set_state(state)
|
||||
await deprecated_addon()
|
||||
check.assert_not_called()
|
||||
check.reset_mock()
|
||||
Reference in New Issue
Block a user