1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-05-19 22:28:52 +01:00
Files
supervisor/tests/api/test_root.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

98 lines
2.6 KiB
Python

"""Test Supervisor API."""
# pylint: disable=protected-access
from unittest.mock import AsyncMock, patch
from aiohttp.test_utils import TestClient
from supervisor.api.const import ATTR_AVAILABLE_UPDATES
from supervisor.coresys import CoreSys
from tests.const import TEST_ADDON_SLUG
async def test_api_info(api_client):
"""Test docker info api."""
resp = await api_client.get("/info")
result = await resp.json()
assert result["data"]["supervisor"] == "9999.09.9.dev9999"
assert result["data"]["docker"] == "1.0.0"
assert result["data"]["supported"] is True
assert result["data"]["channel"] == "stable"
assert result["data"]["logging"] == "info"
assert result["data"]["timezone"] == "Etc/UTC"
async def test_api_available_updates(
install_app_ssh,
api_client,
coresys: CoreSys,
):
"""Test available_updates."""
installed_app = coresys.apps.get(TEST_ADDON_SLUG)
installed_app.persist["version"] = "1.2.3"
async def available_updates():
return (await (await api_client.get("/available_updates")).json())["data"][
ATTR_AVAILABLE_UPDATES
]
updates = await available_updates()
assert len(updates) == 1
assert updates[-1] == {
"icon": None,
"name": "Terminal & SSH",
"panel_path": "/update-available/local_ssh",
"update_type": "addon",
"version_latest": "9.2.1",
}
coresys.updater._data["hassos_unrestricted"] = "321"
coresys.os._version = "123"
updates = await available_updates()
assert len(updates) == 2
assert updates[0] == {
"panel_path": "/update-available/os",
"update_type": "os",
"version_latest": "321",
}
coresys.updater._data["homeassistant"] = "321"
coresys.homeassistant.version = "123"
updates = await available_updates()
assert len(updates) == 3
assert updates[0] == {
"panel_path": "/update-available/core",
"update_type": "core",
"version_latest": "321",
}
async def test_api_refresh_updates(api_client, coresys: CoreSys):
"""Test docker info api."""
coresys.updater.reload = AsyncMock()
coresys.store.reload = AsyncMock()
resp = await api_client.post("/refresh_updates")
assert resp.status == 200
assert coresys.updater.reload.called
assert coresys.store.reload.called
async def test_api_reload_updates(
coresys: CoreSys,
api_client: TestClient,
):
"""Test reload updates."""
with (
patch("supervisor.updater.Updater.fetch_data") as fetch_data,
):
resp = await api_client.post("/reload_updates")
fetch_data.assert_called_once_with()
assert resp.status == 200