2017-02-12 01:29:05 +00:00
|
|
|
"""Test config init."""
|
2017-02-14 05:34:36 +00:00
|
|
|
import asyncio
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
2017-02-12 01:29:05 +00:00
|
|
|
import pytest
|
|
|
|
|
2017-02-14 05:34:36 +00:00
|
|
|
from homeassistant.const import EVENT_COMPONENT_LOADED
|
|
|
|
from homeassistant.bootstrap import async_setup_component, ATTR_COMPONENT
|
|
|
|
from homeassistant.components import config
|
2017-02-12 01:29:05 +00:00
|
|
|
|
2017-02-14 05:34:36 +00:00
|
|
|
from tests.common import mock_http_component, mock_coro
|
2017-02-12 01:29:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def stub_http(hass):
|
|
|
|
"""Stub the HTTP component."""
|
|
|
|
mock_http_component(hass)
|
|
|
|
|
|
|
|
|
2017-02-14 05:34:36 +00:00
|
|
|
@asyncio.coroutine
|
2017-02-12 01:29:05 +00:00
|
|
|
def test_config_setup(hass, loop):
|
|
|
|
"""Test it sets up hassbian."""
|
2017-02-14 05:34:36 +00:00
|
|
|
yield from async_setup_component(hass, 'config', {})
|
2017-02-12 01:29:05 +00:00
|
|
|
assert 'config' in hass.config.components
|
2017-02-14 05:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def test_load_on_demand_already_loaded(hass, test_client):
|
|
|
|
"""Test getting suites."""
|
|
|
|
hass.config.components.add('zwave')
|
|
|
|
|
|
|
|
with patch.object(config, 'SECTIONS', []), \
|
|
|
|
patch.object(config, 'ON_DEMAND', ['zwave']), \
|
|
|
|
patch('homeassistant.components.config.zwave.async_setup') as stp:
|
|
|
|
stp.return_value = mock_coro(True)()
|
|
|
|
|
|
|
|
yield from async_setup_component(hass, 'config', {})
|
|
|
|
|
|
|
|
yield from hass.async_block_till_done()
|
|
|
|
assert 'config.zwave' in hass.config.components
|
|
|
|
assert stp.called
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def test_load_on_demand_on_load(hass, test_client):
|
|
|
|
"""Test getting suites."""
|
|
|
|
with patch.object(config, 'SECTIONS', []), \
|
|
|
|
patch.object(config, 'ON_DEMAND', ['zwave']):
|
|
|
|
yield from async_setup_component(hass, 'config', {})
|
|
|
|
|
|
|
|
assert 'config.zwave' not in hass.config.components
|
|
|
|
|
|
|
|
with patch('homeassistant.components.config.zwave.async_setup') as stp:
|
|
|
|
stp.return_value = mock_coro(True)()
|
|
|
|
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: 'zwave'})
|
|
|
|
yield from hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert 'config.zwave' in hass.config.components
|
|
|
|
assert stp.called
|