2022-09-23 02:16:24 +00:00
|
|
|
"""Test Radarr integration."""
|
2023-12-05 15:51:51 +00:00
|
|
|
import pytest
|
|
|
|
|
2022-09-23 02:16:24 +00:00
|
|
|
from homeassistant.components.radarr.const import DEFAULT_NAME, DOMAIN
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers import device_registry as dr
|
|
|
|
|
2023-10-08 17:39:56 +00:00
|
|
|
from . import create_entry, mock_connection_invalid_auth, setup_integration
|
2022-09-23 02:16:24 +00:00
|
|
|
|
|
|
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
|
|
|
|
|
|
|
2023-12-05 15:51:51 +00:00
|
|
|
@pytest.mark.freeze_time("2021-12-03 00:00:00+00:00")
|
2023-02-15 10:14:04 +00:00
|
|
|
async def test_setup(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
|
2022-09-23 02:16:24 +00:00
|
|
|
"""Test unload."""
|
|
|
|
entry = await setup_integration(hass, aioclient_mock)
|
|
|
|
assert entry.state == ConfigEntryState.LOADED
|
|
|
|
|
|
|
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert entry.state is ConfigEntryState.NOT_LOADED
|
|
|
|
assert not hass.data.get(DOMAIN)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_async_setup_entry_not_ready(
|
|
|
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
2023-02-15 10:14:04 +00:00
|
|
|
) -> None:
|
2022-09-23 02:16:24 +00:00
|
|
|
"""Test that it throws ConfigEntryNotReady when exception occurs during setup."""
|
|
|
|
entry = await setup_integration(hass, aioclient_mock, connection_error=True)
|
|
|
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
|
|
assert entry.state == ConfigEntryState.SETUP_RETRY
|
|
|
|
assert not hass.data.get(DOMAIN)
|
|
|
|
|
|
|
|
|
2023-10-08 17:39:56 +00:00
|
|
|
async def test_async_setup_entry_auth_failed(
|
|
|
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
|
|
) -> None:
|
2022-09-23 02:16:24 +00:00
|
|
|
"""Test that it throws ConfigEntryAuthFailed when authentication fails."""
|
|
|
|
entry = create_entry(hass)
|
2023-10-08 17:39:56 +00:00
|
|
|
mock_connection_invalid_auth(aioclient_mock)
|
|
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
|
|
assert entry.state == ConfigEntryState.SETUP_ERROR
|
|
|
|
assert not hass.data.get(DOMAIN)
|
2022-09-23 02:16:24 +00:00
|
|
|
|
|
|
|
|
2023-12-05 15:51:51 +00:00
|
|
|
@pytest.mark.freeze_time("2021-12-03 00:00:00+00:00")
|
2023-02-15 10:14:04 +00:00
|
|
|
async def test_device_info(
|
|
|
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
|
|
) -> None:
|
2022-09-23 02:16:24 +00:00
|
|
|
"""Test device info."""
|
|
|
|
entry = await setup_integration(hass, aioclient_mock)
|
|
|
|
device_registry = dr.async_get(hass)
|
|
|
|
await hass.async_block_till_done()
|
2023-07-13 17:39:25 +00:00
|
|
|
device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
|
2022-09-23 02:16:24 +00:00
|
|
|
|
|
|
|
assert device.configuration_url == "http://192.168.1.189:7887/test"
|
|
|
|
assert device.identifiers == {(DOMAIN, entry.entry_id)}
|
|
|
|
assert device.manufacturer == DEFAULT_NAME
|
|
|
|
assert device.name == "Mock Title"
|
|
|
|
assert device.sw_version == "10.0.0.34882"
|