Fix Alexa Report State (#26305)

* Fix Alexa Report State

* Forgot to save a file
This commit is contained in:
Paulus Schoutsen authored and Andrew Sayre committed 2019-08-30 20:34:40 -05:00
1 parent 37a3d5fd85
commit 7b05ede297
6 files changed
+81 -10

No files matched your search

+37 -1
View File
@@ -1,6 +1,6 @@
"""Test Alexa config."""
import contextlib
from unittest.mock import patch
from unittest.mock import patch, Mock
from homeassistant.components.cloud import ALEXA_SCHEMA, alexa_config
from homeassistant.util.dt import utcnow
@@ -43,6 +43,42 @@ async def test_alexa_config_report_state(hass, cloud_prefs):
assert conf.is_reporting_states is False
async def test_alexa_config_invalidate_token(hass, cloud_prefs, aioclient_mock):
"""Test Alexa config should expose using prefs."""
aioclient_mock.post(
"http://example/alexa_token",
json={
"access_token": "mock-token",
"event_endpoint": "http://example.com/alexa_endpoint",
"expires_in": 30,
},
)
conf = alexa_config.AlexaConfig(
hass,
ALEXA_SCHEMA({}),
cloud_prefs,
Mock(
alexa_access_token_url="http://example/alexa_token",
run_executor=Mock(side_effect=mock_coro),
websession=hass.helpers.aiohttp_client.async_get_clientsession(),
),
)
token = await conf.async_get_access_token()
assert token == "mock-token"
assert len(aioclient_mock.mock_calls) == 1
token = await conf.async_get_access_token()
assert token == "mock-token"
assert len(aioclient_mock.mock_calls) == 1
assert conf._token_valid is not None
conf.async_invalidate_access_token()
assert conf._token_valid is None
token = await conf.async_get_access_token()
assert token == "mock-token"
assert len(aioclient_mock.mock_calls) == 2
@contextlib.contextmanager
def patch_sync_helper():
"""Patch sync helper.