mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-10 03:19:37 +00:00
Trigger auto-update through Core WebSocket call (#5896)
* Trigger auto-update through Core WebSocket call Instead of auto-updating add-ons on Supervisor side trigger an update through Core via a WebSocket command. This makes sure that the backup is categorized correctly and all backup features like retention are applied. * Add pytest * Fix pytest * Fix pytest * Fix pytest * Fix pytest * Fix pytest cleaner * Set timestamp of add-on far into the past
This commit is contained in:
@@ -8,7 +8,8 @@ from unittest.mock import AsyncMock, MagicMock, Mock, PropertyMock, patch
|
||||
from awesomeversion import AwesomeVersion
|
||||
import pytest
|
||||
|
||||
from supervisor.const import CoreState
|
||||
from supervisor.addons.addon import Addon
|
||||
from supervisor.const import ATTR_VERSION_TIMESTAMP, CoreState
|
||||
from supervisor.coresys import CoreSys
|
||||
from supervisor.exceptions import HomeAssistantError
|
||||
from supervisor.homeassistant.api import HomeAssistantAPI
|
||||
@@ -230,3 +231,37 @@ async def test_core_backup_cleanup(
|
||||
assert not coresys.backups.get("7fed74c8")
|
||||
assert new_tar.exists()
|
||||
assert not old_tar.exists()
|
||||
|
||||
|
||||
async def test_update_addons_auto_update_success(
|
||||
tasks: Tasks,
|
||||
coresys: CoreSys,
|
||||
tmp_supervisor_data: Path,
|
||||
ha_ws_client: AsyncMock,
|
||||
install_addon_example: Addon,
|
||||
):
|
||||
"""Test that an eligible add-on is auto-updated via websocket command."""
|
||||
await coresys.core.set_state(CoreState.RUNNING)
|
||||
|
||||
# Set up the add-on as eligible for auto-update
|
||||
install_addon_example.auto_update = True
|
||||
install_addon_example.data_store[ATTR_VERSION_TIMESTAMP] = 0
|
||||
with patch.object(
|
||||
Addon, "version", new=PropertyMock(return_value=AwesomeVersion("1.0"))
|
||||
):
|
||||
assert install_addon_example.need_update is True
|
||||
assert install_addon_example.auto_update_available is True
|
||||
|
||||
# Make sure all job events from installing the add-on are cleared
|
||||
ha_ws_client.async_send_command.reset_mock()
|
||||
|
||||
# pylint: disable-next=protected-access
|
||||
await tasks._update_addons()
|
||||
|
||||
ha_ws_client.async_send_command.assert_any_call(
|
||||
{
|
||||
"type": "hassio/update/addon",
|
||||
"addon": install_addon_example.slug,
|
||||
"backup": True,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user