mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Late review updates for Blink (#104755)
This commit is contained in:
@@ -19,7 +19,7 @@ from homeassistant.const import (
|
||||
CONF_PIN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@@ -58,7 +58,7 @@ async def test_refresh_service_calls(
|
||||
|
||||
assert mock_blink_api.refresh.call_count == 2
|
||||
|
||||
with pytest.raises(HomeAssistantError) as execinfo:
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_REFRESH,
|
||||
@@ -66,8 +66,6 @@ async def test_refresh_service_calls(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert "Device 'bad-device_id' not found in device registry" in str(execinfo)
|
||||
|
||||
|
||||
async def test_video_service_calls(
|
||||
hass: HomeAssistant,
|
||||
@@ -90,18 +88,17 @@ async def test_video_service_calls(
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
assert mock_blink_api.refresh.call_count == 1
|
||||
|
||||
caplog.clear()
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_VIDEO,
|
||||
{
|
||||
ATTR_DEVICE_ID: [device_entry.id],
|
||||
CONF_NAME: CAMERA_NAME,
|
||||
CONF_FILENAME: FILENAME,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert "no access to path!" in caplog.text
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_VIDEO,
|
||||
{
|
||||
ATTR_DEVICE_ID: [device_entry.id],
|
||||
CONF_NAME: CAMERA_NAME,
|
||||
CONF_FILENAME: FILENAME,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
hass.config.is_allowed_path = Mock(return_value=True)
|
||||
caplog.clear()
|
||||
@@ -118,7 +115,7 @@ async def test_video_service_calls(
|
||||
)
|
||||
mock_blink_api.cameras[CAMERA_NAME].video_to_file.assert_awaited_once()
|
||||
|
||||
with pytest.raises(HomeAssistantError) as execinfo:
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_VIDEO,
|
||||
@@ -130,22 +127,19 @@ async def test_video_service_calls(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert "Device 'bad-device_id' not found in device registry" in str(execinfo)
|
||||
|
||||
mock_blink_api.cameras[CAMERA_NAME].video_to_file = AsyncMock(side_effect=OSError)
|
||||
caplog.clear()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_VIDEO,
|
||||
{
|
||||
ATTR_DEVICE_ID: [device_entry.id],
|
||||
CONF_NAME: CAMERA_NAME,
|
||||
CONF_FILENAME: FILENAME,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert "Can't write image" in caplog.text
|
||||
with pytest.raises(ServiceValidationError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_VIDEO,
|
||||
{
|
||||
ATTR_DEVICE_ID: [device_entry.id],
|
||||
CONF_NAME: CAMERA_NAME,
|
||||
CONF_FILENAME: FILENAME,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
hass.config.is_allowed_path = Mock(return_value=False)
|
||||
|
||||
@@ -171,18 +165,17 @@ async def test_picture_service_calls(
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
assert mock_blink_api.refresh.call_count == 1
|
||||
|
||||
caplog.clear()
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_RECENT_CLIPS,
|
||||
{
|
||||
ATTR_DEVICE_ID: [device_entry.id],
|
||||
CONF_NAME: CAMERA_NAME,
|
||||
CONF_FILE_PATH: FILENAME,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert "no access to path!" in caplog.text
|
||||
with pytest.raises(ServiceValidationError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_RECENT_CLIPS,
|
||||
{
|
||||
ATTR_DEVICE_ID: [device_entry.id],
|
||||
CONF_NAME: CAMERA_NAME,
|
||||
CONF_FILE_PATH: FILENAME,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
hass.config.is_allowed_path = Mock(return_value=True)
|
||||
mock_blink_api.cameras = {CAMERA_NAME: AsyncMock()}
|
||||
@@ -202,21 +195,20 @@ async def test_picture_service_calls(
|
||||
mock_blink_api.cameras[CAMERA_NAME].save_recent_clips = AsyncMock(
|
||||
side_effect=OSError
|
||||
)
|
||||
caplog.clear()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_RECENT_CLIPS,
|
||||
{
|
||||
ATTR_DEVICE_ID: [device_entry.id],
|
||||
CONF_NAME: CAMERA_NAME,
|
||||
CONF_FILE_PATH: FILENAME,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert "Can't write recent clips to directory" in caplog.text
|
||||
with pytest.raises(ServiceValidationError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_RECENT_CLIPS,
|
||||
{
|
||||
ATTR_DEVICE_ID: [device_entry.id],
|
||||
CONF_NAME: CAMERA_NAME,
|
||||
CONF_FILE_PATH: FILENAME,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
with pytest.raises(HomeAssistantError) as execinfo:
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SAVE_RECENT_CLIPS,
|
||||
@@ -228,8 +220,6 @@ async def test_picture_service_calls(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert "Device 'bad-device_id' not found in device registry" in str(execinfo)
|
||||
|
||||
|
||||
async def test_pin_service_calls(
|
||||
hass: HomeAssistant,
|
||||
@@ -259,7 +249,7 @@ async def test_pin_service_calls(
|
||||
)
|
||||
assert mock_blink_api.auth.send_auth_key.assert_awaited_once
|
||||
|
||||
with pytest.raises(HomeAssistantError) as execinfo:
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SEND_PIN,
|
||||
@@ -267,8 +257,6 @@ async def test_pin_service_calls(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert "Device 'bad-device_id' not found in device registry" in str(execinfo)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("service", "params"),
|
||||
@@ -325,7 +313,7 @@ async def test_service_called_with_non_blink_device(
|
||||
parameters = {ATTR_DEVICE_ID: [device_entry.id]}
|
||||
parameters.update(params)
|
||||
|
||||
with pytest.raises(HomeAssistantError) as execinfo:
|
||||
with pytest.raises(ServiceValidationError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
service,
|
||||
@@ -333,8 +321,6 @@ async def test_service_called_with_non_blink_device(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert f"Device '{device_entry.id}' is not a blink device" in str(execinfo)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("service", "params"),
|
||||
@@ -382,12 +368,10 @@ async def test_service_called_with_unloaded_entry(
|
||||
parameters = {ATTR_DEVICE_ID: [device_entry.id]}
|
||||
parameters.update(params)
|
||||
|
||||
with pytest.raises(HomeAssistantError) as execinfo:
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
service,
|
||||
parameters,
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert "Mock Title is not loaded" in str(execinfo)
|
||||
|
||||
Reference in New Issue
Block a user