hass-core/tests/components/config/test_core.py
Pascal Vizeli 41f558b181 Bootstrap / Component setup async (#6264)
* Bootstrap / Entiy setup async

* Cleanup add_job stuff / return task/future object

* Address paulus comments / part 1

* fix install pip

* Cleanup bootstrap / move config stuff to config.py

* Make demo async

* Further bootstrap improvement

* Address Martin's comments

* Fix initial tests

* Fix final tests

* Fix bug with prepare loader

* Remove no longer needed things

* Log error when invalid config

* More cleanup

* Cleanups platform events & fix lint

* Use a non blocking add_entities callback for platform

* Fix Autoamtion is setup befor entity is ready

* Better automation fix

* Address paulus comments

* Typo

* fix lint

* rename functions

* fix tests

* fix test

* change exceptions

* fix spell
2017-02-28 20:33:19 -08:00

42 lines
1.4 KiB
Python

"""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 checking config."""
app = mock_http_component_app(hass)
with patch.object(config, 'SECTIONS', ['core']):
yield from async_setup_component(hass, 'config', {})
# yield from hass.async_block_till_done()
yield from asyncio.sleep(0.1, loop=hass.loop)
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()):
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'