core/tests/components/sonarr/test_init.py

60 lines
2.0 KiB
Python
Raw Normal View History

"""Tests for the Sonsrr integration."""
2021-01-01 21:31:56 +00:00
from unittest.mock import patch
from homeassistant.components.sonarr.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import CONF_SOURCE
from homeassistant.core import HomeAssistant
from tests.components.sonarr import setup_integration
from tests.test_util.aiohttp import AiohttpClientMocker
async def test_config_entry_not_ready(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the configuration entry not ready."""
entry = await setup_integration(hass, aioclient_mock, connection_error=True)
assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_config_entry_reauth(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the configuration entry needing to be re-authenticated."""
with patch.object(hass.config_entries.flow, "async_init") as mock_flow_init:
entry = await setup_integration(hass, aioclient_mock, invalid_auth=True)
assert entry.state is ConfigEntryState.SETUP_ERROR
mock_flow_init.assert_called_once_with(
DOMAIN,
context={
CONF_SOURCE: SOURCE_REAUTH,
"entry_id": entry.entry_id,
"unique_id": entry.unique_id,
},
data=entry.data,
)
async def test_unload_config_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the configuration entry unloading."""
2020-08-20 10:21:58 +00:00
with patch(
2020-08-27 11:56:20 +00:00
"homeassistant.components.sonarr.sensor.async_setup_entry",
return_value=True,
2020-08-20 10:21:58 +00:00
):
entry = await setup_integration(hass, aioclient_mock)
assert hass.data[DOMAIN]
assert entry.entry_id in hass.data[DOMAIN]
assert entry.state is ConfigEntryState.LOADED
await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert entry.entry_id not in hass.data[DOMAIN]
assert entry.state is ConfigEntryState.NOT_LOADED