Skip to content

Commit d393d5f

Browse files
authored
Use non-autospec mock for Reolink's util and view tests (home-assistant#148579)
1 parent a34264f commit d393d5f

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

tests/components/reolink/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def _init_host_mock(host_mock: MagicMock) -> None:
8484
host_mock.set_whiteled = AsyncMock()
8585
host_mock.set_state_light = AsyncMock()
8686
host_mock.renew = AsyncMock()
87+
host_mock.get_vod_source = AsyncMock()
88+
host_mock.expire_session = AsyncMock()
8789
host_mock.is_nvr = True
8890
host_mock.is_hub = False
8991
host_mock.mac_address = TEST_MAC

tests/components/reolink/test_util.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@
103103
async def test_try_function(
104104
hass: HomeAssistant,
105105
config_entry: MockConfigEntry,
106-
reolink_connect: MagicMock,
106+
reolink_host: MagicMock,
107107
side_effect: ReolinkError,
108108
expected: HomeAssistantError,
109109
) -> None:
110110
"""Test try_function error translations using number entity."""
111-
reolink_connect.volume.return_value = 80
111+
reolink_host.volume.return_value = 80
112112

113113
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.NUMBER]):
114114
assert await hass.config_entries.async_setup(config_entry.entry_id)
@@ -117,7 +117,7 @@ async def test_try_function(
117117

118118
entity_id = f"{Platform.NUMBER}.{TEST_NVR_NAME}_volume"
119119

120-
reolink_connect.set_volume.side_effect = side_effect
120+
reolink_host.set_volume.side_effect = side_effect
121121
with pytest.raises(expected.__class__) as err:
122122
await hass.services.async_call(
123123
NUMBER_DOMAIN,
@@ -128,8 +128,6 @@ async def test_try_function(
128128

129129
assert err.value.translation_key == expected.translation_key
130130

131-
reolink_connect.set_volume.reset_mock(side_effect=True)
132-
133131

134132
@pytest.mark.parametrize(
135133
("identifiers"),
@@ -141,12 +139,12 @@ async def test_try_function(
141139
async def test_get_device_uid_and_ch(
142140
hass: HomeAssistant,
143141
config_entry: MockConfigEntry,
144-
reolink_connect: MagicMock,
142+
reolink_host: MagicMock,
145143
device_registry: dr.DeviceRegistry,
146144
identifiers: set[tuple[str, str]],
147145
) -> None:
148146
"""Test get_device_uid_and_ch with multiple identifiers."""
149-
reolink_connect.channels = [0]
147+
reolink_host.channels = [0]
150148

151149
dev_entry = device_registry.async_get_or_create(
152150
identifiers=identifiers,

tests/components/reolink/test_views.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ def get_mock_session(
6464
)
6565
async def test_playback_proxy(
6666
hass: HomeAssistant,
67-
reolink_connect: MagicMock,
67+
reolink_host: MagicMock,
6868
config_entry: MockConfigEntry,
6969
hass_client: ClientSessionGenerator,
7070
caplog: pytest.LogCaptureFixture,
7171
content_type: str,
7272
) -> None:
7373
"""Test successful playback proxy URL."""
74-
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
74+
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
7575

7676
mock_session = get_mock_session(content_type=content_type)
7777

@@ -100,12 +100,12 @@ async def test_playback_proxy(
100100

101101
async def test_proxy_get_source_error(
102102
hass: HomeAssistant,
103-
reolink_connect: MagicMock,
103+
reolink_host: MagicMock,
104104
config_entry: MockConfigEntry,
105105
hass_client: ClientSessionGenerator,
106106
) -> None:
107107
"""Test error while getting source for playback proxy URL."""
108-
reolink_connect.get_vod_source.side_effect = ReolinkError(TEST_ERROR)
108+
reolink_host.get_vod_source.side_effect = ReolinkError(TEST_ERROR)
109109

110110
assert await hass.config_entries.async_setup(config_entry.entry_id)
111111
await hass.async_block_till_done()
@@ -123,12 +123,11 @@ async def test_proxy_get_source_error(
123123

124124
assert await response.content.read() == bytes(TEST_ERROR, "utf-8")
125125
assert response.status == HTTPStatus.BAD_REQUEST
126-
reolink_connect.get_vod_source.side_effect = None
127126

128127

129128
async def test_proxy_invalid_config_entry_id(
130129
hass: HomeAssistant,
131-
reolink_connect: MagicMock,
130+
reolink_host: MagicMock,
132131
config_entry: MockConfigEntry,
133132
hass_client: ClientSessionGenerator,
134133
) -> None:
@@ -156,12 +155,12 @@ async def test_proxy_invalid_config_entry_id(
156155

157156
async def test_playback_proxy_timeout(
158157
hass: HomeAssistant,
159-
reolink_connect: MagicMock,
158+
reolink_host: MagicMock,
160159
config_entry: MockConfigEntry,
161160
hass_client: ClientSessionGenerator,
162161
) -> None:
163162
"""Test playback proxy URL with a timeout in the second chunk."""
164-
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
163+
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
165164

166165
mock_session = get_mock_session([b"test", TimeoutError()], 4)
167166

@@ -190,13 +189,13 @@ async def test_playback_proxy_timeout(
190189
@pytest.mark.parametrize(("content_type"), [("video/x-flv"), ("text/html")])
191190
async def test_playback_wrong_content(
192191
hass: HomeAssistant,
193-
reolink_connect: MagicMock,
192+
reolink_host: MagicMock,
194193
config_entry: MockConfigEntry,
195194
hass_client: ClientSessionGenerator,
196195
content_type: str,
197196
) -> None:
198197
"""Test playback proxy URL with a wrong content type in the response."""
199-
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
198+
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
200199

201200
mock_session = get_mock_session(content_type=content_type)
202201

@@ -223,12 +222,12 @@ async def test_playback_wrong_content(
223222

224223
async def test_playback_connect_error(
225224
hass: HomeAssistant,
226-
reolink_connect: MagicMock,
225+
reolink_host: MagicMock,
227226
config_entry: MockConfigEntry,
228227
hass_client: ClientSessionGenerator,
229228
) -> None:
230229
"""Test playback proxy URL with a connection error."""
231-
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
230+
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
232231

233232
mock_session = Mock()
234233
mock_session.get = AsyncMock(side_effect=ClientConnectionError(TEST_ERROR))

0 commit comments

Comments
 (0)