Add check_config API (#5898)
* Add check_config API * Add config panel to default config * Add tests * Lint * lint
This commit is contained in:
1 parent
dc6a28a8b2
commit
dab6d011ca
7 files changed
+107
-28
No files matched your search
@@ -0,0 +1,39 @@
|
||||
"""Test hassbian config."""
|
||||
import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
from homeassistant.components.config.core import CheckConfigView
|
||||
from tests.common import mock_http_component_app, mock_coro
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_validate_config_ok(hass, test_client):
|
||||
"""Test getting suites."""
|
||||
app = mock_http_component_app(hass)
|
||||
with patch.object(config, 'SECTIONS', ['core']):
|
||||
yield from async_setup_component(hass, 'config', {})
|
||||
|
||||
hass.http.views[CheckConfigView.name].register(app.router)
|
||||
client = yield from test_client(app)
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.config.core.async_check_ha_config_file',
|
||||
return_value=mock_coro(None)()):
|
||||
resp = yield from client.post('/api/config/core/check_config')
|
||||
|
||||
assert resp.status == 200
|
||||
result = yield from resp.json()
|
||||
assert result['result'] == 'valid'
|
||||
assert result['errors'] is None
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.config.core.async_check_ha_config_file',
|
||||
return_value=mock_coro('beer')()):
|
||||
resp = yield from client.post('/api/config/core/check_config')
|
||||
|
||||
assert resp.status == 200
|
||||
result = yield from resp.json()
|
||||
assert result['result'] == 'invalid'
|
||||
assert result['errors'] == 'beer'
|
||||
@@ -4,6 +4,7 @@ import os
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import config
|
||||
from homeassistant.components.config.hassbian import (
|
||||
HassbianSuitesView, HassbianSuiteInstallView)
|
||||
from tests.common import (
|
||||
@@ -13,7 +14,8 @@ from tests.common import (
|
||||
def test_setup_check_env_prevents_load(hass, loop):
|
||||
"""Test it does not set up hassbian if environment var not present."""
|
||||
mock_http_component(hass)
|
||||
with patch.dict(os.environ, clear=True):
|
||||
with patch.dict(os.environ, clear=True), \
|
||||
patch.object(config, 'SECTIONS', ['hassbian']):
|
||||
loop.run_until_complete(async_setup_component(hass, 'config', {}))
|
||||
assert 'config' in hass.config.components
|
||||
assert HassbianSuitesView.name not in hass.http.views
|
||||
@@ -23,7 +25,8 @@ def test_setup_check_env_prevents_load(hass, loop):
|
||||
def test_setup_check_env_works(hass, loop):
|
||||
"""Test it sets up hassbian if environment var present."""
|
||||
mock_http_component(hass)
|
||||
with patch.dict(os.environ, {'FORCE_HASSBIAN': '1'}):
|
||||
with patch.dict(os.environ, {'FORCE_HASSBIAN': '1'}), \
|
||||
patch.object(config, 'SECTIONS', ['hassbian']):
|
||||
loop.run_until_complete(async_setup_component(hass, 'config', {}))
|
||||
assert 'config' in hass.config.components
|
||||
assert HassbianSuitesView.name in hass.http.views
|
||||
@@ -35,7 +38,8 @@ def test_get_suites(hass, test_client):
|
||||
"""Test getting suites."""
|
||||
app = mock_http_component_app(hass)
|
||||
|
||||
with patch.dict(os.environ, {'FORCE_HASSBIAN': '1'}):
|
||||
with patch.dict(os.environ, {'FORCE_HASSBIAN': '1'}), \
|
||||
patch.object(config, 'SECTIONS', ['hassbian']):
|
||||
yield from async_setup_component(hass, 'config', {})
|
||||
|
||||
hass.http.views[HassbianSuitesView.name].register(app.router)
|
||||
@@ -56,7 +60,8 @@ def test_install_suite(hass, test_client):
|
||||
"""Test getting suites."""
|
||||
app = mock_http_component_app(hass)
|
||||
|
||||
with patch.dict(os.environ, {'FORCE_HASSBIAN': '1'}):
|
||||
with patch.dict(os.environ, {'FORCE_HASSBIAN': '1'}), \
|
||||
patch.object(config, 'SECTIONS', ['hassbian']):
|
||||
yield from async_setup_component(hass, 'config', {})
|
||||
|
||||
hass.http.views[HassbianSuiteInstallView.name].register(app.router)
|
||||
|
||||
@@ -396,16 +396,15 @@ class TestConfig(unittest.TestCase):
|
||||
process_mock = mock.MagicMock()
|
||||
attrs = {
|
||||
'communicate.return_value':
|
||||
mock_generator((r'\033[hellom'.encode('utf-8'), 'error')),
|
||||
mock_generator(('\033[34mhello'.encode('utf-8'), 'error')),
|
||||
'wait.return_value': mock_generator(1)}
|
||||
process_mock.configure_mock(**attrs)
|
||||
mock_create.return_value = mock_generator(process_mock)
|
||||
|
||||
with self.assertRaises(HomeAssistantError):
|
||||
run_coroutine_threadsafe(
|
||||
config_util.async_check_ha_config_file(self.hass),
|
||||
self.hass.loop
|
||||
).result()
|
||||
assert run_coroutine_threadsafe(
|
||||
config_util.async_check_ha_config_file(self.hass),
|
||||
self.hass.loop
|
||||
).result() == 'hello'
|
||||
|
||||
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
Reference in new issue
Block a user