1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-07-12 16:16:39 +01:00
Files
supervisor/tests/host/test_manager.py
T
Mike Degatano 7fd6dce55f Migrate to Ruff for lint and format (#4852)
* Migrate to Ruff for lint and format

* Fix pylint issues

* DBus property sets into normal awaitable methods

* Fix tests relying on separate tasks in connect

* Fixes from feedback
2024-02-05 11:37:39 -05:00

59 lines
2.0 KiB
Python

"""Test host manager."""
from unittest.mock import patch
from awesomeversion import AwesomeVersion
import pytest
from supervisor.coresys import CoreSys
from supervisor.dbus.const import MulticastProtocolEnabled
from tests.dbus_service_mocks.base import DBusServiceMock
from tests.dbus_service_mocks.systemd import Systemd as SystemdService
@pytest.fixture(name="systemd_service")
async def fixture_systemd_service(
all_dbus_services: dict[str, DBusServiceMock | dict[str, DBusServiceMock]],
) -> SystemdService:
"""Return systemd service mock."""
yield all_dbus_services["systemd"]
async def test_load(coresys: CoreSys, systemd_service: SystemdService):
"""Test manager load."""
systemd_service.ListUnits.calls.clear()
with patch.object(coresys.host.sound, "update") as sound_update:
await coresys.host.load()
assert coresys.dbus.hostname.hostname == "homeassistant-n2"
assert coresys.dbus.systemd.boot_timestamp == 1632236713344227
assert coresys.dbus.timedate.timezone == "Etc/UTC"
assert coresys.dbus.agent.diagnostics is True
assert coresys.dbus.network.connectivity_enabled is True
assert coresys.dbus.resolved.multicast_dns == MulticastProtocolEnabled.RESOLVE
assert coresys.dbus.agent.apparmor.version == "2.13.2"
assert len(coresys.host.logs.default_identifiers) > 0
assert coresys.dbus.udisks2.version == AwesomeVersion("2.9.2")
sound_update.assert_called_once()
assert systemd_service.ListUnits.calls == [()]
async def test_reload(coresys: CoreSys, systemd_service: SystemdService):
"""Test manager reload and ensure it does not unnecessarily recreate dbus objects."""
await coresys.host.load()
systemd_service.ListUnits.calls.clear()
with patch("supervisor.utils.dbus.DBus.connect") as connect, patch.object(
coresys.host.sound, "update"
) as sound_update:
await coresys.host.reload()
connect.assert_not_called()
sound_update.assert_called_once()
assert systemd_service.ListUnits.calls == [()]