diff --git a/tests/common.py b/tests/common.py index 3b3cea6302e..d6dd6cd3279 100644 --- a/tests/common.py +++ b/tests/common.py @@ -9,6 +9,7 @@ from datetime import timedelta from unittest import mock import homeassistant as ha +import homeassistant.util.location as location_util import homeassistant.util.dt as dt_util from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import ( @@ -40,6 +41,23 @@ def get_test_home_assistant(num_threads=None): return hass +def mock_detect_location_info(): + """ Mock implementation of util.detect_location_info. """ + return location_util.LocationInfo( + ip='1.1.1.1', + country_code='US', + country_name='United States', + region_code='CA', + region_name='California', + city='San Diego', + zip_code='92122', + time_zone='America/Los_Angeles', + latitude='2.0', + longitude='1.0', + use_fahrenheit=True, + ) + + def mock_service(hass, domain, service): """ Sets up a fake service. diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py new file mode 100644 index 00000000000..df05964a79f --- /dev/null +++ b/tests/test_bootstrap.py @@ -0,0 +1,41 @@ +""" +tests.test_bootstrap +~~~~~~~~~~~~~~~~~~~~ + +Tests bootstrap. +""" +# pylint: disable=too-many-public-methods,protected-access +import tempfile +import unittest +from unittest import mock + +from homeassistant import bootstrap +import homeassistant.util.dt as dt_util + +from tests.common import mock_detect_location_info + + +class TestBootstrap(unittest.TestCase): + """ Test the bootstrap utils. """ + + def setUp(self): + self.orig_timezone = dt_util.DEFAULT_TIME_ZONE + + def tearDown(self): + dt_util.DEFAULT_TIME_ZONE = self.orig_timezone + + def test_from_config_file(self): + components = ['browser', 'conversation', 'script'] + with tempfile.NamedTemporaryFile() as fp: + for comp in components: + fp.write('{}:\n'.format(comp).encode('utf-8')) + fp.flush() + + with mock.patch('homeassistant.util.location.detect_location_info', + mock_detect_location_info): + hass = bootstrap.from_config_file(fp.name) + + components.append('group') + + self.assertEqual(sorted(components), + sorted(hass.config.components)) diff --git a/tests/test_config.py b/tests/test_config.py index 235549f6cef..b8d050d14ae 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -10,13 +10,12 @@ import unittest.mock as mock import os from homeassistant import DOMAIN, HomeAssistantError -import homeassistant.util.location as location_util import homeassistant.config as config_util from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, CONF_TEMPERATURE_UNIT, CONF_NAME, CONF_TIME_ZONE) -from common import get_test_config_dir +from common import get_test_config_dir, mock_detect_location_info CONFIG_DIR = get_test_config_dir() YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE) @@ -28,23 +27,6 @@ def create_file(path): pass -def mock_detect_location_info(): - """ Mock implementation of util.detect_location_info. """ - return location_util.LocationInfo( - ip='1.1.1.1', - country_code='US', - country_name='United States', - region_code='CA', - region_name='California', - city='San Diego', - zip_code='92122', - time_zone='America/Los_Angeles', - latitude='2.0', - longitude='1.0', - use_fahrenheit=True, - ) - - class TestConfig(unittest.TestCase): """ Test the config utils. """