2016-03-09 09:25:50 +00:00
|
|
|
"""Test the bootstrapping."""
|
2016-10-30 21:18:53 +00:00
|
|
|
# pylint: disable=protected-access
|
2017-02-18 19:31:37 +00:00
|
|
|
import asyncio
|
2016-11-30 21:02:45 +00:00
|
|
|
import os
|
2017-03-05 09:41:54 +00:00
|
|
|
from unittest.mock import Mock, patch
|
2016-10-08 18:27:35 +00:00
|
|
|
import logging
|
2015-08-11 15:20:13 +00:00
|
|
|
|
2016-11-30 21:02:45 +00:00
|
|
|
import homeassistant.config as config_util
|
2017-03-05 09:41:54 +00:00
|
|
|
from homeassistant import bootstrap
|
2015-08-11 15:20:13 +00:00
|
|
|
import homeassistant.util.dt as dt_util
|
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
from tests.common import patch_yaml_files, get_test_config_dir
|
2016-02-14 23:08:23 +00:00
|
|
|
|
2016-03-30 05:50:38 +00:00
|
|
|
ORIG_TIMEZONE = dt_util.DEFAULT_TIME_ZONE
|
2016-11-30 21:02:45 +00:00
|
|
|
VERSION_PATH = os.path.join(get_test_config_dir(), config_util.VERSION_FILE)
|
2015-08-11 15:20:13 +00:00
|
|
|
|
2016-10-08 18:27:35 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2016-03-30 05:50:38 +00:00
|
|
|
|
2018-01-27 19:58:27 +00:00
|
|
|
# prevent .HA_VERSION file from being written
|
2017-03-05 09:41:54 +00:00
|
|
|
@patch(
|
|
|
|
'homeassistant.bootstrap.conf_util.process_ha_config_upgrade', Mock())
|
|
|
|
@patch('homeassistant.util.location.detect_location_info',
|
|
|
|
Mock(return_value=None))
|
|
|
|
@patch('homeassistant.bootstrap.async_register_signal_handling', Mock())
|
|
|
|
@patch('os.path.isfile', Mock(return_value=True))
|
|
|
|
@patch('os.access', Mock(return_value=True))
|
|
|
|
@patch('homeassistant.bootstrap.async_enable_logging',
|
|
|
|
Mock(return_value=True))
|
|
|
|
def test_from_config_file(hass):
|
|
|
|
"""Test with configuration file."""
|
|
|
|
components = set(['browser', 'conversation', 'script'])
|
|
|
|
files = {
|
|
|
|
'config.yaml': ''.join('{}:\n'.format(comp) for comp in components)
|
|
|
|
}
|
2016-03-30 05:50:38 +00:00
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
with patch_yaml_files(files, True):
|
|
|
|
yield from bootstrap.async_from_config_file('config.yaml')
|
2016-03-30 05:50:38 +00:00
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
assert components == hass.config.components
|
2017-02-18 19:31:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2017-03-05 09:41:54 +00:00
|
|
|
@patch('homeassistant.bootstrap.async_enable_logging', Mock())
|
|
|
|
@patch('homeassistant.bootstrap.async_register_signal_handling', Mock())
|
|
|
|
def test_home_assistant_core_config_validation(hass):
|
|
|
|
"""Test if we pass in wrong information for HA conf."""
|
|
|
|
# Extensive HA conf validation testing is done
|
|
|
|
result = yield from bootstrap.async_from_config_dict({
|
|
|
|
'homeassistant': {
|
|
|
|
'latitude': 'some string'
|
|
|
|
}
|
|
|
|
}, hass)
|
|
|
|
assert result is None
|