hass-core/tests/components/config/test_core.py
Paulus Schoutsen 36c196f9e8 Add initial Z-Wave config panel (#5937)
* Add Z-Wave config panel

* Add config to Z-Wave dependencies

* Lint

* lint

* Add tests

* Remove temp workaround

* Lint

* Fix tests

* Address comments

* Fix tests under Py34
2017-02-13 21:34:36 -08:00

39 lines
1.3 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', {})
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'