Retry keyset cloud (#12270)
* Use less threads in helpers.event tests * Add helpers.event.async_call_later * Cloud: retry fetching keyset
This commit is contained in:
1 parent
134445f622
commit
f2296e1ff8
6 files changed
+66
-40
No files matched your search
@@ -14,8 +14,8 @@ from tests.common import mock_coro
|
||||
@pytest.fixture
|
||||
def cloud_client(hass, test_client):
|
||||
"""Fixture that can fetch from the cloud client."""
|
||||
with patch('homeassistant.components.cloud.Cloud.initialize',
|
||||
return_value=mock_coro(True)):
|
||||
with patch('homeassistant.components.cloud.Cloud.async_start',
|
||||
return_value=mock_coro()):
|
||||
hass.loop.run_until_complete(async_setup_component(hass, 'cloud', {
|
||||
'cloud': {
|
||||
'mode': 'development',
|
||||
|
||||
@@ -87,7 +87,7 @@ def test_initialize_loads_info(mock_os, hass):
|
||||
|
||||
with patch('homeassistant.components.cloud.open', mopen, create=True), \
|
||||
patch('homeassistant.components.cloud.Cloud._decode_claims'):
|
||||
cl._start_cloud(None)
|
||||
yield from cl.async_start(None)
|
||||
|
||||
assert cl.id_token == 'test-id-token'
|
||||
assert cl.access_token == 'test-access-token'
|
||||
|
||||
@@ -266,8 +266,8 @@ def test_handler_alexa(hass):
|
||||
hass.states.async_set(
|
||||
'switch.test2', 'on', {'friendly_name': "Test switch 2"})
|
||||
|
||||
with patch('homeassistant.components.cloud.Cloud.initialize',
|
||||
return_value=mock_coro(True)):
|
||||
with patch('homeassistant.components.cloud.Cloud.async_start',
|
||||
return_value=mock_coro()):
|
||||
setup = yield from async_setup_component(hass, 'cloud', {
|
||||
'cloud': {
|
||||
'alexa': {
|
||||
@@ -309,8 +309,8 @@ def test_handler_google_actions(hass):
|
||||
hass.states.async_set(
|
||||
'switch.test2', 'on', {'friendly_name': "Test switch 2"})
|
||||
|
||||
with patch('homeassistant.components.cloud.Cloud.initialize',
|
||||
return_value=mock_coro(True)):
|
||||
with patch('homeassistant.components.cloud.Cloud.async_start',
|
||||
return_value=mock_coro()):
|
||||
setup = yield from async_setup_component(hass, 'cloud', {
|
||||
'cloud': {
|
||||
'google_actions': {
|
||||
|
||||
@@ -7,10 +7,12 @@ from datetime import datetime, timedelta
|
||||
from astral import Astral
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.setup import setup_component
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.const import MATCH_ALL
|
||||
from homeassistant.helpers.event import (
|
||||
async_call_later,
|
||||
track_point_in_utc_time,
|
||||
track_point_in_time,
|
||||
track_utc_time_change,
|
||||
@@ -52,7 +54,7 @@ class TestEventHelpers(unittest.TestCase):
|
||||
runs = []
|
||||
|
||||
track_point_in_utc_time(
|
||||
self.hass, lambda x: runs.append(1), birthday_paulus)
|
||||
self.hass, callback(lambda x: runs.append(1)), birthday_paulus)
|
||||
|
||||
self._send_time_changed(before_birthday)
|
||||
self.hass.block_till_done()
|
||||
@@ -68,14 +70,14 @@ class TestEventHelpers(unittest.TestCase):
|
||||
self.assertEqual(1, len(runs))
|
||||
|
||||
track_point_in_time(
|
||||
self.hass, lambda x: runs.append(1), birthday_paulus)
|
||||
self.hass, callback(lambda x: runs.append(1)), birthday_paulus)
|
||||
|
||||
self._send_time_changed(after_birthday)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(2, len(runs))
|
||||
|
||||
unsub = track_point_in_time(
|
||||
self.hass, lambda x: runs.append(1), birthday_paulus)
|
||||
self.hass, callback(lambda x: runs.append(1)), birthday_paulus)
|
||||
unsub()
|
||||
|
||||
self._send_time_changed(after_birthday)
|
||||
@@ -642,3 +644,22 @@ class TestEventHelpers(unittest.TestCase):
|
||||
self._send_time_changed(datetime(2014, 5, 2, 0, 0, 0))
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(specific_runs))
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_async_call_later(hass):
|
||||
"""Test calling an action later."""
|
||||
def action(): pass
|
||||
now = datetime(2017, 12, 19, 15, 40, 0, tzinfo=dt_util.UTC)
|
||||
|
||||
with patch('homeassistant.helpers.event'
|
||||
'.async_track_point_in_utc_time') as mock, \
|
||||
patch('homeassistant.util.dt.utcnow', return_value=now):
|
||||
remove = async_call_later(hass, 3, action)
|
||||
|
||||
assert len(mock.mock_calls) == 1
|
||||
p_hass, p_action, p_point = mock.mock_calls[0][1]
|
||||
assert hass is hass
|
||||
assert p_action is action
|
||||
assert p_point == now + timedelta(seconds=3)
|
||||
assert remove is mock()
|
||||
Reference in new issue
Block a user