mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Only create cloud user if cloud in use (#29150)
* Only create cloud user if cloud in use * Pass context to alexa * Update requirements * Fix handing & design pattern for 0.30 * fix tests * Fix lint & tests * rename internal user
This commit is contained in:
committed by
Pascal Vizeli
parent
5d5d053bce
commit
b847d55077
@@ -5,7 +5,6 @@ import pytest
|
||||
|
||||
from homeassistant.core import Context
|
||||
from homeassistant.exceptions import Unauthorized
|
||||
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
|
||||
@@ -142,68 +141,11 @@ async def test_setup_existing_cloud_user(hass, hass_storage):
|
||||
assert hass_storage[STORAGE_KEY]["data"]["cloud_user"] == user.id
|
||||
|
||||
|
||||
async def test_setup_invalid_cloud_user(hass, hass_storage):
|
||||
"""Test setup with API push default data."""
|
||||
hass_storage[STORAGE_KEY] = {"version": 1, "data": {"cloud_user": "non-existing"}}
|
||||
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"] != "non-existing"
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
async def test_on_connect(hass, mock_cloud_fixture):
|
||||
"""Test cloud on connect triggers."""
|
||||
cl = hass.data["cloud"]
|
||||
|
||||
assert len(cl.iot._on_connect) == 4
|
||||
assert len(cl.iot._on_connect) == 3
|
||||
|
||||
assert len(hass.states.async_entity_ids("binary_sensor")) == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user