Core support for hass.io calls & Bugfix check_config (#11571)
* Initial overwrites * Add check_config function. * Update hassio.py * Address comments * add hassio support * add more tests * revert core changes * Address check_config * Address comment with api_bool * Bugfix check_config * Update core.py * Update test_core.py * Update config.py * Update hassio.py * Update config.py * Update test_config.py
This commit is contained in:
1 parent
033e06868e
commit
f2cc00cc64
6 files changed
+179
-17
No files matched your search
@@ -7,6 +7,7 @@ import pytest
|
||||
|
||||
from homeassistant.const import HTTP_HEADER_HA_AUTH
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.hassio import async_check_config
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
@@ -60,6 +61,8 @@ def test_fail_setup_cannot_connect(hass):
|
||||
result = yield from async_setup_component(hass, 'hassio', {})
|
||||
assert not result
|
||||
|
||||
assert not hass.components.hassio.is_hassio()
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_api_ping(hass, aioclient_mock):
|
||||
@@ -75,7 +78,8 @@ def test_setup_api_ping(hass, aioclient_mock):
|
||||
assert result
|
||||
|
||||
assert aioclient_mock.call_count == 2
|
||||
assert hass.data['hassio_hass_version'] == "10.0"
|
||||
assert hass.components.hassio.get_homeassistant_version() == "10.0"
|
||||
assert hass.components.hassio.is_hassio()
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
@@ -215,6 +219,7 @@ def test_service_register(hassio_env, hass):
|
||||
assert hass.services.has_service('hassio', 'addon_stdin')
|
||||
assert hass.services.has_service('hassio', 'host_shutdown')
|
||||
assert hass.services.has_service('hassio', 'host_reboot')
|
||||
assert hass.services.has_service('hassio', 'host_reboot')
|
||||
assert hass.services.has_service('hassio', 'snapshot_full')
|
||||
assert hass.services.has_service('hassio', 'snapshot_partial')
|
||||
assert hass.services.has_service('hassio', 'restore_full')
|
||||
@@ -294,6 +299,57 @@ def test_service_calls(hassio_env, hass, aioclient_mock):
|
||||
'addons': ['test'], 'folders': ['ssl'], 'homeassistant': False}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_service_calls_core(hassio_env, hass, aioclient_mock):
|
||||
"""Call core service and check the API calls behind that."""
|
||||
assert (yield from async_setup_component(hass, 'hassio', {}))
|
||||
|
||||
aioclient_mock.post(
|
||||
"http://127.0.0.1/homeassistant/restart", json={'result': 'ok'})
|
||||
aioclient_mock.post(
|
||||
"http://127.0.0.1/homeassistant/stop", json={'result': 'ok'})
|
||||
aioclient_mock.post(
|
||||
"http://127.0.0.1/homeassistant/check", json={'result': 'ok'})
|
||||
|
||||
yield from hass.services.async_call('homeassistant', 'stop')
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
yield from hass.services.async_call('homeassistant', 'check_config')
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert aioclient_mock.call_count == 2
|
||||
|
||||
yield from hass.services.async_call('homeassistant', 'restart')
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert aioclient_mock.call_count == 4
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_check_config_ok(hassio_env, hass, aioclient_mock):
|
||||
"""Check Config that is okay."""
|
||||
assert (yield from async_setup_component(hass, 'hassio', {}))
|
||||
|
||||
aioclient_mock.post(
|
||||
"http://127.0.0.1/homeassistant/check", json={'result': 'ok'})
|
||||
|
||||
assert (yield from async_check_config(hass)) is None
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_check_config_fail(hassio_env, hass, aioclient_mock):
|
||||
"""Check Config that is wrong."""
|
||||
assert (yield from async_setup_component(hass, 'hassio', {}))
|
||||
|
||||
aioclient_mock.post(
|
||||
"http://127.0.0.1/homeassistant/check", json={
|
||||
'result': 'error', 'message': "Error"})
|
||||
|
||||
assert (yield from async_check_config(hass)) == "Error"
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_forward_request(hassio_client):
|
||||
"""Test fetching normal path."""
|
||||
|
||||
@@ -8,7 +8,7 @@ import pytest
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import updater
|
||||
import homeassistant.util.dt as dt_util
|
||||
from tests.common import async_fire_time_changed, mock_coro
|
||||
from tests.common import async_fire_time_changed, mock_coro, mock_component
|
||||
|
||||
NEW_VERSION = '10000.0'
|
||||
MOCK_VERSION = '10.0'
|
||||
@@ -174,3 +174,24 @@ def test_error_fetching_new_version_invalid_response(hass, aioclient_mock):
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res is None
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_new_version_shows_entity_after_hour_hassio(
|
||||
hass, mock_get_uuid, mock_get_newest_version):
|
||||
"""Test if new entity is created if new version is available / hass.io."""
|
||||
mock_get_uuid.return_value = MOCK_HUUID
|
||||
mock_get_newest_version.return_value = mock_coro((NEW_VERSION, ''))
|
||||
mock_component(hass, 'hassio')
|
||||
hass.data['hassio_hass_version'] = "999.0"
|
||||
|
||||
res = yield from async_setup_component(
|
||||
hass, updater.DOMAIN, {updater.DOMAIN: {}})
|
||||
assert res, 'Updater failed to setup'
|
||||
|
||||
with patch('homeassistant.components.updater.current_version',
|
||||
MOCK_VERSION):
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(hours=1))
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert hass.states.is_state(updater.ENTITY_ID, "999.0")
|
||||
Reference in new issue
Block a user