Reolink 100% test coverage (#94763)
This commit is contained in:
parent
e209f3723e
commit
92cf6ed2a0
3 changed files with 42 additions and 24 deletions
|
@ -1,18 +1,23 @@
|
|||
"""Test the Reolink init."""
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from reolink_aio.exceptions import ReolinkError
|
||||
|
||||
from homeassistant.components.reolink import const
|
||||
from homeassistant.components.reolink import FIRMWARE_UPDATE_INTERVAL, const
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from .conftest import TEST_NVR_NAME
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("reolink_connect", "reolink_platforms")
|
||||
|
||||
|
@ -45,17 +50,11 @@ pytestmark = pytest.mark.usefixtures("reolink_connect", "reolink_platforms")
|
|||
Mock(return_value=False),
|
||||
ConfigEntryState.LOADED,
|
||||
),
|
||||
(
|
||||
"check_new_firmware",
|
||||
AsyncMock(side_effect=ReolinkError("Test error")),
|
||||
ConfigEntryState.LOADED,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_failures_parametrized(
|
||||
hass: HomeAssistant,
|
||||
reolink_connect: MagicMock,
|
||||
reolink_ONVIF_wait: MagicMock,
|
||||
config_entry: MockConfigEntry,
|
||||
attr: str,
|
||||
value: Any,
|
||||
|
@ -71,11 +70,36 @@ async def test_failures_parametrized(
|
|||
assert config_entry.state == expected
|
||||
|
||||
|
||||
async def test_firmware_error_twice(
|
||||
hass: HomeAssistant,
|
||||
reolink_connect: MagicMock,
|
||||
config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test when the firmware update fails 2 times."""
|
||||
reolink_connect.check_new_firmware = AsyncMock(
|
||||
side_effect=ReolinkError("Test error")
|
||||
)
|
||||
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.UPDATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id) is True
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
entity_id = f"{Platform.UPDATE}.{TEST_NVR_NAME}_update"
|
||||
assert hass.states.is_state(entity_id, STATE_OFF)
|
||||
|
||||
async_fire_time_changed(
|
||||
hass, utcnow() + FIRMWARE_UPDATE_INTERVAL + timedelta(minutes=1)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.is_state(entity_id, STATE_UNAVAILABLE)
|
||||
|
||||
|
||||
async def test_entry_reloading(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
reolink_connect: MagicMock,
|
||||
reolink_ONVIF_wait: MagicMock,
|
||||
) -> None:
|
||||
"""Test the entry is reloaded correctly when settings change."""
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
@ -92,7 +116,7 @@ async def test_entry_reloading(
|
|||
|
||||
|
||||
async def test_no_repair_issue(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, reolink_ONVIF_wait: MagicMock
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test no repairs issue is raised when http local url is used."""
|
||||
await async_process_ha_core_config(
|
||||
|
@ -111,7 +135,7 @@ async def test_no_repair_issue(
|
|||
|
||||
|
||||
async def test_https_repair_issue(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, reolink_ONVIF_wait: MagicMock
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test repairs issue is raised when https local url is used."""
|
||||
await async_process_ha_core_config(
|
||||
|
@ -133,7 +157,7 @@ async def test_https_repair_issue(
|
|||
|
||||
|
||||
async def test_ssl_repair_issue(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, reolink_ONVIF_wait: MagicMock
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test repairs issue is raised when global ssl certificate is used."""
|
||||
assert await async_setup_component(hass, "webhook", {})
|
||||
|
@ -162,7 +186,6 @@ async def test_port_repair_issue(
|
|||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
reolink_connect: MagicMock,
|
||||
reolink_ONVIF_wait: MagicMock,
|
||||
protocol: str,
|
||||
) -> None:
|
||||
"""Test repairs issue is raised when auto enable of ports fails."""
|
||||
|
@ -200,7 +223,6 @@ async def test_firmware_repair_issue(
|
|||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
reolink_connect: MagicMock,
|
||||
reolink_ONVIF_wait: MagicMock,
|
||||
) -> None:
|
||||
"""Test firmware issue is raised when too old firmware is used."""
|
||||
reolink_connect.sw_version_update_required = True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue