core/tests/components/dnsip/test_init.py

55 lines
1.5 KiB
Python

"""Test for DNS IP component Init."""
from __future__ import annotations
from unittest.mock import patch
from homeassistant import config_entries
from homeassistant.components.dnsip.const import (
CONF_HOSTNAME,
CONF_IPV4,
CONF_IPV6,
CONF_RESOLVER,
CONF_RESOLVER_IPV6,
DOMAIN,
)
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
from . import RetrieveDNS
from tests.common import MockConfigEntry
async def test_load_unload_entry(hass: HomeAssistant) -> None:
"""Test load and unload an entry."""
entry = MockConfigEntry(
domain=DOMAIN,
source=SOURCE_USER,
data={
CONF_HOSTNAME: "home-assistant.io",
CONF_NAME: "home-assistant.io",
CONF_IPV4: True,
CONF_IPV6: False,
},
options={
CONF_RESOLVER: "208.67.222.222",
CONF_RESOLVER_IPV6: "2620:0:ccc::2",
},
entry_id="1",
unique_id="home-assistant.io",
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.dnsip.config_flow.aiodns.DNSResolver",
return_value=RetrieveDNS(),
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state == config_entries.ConfigEntryState.LOADED
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert entry.state is config_entries.ConfigEntryState.NOT_LOADED