core/tests/components/smhi/test_init.py

49 lines
1.5 KiB
Python
Raw Normal View History

"""Test SMHI component setup process."""
2021-05-15 18:22:32 +00:00
from smhi.smhi_lib import APIURL_TEMPLATE
2021-01-01 21:31:56 +00:00
2021-05-15 18:22:32 +00:00
from homeassistant.components.smhi.const import DOMAIN
from homeassistant.core import HomeAssistant
2021-05-15 18:22:32 +00:00
from . import ENTITY_ID, TEST_CONFIG
2021-05-15 18:22:32 +00:00
from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker
2021-05-15 18:22:32 +00:00
async def test_setup_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, api_response: str
) -> None:
"""Test setup entry."""
uri = APIURL_TEMPLATE.format(TEST_CONFIG["longitude"], TEST_CONFIG["latitude"])
aioclient_mock.get(uri, text=api_response)
entry = MockConfigEntry(domain=DOMAIN, data=TEST_CONFIG)
entry.add_to_hass(hass)
2021-05-15 18:22:32 +00:00
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
2021-05-15 18:22:32 +00:00
state = hass.states.get(ENTITY_ID)
assert state
2021-05-15 18:22:32 +00:00
async def test_remove_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, api_response: str
) -> None:
2021-05-15 18:22:32 +00:00
"""Test remove entry."""
uri = APIURL_TEMPLATE.format(TEST_CONFIG["longitude"], TEST_CONFIG["latitude"])
aioclient_mock.get(uri, text=api_response)
2021-05-15 18:22:32 +00:00
entry = MockConfigEntry(domain=DOMAIN, data=TEST_CONFIG)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ID)
assert state
await hass.config_entries.async_remove(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ID)
assert not state