mirror of
https://github.com/home-assistant/core.git
synced 2025-08-06 06:05:10 +02:00
Further tests implemented
This commit is contained in:
73
tests/components/homematicip_cloud/test_hap.py
Normal file
73
tests/components/homematicip_cloud/test_hap.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
"""Test HomematicIP Cloud hap."""
|
||||||
|
|
||||||
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
|
from homeassistant.components import homematicip_cloud as hmipc
|
||||||
|
|
||||||
|
from tests.common import mock_coro
|
||||||
|
|
||||||
|
from homematicip.base.base_connection import HmipConnectionError
|
||||||
|
|
||||||
|
|
||||||
|
async def test_hap_init(aioclient_mock):
|
||||||
|
"""Test a successful setup."""
|
||||||
|
hass = Mock()
|
||||||
|
entry = Mock()
|
||||||
|
home = Mock()
|
||||||
|
entry.data = {
|
||||||
|
hmipc.HMIPC_HAPID: 'ABC123',
|
||||||
|
hmipc.HMIPC_AUTHTOKEN: '123',
|
||||||
|
hmipc.HMIPC_NAME: 'hmip',
|
||||||
|
}
|
||||||
|
hap = hmipc.HomematicipHAP(hass, entry)
|
||||||
|
with patch.object(hap, 'get_hap', return_value=mock_coro(home)):
|
||||||
|
assert await hap.async_setup() is True
|
||||||
|
|
||||||
|
assert hap.home is home
|
||||||
|
assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 5
|
||||||
|
assert hass.config_entries.async_forward_entry_setup.mock_calls[0][1] == \
|
||||||
|
(entry, 'binary_sensor')
|
||||||
|
|
||||||
|
|
||||||
|
async def test_hap_setup_invalid_token():
|
||||||
|
"""Test we start config flow if username is no longer whitelisted."""
|
||||||
|
hass = Mock()
|
||||||
|
entry = Mock()
|
||||||
|
entry.data = {
|
||||||
|
hmipc.HMIPC_HAPID: 'ABC123',
|
||||||
|
hmipc.HMIPC_AUTHTOKEN: '123',
|
||||||
|
hmipc.HMIPC_NAME: 'hmip',
|
||||||
|
}
|
||||||
|
hap = hmipc.HomematicipHAP(hass, entry)
|
||||||
|
|
||||||
|
with patch.object(hap, 'get_hap',
|
||||||
|
side_effect=HmipConnectionError):
|
||||||
|
assert await hap.async_setup() is False
|
||||||
|
|
||||||
|
assert len(hass.async_add_job.mock_calls) == 0
|
||||||
|
assert len(hass.config_entries.flow.async_init.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_reset_unloads_entry_if_setup():
|
||||||
|
"""Test calling reset while the entry has been setup."""
|
||||||
|
hass = Mock()
|
||||||
|
entry = Mock()
|
||||||
|
home = Mock()
|
||||||
|
entry.data = {
|
||||||
|
hmipc.HMIPC_HAPID: 'ABC123',
|
||||||
|
hmipc.HMIPC_AUTHTOKEN: '123',
|
||||||
|
hmipc.HMIPC_NAME: 'hmip',
|
||||||
|
}
|
||||||
|
hap = hmipc.HomematicipHAP(hass, entry)
|
||||||
|
with patch.object(hap, 'get_hap', return_value=mock_coro(home)):
|
||||||
|
assert await hap.async_setup() is True
|
||||||
|
|
||||||
|
assert hap.home is home
|
||||||
|
assert len(hass.services.async_register.mock_calls) == 0
|
||||||
|
assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 5
|
||||||
|
|
||||||
|
hass.config_entries.async_forward_entry_unload.return_value = \
|
||||||
|
mock_coro(True)
|
||||||
|
await hap.async_reset()
|
||||||
|
|
||||||
|
assert len(hass.config_entries.async_forward_entry_unload.mock_calls) == 5
|
@@ -74,7 +74,6 @@ async def test_setup_defined_hosts_no_known_auth(hass):
|
|||||||
}
|
}
|
||||||
}) is True
|
}) is True
|
||||||
|
|
||||||
# Flow started for discovered bridge
|
|
||||||
assert len(mock_config_entries.flow.mock_calls) == 1
|
assert len(mock_config_entries.flow.mock_calls) == 1
|
||||||
assert mock_config_entries.flow.mock_calls[0][2]['data'] == {
|
assert mock_config_entries.flow.mock_calls[0][2]['data'] == {
|
||||||
hmipc.HMIPC_HAPID: 'ABC123',
|
hmipc.HMIPC_HAPID: 'ABC123',
|
||||||
|
Reference in New Issue
Block a user