Use aiopyarr for sonarr (#65349)
This commit is contained in:
parent
c14912471d
commit
f30681dae7
20 changed files with 464 additions and 345 deletions
|
@ -1,11 +1,19 @@
|
|||
"""Tests for the Sonsrr integration."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from sonarr import SonarrAccessRestricted, SonarrError
|
||||
from aiopyarr import ArrAuthenticationException, ArrException
|
||||
|
||||
from homeassistant.components.sonarr.const import DOMAIN
|
||||
from homeassistant.components.sonarr.const import CONF_BASE_PATH, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import CONF_SOURCE
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
CONF_SOURCE,
|
||||
CONF_SSL,
|
||||
CONF_URL,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
@ -17,7 +25,7 @@ async def test_config_entry_not_ready(
|
|||
mock_sonarr: MagicMock,
|
||||
) -> None:
|
||||
"""Test the configuration entry not ready."""
|
||||
mock_sonarr.update.side_effect = SonarrError
|
||||
mock_sonarr.async_get_system_status.side_effect = ArrException
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
|
@ -32,7 +40,7 @@ async def test_config_entry_reauth(
|
|||
mock_sonarr: MagicMock,
|
||||
) -> None:
|
||||
"""Test the configuration entry needing to be re-authenticated."""
|
||||
mock_sonarr.update.side_effect = SonarrAccessRestricted
|
||||
mock_sonarr.async_get_system_status.side_effect = ArrAuthenticationException
|
||||
|
||||
with patch.object(hass.config_entries.flow, "async_init") as mock_flow_init:
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
@ -77,3 +85,34 @@ async def test_unload_config_entry(
|
|||
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
assert mock_config_entry.entry_id not in hass.data[DOMAIN]
|
||||
|
||||
|
||||
async def test_migrate_config_entry(hass: HomeAssistant):
|
||||
"""Test successful migration of entry data."""
|
||||
legacy_config = {
|
||||
CONF_API_KEY: "MOCK_API_KEY",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_PORT: 8989,
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: False,
|
||||
CONF_BASE_PATH: "/base/",
|
||||
}
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=legacy_config)
|
||||
|
||||
assert entry.data == legacy_config
|
||||
assert entry.version == 1
|
||||
assert not entry.unique_id
|
||||
|
||||
await entry.async_migrate(hass)
|
||||
|
||||
assert entry.data == {
|
||||
CONF_API_KEY: "MOCK_API_KEY",
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_PORT: 8989,
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: False,
|
||||
CONF_BASE_PATH: "/base/",
|
||||
CONF_URL: "http://1.2.3.4:8989/base",
|
||||
}
|
||||
assert entry.version == 2
|
||||
assert not entry.unique_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue