mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Use non-autospec mock for Reolink's util and view tests (#148579)
This commit is contained in:
parent
a34264f345
commit
d393d5fdbb
@ -84,6 +84,8 @@ def _init_host_mock(host_mock: MagicMock) -> None:
|
|||||||
host_mock.set_whiteled = AsyncMock()
|
host_mock.set_whiteled = AsyncMock()
|
||||||
host_mock.set_state_light = AsyncMock()
|
host_mock.set_state_light = AsyncMock()
|
||||||
host_mock.renew = AsyncMock()
|
host_mock.renew = AsyncMock()
|
||||||
|
host_mock.get_vod_source = AsyncMock()
|
||||||
|
host_mock.expire_session = AsyncMock()
|
||||||
host_mock.is_nvr = True
|
host_mock.is_nvr = True
|
||||||
host_mock.is_hub = False
|
host_mock.is_hub = False
|
||||||
host_mock.mac_address = TEST_MAC
|
host_mock.mac_address = TEST_MAC
|
||||||
|
@ -103,12 +103,12 @@ DEV_ID_STANDALONE_CAM = f"{TEST_UID_CAM}"
|
|||||||
async def test_try_function(
|
async def test_try_function(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
reolink_connect: MagicMock,
|
reolink_host: MagicMock,
|
||||||
side_effect: ReolinkError,
|
side_effect: ReolinkError,
|
||||||
expected: HomeAssistantError,
|
expected: HomeAssistantError,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test try_function error translations using number entity."""
|
"""Test try_function error translations using number entity."""
|
||||||
reolink_connect.volume.return_value = 80
|
reolink_host.volume.return_value = 80
|
||||||
|
|
||||||
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.NUMBER]):
|
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.NUMBER]):
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
@ -117,7 +117,7 @@ async def test_try_function(
|
|||||||
|
|
||||||
entity_id = f"{Platform.NUMBER}.{TEST_NVR_NAME}_volume"
|
entity_id = f"{Platform.NUMBER}.{TEST_NVR_NAME}_volume"
|
||||||
|
|
||||||
reolink_connect.set_volume.side_effect = side_effect
|
reolink_host.set_volume.side_effect = side_effect
|
||||||
with pytest.raises(expected.__class__) as err:
|
with pytest.raises(expected.__class__) as err:
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
NUMBER_DOMAIN,
|
NUMBER_DOMAIN,
|
||||||
@ -128,8 +128,6 @@ async def test_try_function(
|
|||||||
|
|
||||||
assert err.value.translation_key == expected.translation_key
|
assert err.value.translation_key == expected.translation_key
|
||||||
|
|
||||||
reolink_connect.set_volume.reset_mock(side_effect=True)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("identifiers"),
|
("identifiers"),
|
||||||
@ -141,12 +139,12 @@ async def test_try_function(
|
|||||||
async def test_get_device_uid_and_ch(
|
async def test_get_device_uid_and_ch(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
reolink_connect: MagicMock,
|
reolink_host: MagicMock,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
identifiers: set[tuple[str, str]],
|
identifiers: set[tuple[str, str]],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test get_device_uid_and_ch with multiple identifiers."""
|
"""Test get_device_uid_and_ch with multiple identifiers."""
|
||||||
reolink_connect.channels = [0]
|
reolink_host.channels = [0]
|
||||||
|
|
||||||
dev_entry = device_registry.async_get_or_create(
|
dev_entry = device_registry.async_get_or_create(
|
||||||
identifiers=identifiers,
|
identifiers=identifiers,
|
||||||
|
@ -64,14 +64,14 @@ def get_mock_session(
|
|||||||
)
|
)
|
||||||
async def test_playback_proxy(
|
async def test_playback_proxy(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
reolink_connect: MagicMock,
|
reolink_host: MagicMock,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
content_type: str,
|
content_type: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful playback proxy URL."""
|
"""Test successful playback proxy URL."""
|
||||||
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
|
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
|
||||||
|
|
||||||
mock_session = get_mock_session(content_type=content_type)
|
mock_session = get_mock_session(content_type=content_type)
|
||||||
|
|
||||||
@ -100,12 +100,12 @@ async def test_playback_proxy(
|
|||||||
|
|
||||||
async def test_proxy_get_source_error(
|
async def test_proxy_get_source_error(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
reolink_connect: MagicMock,
|
reolink_host: MagicMock,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error while getting source for playback proxy URL."""
|
"""Test error while getting source for playback proxy URL."""
|
||||||
reolink_connect.get_vod_source.side_effect = ReolinkError(TEST_ERROR)
|
reolink_host.get_vod_source.side_effect = ReolinkError(TEST_ERROR)
|
||||||
|
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -123,12 +123,11 @@ async def test_proxy_get_source_error(
|
|||||||
|
|
||||||
assert await response.content.read() == bytes(TEST_ERROR, "utf-8")
|
assert await response.content.read() == bytes(TEST_ERROR, "utf-8")
|
||||||
assert response.status == HTTPStatus.BAD_REQUEST
|
assert response.status == HTTPStatus.BAD_REQUEST
|
||||||
reolink_connect.get_vod_source.side_effect = None
|
|
||||||
|
|
||||||
|
|
||||||
async def test_proxy_invalid_config_entry_id(
|
async def test_proxy_invalid_config_entry_id(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
reolink_connect: MagicMock,
|
reolink_host: MagicMock,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -156,12 +155,12 @@ async def test_proxy_invalid_config_entry_id(
|
|||||||
|
|
||||||
async def test_playback_proxy_timeout(
|
async def test_playback_proxy_timeout(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
reolink_connect: MagicMock,
|
reolink_host: MagicMock,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test playback proxy URL with a timeout in the second chunk."""
|
"""Test playback proxy URL with a timeout in the second chunk."""
|
||||||
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
|
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
|
||||||
|
|
||||||
mock_session = get_mock_session([b"test", TimeoutError()], 4)
|
mock_session = get_mock_session([b"test", TimeoutError()], 4)
|
||||||
|
|
||||||
@ -190,13 +189,13 @@ async def test_playback_proxy_timeout(
|
|||||||
@pytest.mark.parametrize(("content_type"), [("video/x-flv"), ("text/html")])
|
@pytest.mark.parametrize(("content_type"), [("video/x-flv"), ("text/html")])
|
||||||
async def test_playback_wrong_content(
|
async def test_playback_wrong_content(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
reolink_connect: MagicMock,
|
reolink_host: MagicMock,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
content_type: str,
|
content_type: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test playback proxy URL with a wrong content type in the response."""
|
"""Test playback proxy URL with a wrong content type in the response."""
|
||||||
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
|
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
|
||||||
|
|
||||||
mock_session = get_mock_session(content_type=content_type)
|
mock_session = get_mock_session(content_type=content_type)
|
||||||
|
|
||||||
@ -223,12 +222,12 @@ async def test_playback_wrong_content(
|
|||||||
|
|
||||||
async def test_playback_connect_error(
|
async def test_playback_connect_error(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
reolink_connect: MagicMock,
|
reolink_host: MagicMock,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test playback proxy URL with a connection error."""
|
"""Test playback proxy URL with a connection error."""
|
||||||
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
|
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
|
||||||
|
|
||||||
mock_session = Mock()
|
mock_session = Mock()
|
||||||
mock_session.get = AsyncMock(side_effect=ClientConnectionError(TEST_ERROR))
|
mock_session.get = AsyncMock(side_effect=ClientConnectionError(TEST_ERROR))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user