Adjust tests for removing github devices (#64448)
This commit is contained in:
parent
9facd3962c
commit
554e51017e
4 changed files with 72 additions and 41 deletions
|
@ -1,31 +1,46 @@
|
|||
"""Test the GitHub init file."""
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
from homeassistant.components.github import async_cleanup_device_registry
|
||||
from homeassistant.components.github.const import DOMAIN
|
||||
from homeassistant.components.github.const import CONF_REPOSITORIES
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from tests.common import MockConfigEntry, mock_device_registry
|
||||
from .common import setup_github_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
async def test_device_registry_cleanup(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
caplog: LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that we remove untracked repositories from the decvice registry."""
|
||||
registry = mock_device_registry(hass)
|
||||
mock_config_entry.options = {CONF_REPOSITORIES: ["home-assistant/core"]}
|
||||
await setup_github_integration(hass, mock_config_entry, aioclient_mock)
|
||||
|
||||
device = registry.async_get_or_create(
|
||||
identifiers={(DOMAIN, "test/repository")},
|
||||
device_registry = dr.async_get(hass)
|
||||
devices = dr.async_entries_for_config_entry(
|
||||
registry=device_registry,
|
||||
config_entry_id=mock_config_entry.entry_id,
|
||||
)
|
||||
|
||||
assert registry.async_get_device({(DOMAIN, "test/repository")}) == device
|
||||
await async_cleanup_device_registry(hass, mock_config_entry)
|
||||
assert len(devices) == 1
|
||||
|
||||
mock_config_entry.options = {CONF_REPOSITORIES: []}
|
||||
assert await hass.config_entries.async_reload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
f"Unlinking device {device.id} for untracked repository test/repository from config entry {mock_config_entry.entry_id}"
|
||||
f"Unlinking device {devices[0].id} for untracked repository home-assistant/core from config entry {mock_config_entry.entry_id}"
|
||||
in caplog.text
|
||||
)
|
||||
assert registry.async_get_device({(DOMAIN, "test/repository")}) is None
|
||||
|
||||
devices = dr.async_entries_for_config_entry(
|
||||
registry=device_registry,
|
||||
config_entry_id=mock_config_entry.entry_id,
|
||||
)
|
||||
|
||||
assert len(devices) == 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue