core/tests/components/imgw_pib/test_init.py

46 lines
1.3 KiB
Python

"""Test init of IMGW-PIB integration."""
from unittest.mock import AsyncMock, patch
from imgw_pib import ApiError
from homeassistant.components.imgw_pib.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from . import init_integration
from tests.common import MockConfigEntry
async def test_config_not_ready(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test for setup failure if the connection to the service fails."""
with patch(
"homeassistant.components.imgw_pib.ImgwPib.create",
side_effect=ApiError("API Error"),
):
await init_integration(hass, mock_config_entry)
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_unload_entry(
hass: HomeAssistant,
mock_imgw_pib_client: AsyncMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test successful unload of entry."""
await init_integration(hass, mock_config_entry)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert mock_config_entry.state is ConfigEntryState.LOADED
assert await hass.config_entries.async_unload(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
assert not hass.data.get(DOMAIN)