2018-02-09 07:11:47 +00:00
|
|
|
"""Tests for the cloud component."""
|
2018-09-20 21:46:51 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from homeassistant.components import cloud
|
2018-11-20 22:23:07 +00:00
|
|
|
from homeassistant.components.cloud import const
|
2018-09-20 21:46:51 +00:00
|
|
|
|
|
|
|
from jose import jwt
|
|
|
|
|
|
|
|
from tests.common import mock_coro
|
|
|
|
|
|
|
|
|
|
|
|
def mock_cloud(hass, config={}):
|
|
|
|
"""Mock cloud."""
|
2019-03-11 19:21:20 +00:00
|
|
|
with patch('hass_nabucasa.Cloud.start', return_value=mock_coro()):
|
2018-09-20 21:46:51 +00:00
|
|
|
assert hass.loop.run_until_complete(async_setup_component(
|
|
|
|
hass, cloud.DOMAIN, {
|
|
|
|
'cloud': config
|
|
|
|
}))
|
|
|
|
|
|
|
|
hass.data[cloud.DOMAIN]._decode_claims = \
|
|
|
|
lambda token: jwt.get_unverified_claims(token)
|
|
|
|
|
|
|
|
|
|
|
|
def mock_cloud_prefs(hass, prefs={}):
|
|
|
|
"""Fixture for cloud component."""
|
|
|
|
prefs_to_set = {
|
2018-11-20 22:23:07 +00:00
|
|
|
const.PREF_ENABLE_ALEXA: True,
|
|
|
|
const.PREF_ENABLE_GOOGLE: True,
|
2019-04-19 21:50:21 +00:00
|
|
|
const.PREF_GOOGLE_SECURE_DEVICES_PIN: None,
|
2018-09-20 21:46:51 +00:00
|
|
|
}
|
|
|
|
prefs_to_set.update(prefs)
|
2019-03-11 19:21:20 +00:00
|
|
|
hass.data[cloud.DOMAIN].client._prefs._prefs = prefs_to_set
|
2018-09-20 21:46:51 +00:00
|
|
|
return prefs_to_set
|