2017-02-12 11:31:46 -08:00
|
|
|
"""Test hassbian config."""
|
|
|
|
import asyncio
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from homeassistant.bootstrap import async_setup_component
|
|
|
|
from homeassistant.components import config
|
2017-05-25 21:13:53 -07:00
|
|
|
from tests.common import mock_coro
|
2017-02-12 11:31:46 -08:00
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-12-02 16:32:53 +01:00
|
|
|
def test_validate_config_ok(hass, hass_client):
|
2017-02-13 21:34:36 -08:00
|
|
|
"""Test checking config."""
|
2017-02-12 11:31:46 -08:00
|
|
|
with patch.object(config, 'SECTIONS', ['core']):
|
|
|
|
yield from async_setup_component(hass, 'config', {})
|
|
|
|
|
2017-03-01 05:33:19 +01:00
|
|
|
yield from asyncio.sleep(0.1, loop=hass.loop)
|
|
|
|
|
2018-12-02 16:32:53 +01:00
|
|
|
client = yield from hass_client()
|
2017-02-12 11:31:46 -08:00
|
|
|
|
|
|
|
with patch(
|
|
|
|
'homeassistant.components.config.core.async_check_ha_config_file',
|
2017-02-15 23:19:34 -08:00
|
|
|
return_value=mock_coro()):
|
2017-02-12 11:31:46 -08:00
|
|
|
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',
|
2017-02-15 23:19:34 -08:00
|
|
|
return_value=mock_coro('beer')):
|
2017-02-12 11:31:46 -08:00
|
|
|
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'
|