Add some tests to the cloud component (#11460)
This commit is contained in:
parent
35f35050ff
commit
b7c7041873
3 changed files with 62 additions and 3 deletions
|
@ -72,7 +72,7 @@ def async_setup(hass, config):
|
|||
kwargs[CONF_GOOGLE_ASSISTANT] = ASSISTANT_SCHEMA({})
|
||||
|
||||
kwargs[CONF_ALEXA] = alexa_sh.Config(**kwargs[CONF_ALEXA])
|
||||
kwargs['gass_should_expose'] = kwargs.pop(CONF_GOOGLE_ASSISTANT)
|
||||
kwargs['gass_should_expose'] = kwargs.pop(CONF_GOOGLE_ASSISTANT)['filter']
|
||||
cloud = hass.data[DOMAIN] = Cloud(hass, **kwargs)
|
||||
|
||||
success = yield from cloud.initialize()
|
||||
|
|
|
@ -212,8 +212,8 @@ def async_handle_alexa(hass, cloud, payload):
|
|||
|
||||
@HANDLERS.register('google_actions')
|
||||
@asyncio.coroutine
|
||||
def async_handle_google_assistant(hass, cloud, payload):
|
||||
"""Handle an incoming IoT message for Google Assistant."""
|
||||
def async_handle_google_actions(hass, cloud, payload):
|
||||
"""Handle an incoming IoT message for Google Actions."""
|
||||
result = yield from ga.async_handle_message(hass, cloud.gass_config,
|
||||
payload)
|
||||
return result
|
||||
|
|
|
@ -5,7 +5,9 @@ from unittest.mock import patch, MagicMock, PropertyMock
|
|||
from aiohttp import WSMsgType, client_exceptions
|
||||
import pytest
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.cloud import iot, auth_api
|
||||
from tests.components.alexa import test_smart_home as test_alexa
|
||||
from tests.common import mock_coro
|
||||
|
||||
|
||||
|
@ -36,6 +38,16 @@ def mock_cloud():
|
|||
return MagicMock(subscription_expired=False)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cloud_instance(loop, hass):
|
||||
"""Instance of an initialized cloud class."""
|
||||
with patch('homeassistant.components.cloud.Cloud.initialize',
|
||||
return_value=mock_coro(True)):
|
||||
loop.run_until_complete(async_setup_component(hass, 'cloud', {}))
|
||||
|
||||
yield hass.data['cloud']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_cloud_calling_handler(mock_client, mock_handle_message, mock_cloud):
|
||||
"""Test we call handle message with correct info."""
|
||||
|
@ -254,3 +266,50 @@ def test_refresh_token_before_expiration_fails(hass, mock_cloud):
|
|||
|
||||
assert len(mock_check_token.mock_calls) == 1
|
||||
assert len(mock_create.mock_calls) == 1
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_handler_alexa(hass, cloud_instance):
|
||||
"""Test handler Alexa."""
|
||||
hass.states.async_set(
|
||||
'switch.test', 'on', {'friendly_name': "Test switch"})
|
||||
|
||||
resp = yield from iot.async_handle_alexa(
|
||||
hass, cloud_instance,
|
||||
test_alexa.get_new_request('Alexa.Discovery', 'Discover'))
|
||||
|
||||
endpoints = resp['event']['payload']['endpoints']
|
||||
|
||||
assert len(endpoints) == 1
|
||||
device = endpoints[0]
|
||||
|
||||
assert device['description'] == 'switch.test'
|
||||
assert device['friendlyName'] == 'Test switch'
|
||||
assert device['manufacturerName'] == 'Home Assistant'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_handler_google_actions(hass, cloud_instance):
|
||||
"""Test handler Google Actions."""
|
||||
hass.states.async_set(
|
||||
'switch.test', 'on', {'friendly_name': "Test switch"})
|
||||
|
||||
reqid = '5711642932632160983'
|
||||
data = {'requestId': reqid, 'inputs': [{'intent': 'action.devices.SYNC'}]}
|
||||
|
||||
with patch('homeassistant.components.cloud.Cloud._decode_claims',
|
||||
return_value={'cognito:username': 'myUserName'}):
|
||||
resp = yield from iot.async_handle_google_actions(
|
||||
hass, cloud_instance, data)
|
||||
|
||||
assert resp['requestId'] == reqid
|
||||
payload = resp['payload']
|
||||
|
||||
assert payload['agentUserId'] == 'myUserName'
|
||||
|
||||
devices = payload['devices']
|
||||
assert len(devices) == 1
|
||||
|
||||
device = devices[0]
|
||||
assert device['id'] == 'switch.test'
|
||||
assert device['name']['name'] == 'Test switch'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue