-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to disable specific integrations (#16757)
* Add option to disable specific integrations * Lint
- Loading branch information
Showing
10 changed files
with
222 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
"""Tests for the cloud component.""" | ||
from unittest.mock import patch | ||
from homeassistant.setup import async_setup_component | ||
from homeassistant.components import cloud | ||
|
||
from jose import jwt | ||
|
||
from tests.common import mock_coro | ||
|
||
|
||
def mock_cloud(hass, config={}): | ||
"""Mock cloud.""" | ||
with patch('homeassistant.components.cloud.Cloud.async_start', | ||
return_value=mock_coro()): | ||
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 = { | ||
cloud.STORAGE_ENABLE_ALEXA: True, | ||
cloud.STORAGE_ENABLE_GOOGLE: True, | ||
} | ||
prefs_to_set.update(prefs) | ||
hass.data[cloud.DOMAIN]._prefs = prefs_to_set | ||
return prefs_to_set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Fixtures for cloud tests.""" | ||
import pytest | ||
|
||
from . import mock_cloud, mock_cloud_prefs | ||
|
||
|
||
@pytest.fixture | ||
def mock_cloud_fixture(hass): | ||
"""Fixture for cloud component.""" | ||
mock_cloud(hass) | ||
return mock_cloud_prefs(hass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,12 @@ | |
import pytest | ||
from jose import jwt | ||
|
||
from homeassistant.bootstrap import async_setup_component | ||
from homeassistant.components.cloud import DOMAIN, auth_api, iot | ||
from homeassistant.components.cloud import ( | ||
DOMAIN, auth_api, iot, STORAGE_ENABLE_GOOGLE, STORAGE_ENABLE_ALEXA) | ||
|
||
from tests.common import mock_coro | ||
|
||
from . import mock_cloud, mock_cloud_prefs | ||
|
||
GOOGLE_ACTIONS_SYNC_URL = 'https://api-test.hass.io/google_actions_sync' | ||
SUBSCRIPTION_INFO_URL = 'https://api-test.hass.io/subscription_info' | ||
|
@@ -25,22 +26,16 @@ def mock_auth(): | |
@pytest.fixture(autouse=True) | ||
def setup_api(hass): | ||
"""Initialize HTTP API.""" | ||
with patch('homeassistant.components.cloud.Cloud.async_start', | ||
return_value=mock_coro()): | ||
assert hass.loop.run_until_complete(async_setup_component( | ||
hass, 'cloud', { | ||
'cloud': { | ||
'mode': 'development', | ||
'cognito_client_id': 'cognito_client_id', | ||
'user_pool_id': 'user_pool_id', | ||
'region': 'region', | ||
'relayer': 'relayer', | ||
'google_actions_sync_url': GOOGLE_ACTIONS_SYNC_URL, | ||
'subscription_info_url': SUBSCRIPTION_INFO_URL, | ||
} | ||
})) | ||
hass.data['cloud']._decode_claims = \ | ||
lambda token: jwt.get_unverified_claims(token) | ||
mock_cloud(hass, { | ||
'mode': 'development', | ||
'cognito_client_id': 'cognito_client_id', | ||
'user_pool_id': 'user_pool_id', | ||
'region': 'region', | ||
'relayer': 'relayer', | ||
'google_actions_sync_url': GOOGLE_ACTIONS_SYNC_URL, | ||
'subscription_info_url': SUBSCRIPTION_INFO_URL, | ||
}) | ||
return mock_cloud_prefs(hass) | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -321,7 +316,7 @@ def test_resend_confirm_view_unknown_error(mock_cognito, cloud_client): | |
assert req.status == 502 | ||
|
||
|
||
async def test_websocket_status(hass, hass_ws_client): | ||
async def test_websocket_status(hass, hass_ws_client, mock_cloud_fixture): | ||
"""Test querying the status.""" | ||
hass.data[DOMAIN].id_token = jwt.encode({ | ||
'email': '[email protected]', | ||
|
@@ -338,6 +333,8 @@ async def test_websocket_status(hass, hass_ws_client): | |
'logged_in': True, | ||
'email': '[email protected]', | ||
'cloud': 'connected', | ||
'alexa_enabled': True, | ||
'google_enabled': True, | ||
} | ||
|
||
|
||
|
@@ -407,3 +404,26 @@ async def test_websocket_subscription_not_logged_in(hass, hass_ws_client): | |
|
||
assert not response['success'] | ||
assert response['error']['code'] == 'not_logged_in' | ||
|
||
|
||
async def test_websocket_update_preferences(hass, hass_ws_client, | ||
aioclient_mock, setup_api): | ||
"""Test updating preference.""" | ||
assert setup_api[STORAGE_ENABLE_GOOGLE] | ||
assert setup_api[STORAGE_ENABLE_ALEXA] | ||
hass.data[DOMAIN].id_token = jwt.encode({ | ||
'email': '[email protected]', | ||
'custom:sub-exp': '2018-01-03' | ||
}, 'test') | ||
client = await hass_ws_client(hass) | ||
await client.send_json({ | ||
'id': 5, | ||
'type': 'cloud/update_prefs', | ||
'alexa_enabled': False, | ||
'google_enabled': False, | ||
}) | ||
response = await client.receive_json() | ||
|
||
assert response['success'] | ||
assert not setup_api[STORAGE_ENABLE_GOOGLE] | ||
assert not setup_api[STORAGE_ENABLE_ALEXA] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.