Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -9,22 +9,19 @@ from homeassistant.components.axis import device, errors
|
|||
from homeassistant.components.axis.camera import AxisCamera
|
||||
|
||||
DEVICE_DATA = {
|
||||
device.CONF_HOST: '1.2.3.4',
|
||||
device.CONF_USERNAME: 'username',
|
||||
device.CONF_PASSWORD: 'password',
|
||||
device.CONF_PORT: 1234
|
||||
device.CONF_HOST: "1.2.3.4",
|
||||
device.CONF_USERNAME: "username",
|
||||
device.CONF_PASSWORD: "password",
|
||||
device.CONF_PORT: 1234,
|
||||
}
|
||||
|
||||
ENTRY_OPTIONS = {
|
||||
device.CONF_CAMERA: True,
|
||||
device.CONF_EVENTS: True,
|
||||
}
|
||||
ENTRY_OPTIONS = {device.CONF_CAMERA: True, device.CONF_EVENTS: True}
|
||||
|
||||
ENTRY_CONFIG = {
|
||||
device.CONF_DEVICE: DEVICE_DATA,
|
||||
device.CONF_MAC: 'mac',
|
||||
device.CONF_MODEL: 'model',
|
||||
device.CONF_NAME: 'name'
|
||||
device.CONF_MAC: "mac",
|
||||
device.CONF_MODEL: "model",
|
||||
device.CONF_NAME: "name",
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,60 +41,70 @@ async def test_device_setup():
|
|||
assert axis_device.name == ENTRY_CONFIG[device.CONF_NAME]
|
||||
assert axis_device.serial == ENTRY_CONFIG[device.CONF_MAC]
|
||||
|
||||
with patch.object(device, 'get_device', return_value=mock_coro(api)):
|
||||
with patch.object(device, "get_device", return_value=mock_coro(api)):
|
||||
assert await axis_device.async_setup() is True
|
||||
|
||||
assert axis_device.api is api
|
||||
assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 3
|
||||
assert hass.config_entries.async_forward_entry_setup.mock_calls[0][1] == \
|
||||
(entry, 'camera')
|
||||
assert hass.config_entries.async_forward_entry_setup.mock_calls[1][1] == \
|
||||
(entry, 'binary_sensor')
|
||||
assert hass.config_entries.async_forward_entry_setup.mock_calls[2][1] == \
|
||||
(entry, 'switch')
|
||||
assert hass.config_entries.async_forward_entry_setup.mock_calls[0][1] == (
|
||||
entry,
|
||||
"camera",
|
||||
)
|
||||
assert hass.config_entries.async_forward_entry_setup.mock_calls[1][1] == (
|
||||
entry,
|
||||
"binary_sensor",
|
||||
)
|
||||
assert hass.config_entries.async_forward_entry_setup.mock_calls[2][1] == (
|
||||
entry,
|
||||
"switch",
|
||||
)
|
||||
|
||||
|
||||
async def test_device_signal_new_address(hass):
|
||||
"""Successful setup."""
|
||||
entry = MockConfigEntry(
|
||||
domain=device.DOMAIN, data=ENTRY_CONFIG, options=ENTRY_OPTIONS)
|
||||
domain=device.DOMAIN, data=ENTRY_CONFIG, options=ENTRY_OPTIONS
|
||||
)
|
||||
|
||||
api = Mock()
|
||||
api.vapix.get_param.return_value = '1234'
|
||||
api.vapix.get_param.return_value = "1234"
|
||||
|
||||
axis_device = device.AxisNetworkDevice(hass, entry)
|
||||
hass.data[device.DOMAIN] = {axis_device.serial: axis_device}
|
||||
|
||||
with patch.object(device, 'get_device', return_value=mock_coro(api)), \
|
||||
patch.object(AxisCamera, '_new_address') as new_address_mock:
|
||||
with patch.object(device, "get_device", return_value=mock_coro(api)), patch.object(
|
||||
AxisCamera, "_new_address"
|
||||
) as new_address_mock:
|
||||
await axis_device.async_setup()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 1
|
||||
assert len(axis_device.listeners) == 2
|
||||
|
||||
entry.data[device.CONF_DEVICE][device.CONF_HOST] = '2.3.4.5'
|
||||
entry.data[device.CONF_DEVICE][device.CONF_HOST] = "2.3.4.5"
|
||||
hass.config_entries.async_update_entry(entry, data=entry.data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert axis_device.host == '2.3.4.5'
|
||||
assert axis_device.api.config.host == '2.3.4.5'
|
||||
assert axis_device.host == "2.3.4.5"
|
||||
assert axis_device.api.config.host == "2.3.4.5"
|
||||
assert len(new_address_mock.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_device_unavailable(hass):
|
||||
"""Successful setup."""
|
||||
entry = MockConfigEntry(
|
||||
domain=device.DOMAIN, data=ENTRY_CONFIG, options=ENTRY_OPTIONS)
|
||||
domain=device.DOMAIN, data=ENTRY_CONFIG, options=ENTRY_OPTIONS
|
||||
)
|
||||
|
||||
api = Mock()
|
||||
api.vapix.get_param.return_value = '1234'
|
||||
api.vapix.get_param.return_value = "1234"
|
||||
|
||||
axis_device = device.AxisNetworkDevice(hass, entry)
|
||||
hass.data[device.DOMAIN] = {axis_device.serial: axis_device}
|
||||
|
||||
with patch.object(device, 'get_device', return_value=mock_coro(api)), \
|
||||
patch.object(device, 'async_dispatcher_send') as mock_dispatcher:
|
||||
with patch.object(device, "get_device", return_value=mock_coro(api)), patch.object(
|
||||
device, "async_dispatcher_send"
|
||||
) as mock_dispatcher:
|
||||
await axis_device.async_setup()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -110,15 +117,16 @@ async def test_device_unavailable(hass):
|
|||
async def test_device_reset(hass):
|
||||
"""Successfully reset device."""
|
||||
entry = MockConfigEntry(
|
||||
domain=device.DOMAIN, data=ENTRY_CONFIG, options=ENTRY_OPTIONS)
|
||||
domain=device.DOMAIN, data=ENTRY_CONFIG, options=ENTRY_OPTIONS
|
||||
)
|
||||
|
||||
api = Mock()
|
||||
api.vapix.get_param.return_value = '1234'
|
||||
api.vapix.get_param.return_value = "1234"
|
||||
|
||||
axis_device = device.AxisNetworkDevice(hass, entry)
|
||||
hass.data[device.DOMAIN] = {axis_device.serial: axis_device}
|
||||
|
||||
with patch.object(device, 'get_device', return_value=mock_coro(api)):
|
||||
with patch.object(device, "get_device", return_value=mock_coro(api)):
|
||||
await axis_device.async_setup()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -139,9 +147,9 @@ async def test_device_not_accessible():
|
|||
|
||||
axis_device = device.AxisNetworkDevice(hass, entry)
|
||||
|
||||
with patch.object(device, 'get_device',
|
||||
side_effect=errors.CannotConnect), \
|
||||
pytest.raises(device.ConfigEntryNotReady):
|
||||
with patch.object(
|
||||
device, "get_device", side_effect=errors.CannotConnect
|
||||
), pytest.raises(device.ConfigEntryNotReady):
|
||||
await axis_device.async_setup()
|
||||
|
||||
assert not hass.helpers.event.async_call_later.mock_calls
|
||||
|
@ -156,7 +164,7 @@ async def test_device_unknown_error():
|
|||
|
||||
axis_device = device.AxisNetworkDevice(hass, entry)
|
||||
|
||||
with patch.object(device, 'get_device', side_effect=Exception):
|
||||
with patch.object(device, "get_device", side_effect=Exception):
|
||||
assert await axis_device.async_setup() is False
|
||||
|
||||
assert not hass.helpers.event.async_call_later.mock_calls
|
||||
|
@ -169,8 +177,8 @@ async def test_new_event_sends_signal(hass):
|
|||
|
||||
axis_device = device.AxisNetworkDevice(hass, entry)
|
||||
|
||||
with patch.object(device, 'async_dispatcher_send') as mock_dispatch_send:
|
||||
axis_device.async_event_callback(action='add', event_id='event')
|
||||
with patch.object(device, "async_dispatcher_send") as mock_dispatch_send:
|
||||
axis_device.async_event_callback(action="add", event_id="event")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_dispatch_send.mock_calls) == 1
|
||||
|
@ -193,12 +201,9 @@ async def test_shutdown():
|
|||
|
||||
async def test_get_device(hass):
|
||||
"""Successful call."""
|
||||
with patch('axis.param_cgi.Params.update_brand',
|
||||
return_value=mock_coro()), \
|
||||
patch('axis.param_cgi.Params.update_properties',
|
||||
return_value=mock_coro()), \
|
||||
patch('axis.port_cgi.Ports.update',
|
||||
return_value=mock_coro()):
|
||||
with patch("axis.param_cgi.Params.update_brand", return_value=mock_coro()), patch(
|
||||
"axis.param_cgi.Params.update_properties", return_value=mock_coro()
|
||||
), patch("axis.port_cgi.Ports.update", return_value=mock_coro()):
|
||||
assert await device.get_device(hass, DEVICE_DATA)
|
||||
|
||||
|
||||
|
@ -206,9 +211,9 @@ async def test_get_device_fails(hass):
|
|||
"""Device unauthorized yields authentication required error."""
|
||||
import axis
|
||||
|
||||
with patch('axis.param_cgi.Params.update_brand',
|
||||
side_effect=axis.Unauthorized), \
|
||||
pytest.raises(errors.AuthenticationRequired):
|
||||
with patch(
|
||||
"axis.param_cgi.Params.update_brand", side_effect=axis.Unauthorized
|
||||
), pytest.raises(errors.AuthenticationRequired):
|
||||
await device.get_device(hass, DEVICE_DATA)
|
||||
|
||||
|
||||
|
@ -216,9 +221,9 @@ async def test_get_device_device_unavailable(hass):
|
|||
"""Device unavailable yields cannot connect error."""
|
||||
import axis
|
||||
|
||||
with patch('axis.param_cgi.Params.update_brand',
|
||||
side_effect=axis.RequestError), \
|
||||
pytest.raises(errors.CannotConnect):
|
||||
with patch(
|
||||
"axis.param_cgi.Params.update_brand", side_effect=axis.RequestError
|
||||
), pytest.raises(errors.CannotConnect):
|
||||
await device.get_device(hass, DEVICE_DATA)
|
||||
|
||||
|
||||
|
@ -226,7 +231,7 @@ async def test_get_device_unknown_error(hass):
|
|||
"""Device yield unknown error."""
|
||||
import axis
|
||||
|
||||
with patch('axis.param_cgi.Params.update_brand',
|
||||
side_effect=axis.AxisException), \
|
||||
pytest.raises(errors.AuthenticationRequired):
|
||||
with patch(
|
||||
"axis.param_cgi.Params.update_brand", side_effect=axis.AxisException
|
||||
), pytest.raises(errors.AuthenticationRequired):
|
||||
await device.get_device(hass, DEVICE_DATA)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue