Fix Google Assistant User with Cloud (#22042)
* Fix Google Assistant User with Cloud * Fix User Agent ID * respell * Fix object * Fix tests * fix lint * Fix lint
This commit is contained in:
parent
3769f5893a
commit
6a80ffa8cc
5 changed files with 94 additions and 20 deletions
|
@ -1,24 +1,21 @@
|
|||
"""Test the cloud component."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_START)
|
||||
from homeassistant.auth.const import GROUP_ID_ADMIN
|
||||
from homeassistant.components import cloud
|
||||
from homeassistant.components.cloud.const import DOMAIN
|
||||
|
||||
from homeassistant.components.cloud.prefs import STORAGE_KEY
|
||||
from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
||||
from homeassistant.setup import async_setup_component
|
||||
from tests.common import mock_coro
|
||||
|
||||
|
||||
async def test_constructor_loads_info_from_config():
|
||||
async def test_constructor_loads_info_from_config(hass):
|
||||
"""Test non-dev mode loads info from SERVERS constant."""
|
||||
hass = MagicMock(data={})
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.cloud.prefs.CloudPreferences."
|
||||
"async_initialize",
|
||||
return_value=mock_coro()
|
||||
):
|
||||
result = await cloud.async_setup(hass, {
|
||||
with patch("hass_nabucasa.Cloud.start", return_value=mock_coro()):
|
||||
result = await async_setup_component(hass, 'cloud', {
|
||||
'http': {},
|
||||
'cloud': {
|
||||
cloud.CONF_MODE: cloud.MODE_DEV,
|
||||
'cognito_client_id': 'test-cognito_client_id',
|
||||
|
@ -79,3 +76,57 @@ async def test_startup_shutdown_events(hass, mock_cloud_fixture):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_stop.called
|
||||
|
||||
|
||||
async def test_setup_existing_cloud_user(hass, hass_storage):
|
||||
"""Test setup with API push default data."""
|
||||
user = await hass.auth.async_create_system_user('Cloud test')
|
||||
hass_storage[STORAGE_KEY] = {
|
||||
'version': 1,
|
||||
'data': {
|
||||
'cloud_user': user.id
|
||||
}
|
||||
}
|
||||
with patch('hass_nabucasa.Cloud.start', return_value=mock_coro()):
|
||||
result = await async_setup_component(hass, 'cloud', {
|
||||
'http': {},
|
||||
'cloud': {
|
||||
cloud.CONF_MODE: cloud.MODE_DEV,
|
||||
'cognito_client_id': 'test-cognito_client_id',
|
||||
'user_pool_id': 'test-user_pool_id',
|
||||
'region': 'test-region',
|
||||
'relayer': 'test-relayer',
|
||||
}
|
||||
})
|
||||
assert result
|
||||
|
||||
assert hass_storage[STORAGE_KEY]['data']['cloud_user'] == user.id
|
||||
|
||||
|
||||
async def test_setup_setup_cloud_user(hass, hass_storage):
|
||||
"""Test setup with API push default data."""
|
||||
hass_storage[STORAGE_KEY] = {
|
||||
'version': 1,
|
||||
'data': {
|
||||
'cloud_user': None
|
||||
}
|
||||
}
|
||||
with patch('hass_nabucasa.Cloud.start', return_value=mock_coro()):
|
||||
result = await async_setup_component(hass, 'cloud', {
|
||||
'http': {},
|
||||
'cloud': {
|
||||
cloud.CONF_MODE: cloud.MODE_DEV,
|
||||
'cognito_client_id': 'test-cognito_client_id',
|
||||
'user_pool_id': 'test-user_pool_id',
|
||||
'region': 'test-region',
|
||||
'relayer': 'test-relayer',
|
||||
}
|
||||
})
|
||||
assert result
|
||||
|
||||
cloud_user = await hass.auth.async_get_user(
|
||||
hass_storage[STORAGE_KEY]['data']['cloud_user']
|
||||
)
|
||||
|
||||
assert cloud_user
|
||||
assert cloud_user.groups[0].id == GROUP_ID_ADMIN
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue