core/tests/components/config/test_core.py

39 lines
1.2 KiB
Python
Raw Normal View History

"""Test hassbian config."""
import asyncio
from unittest.mock import patch
from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from tests.common import mock_coro
@asyncio.coroutine
def test_validate_config_ok(hass, test_client):
"""Test checking config."""
with patch.object(config, 'SECTIONS', ['core']):
yield from async_setup_component(hass, 'config', {})
yield from asyncio.sleep(0.1, loop=hass.loop)
client = yield from test_client(hass.http.app)
with patch(
'homeassistant.components.config.core.async_check_ha_config_file',
2017-02-16 07:19:34 +00:00
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',
2017-02-16 07:19:34 +00:00
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'