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:
Pascal Vizeli 2018-01-12 15:29:58 +01:00 committed by GitHub
parent 8a301c6c59
commit dacd7cd8a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 179 additions and 17 deletions

View file

@ -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."""