Stub http component in tests
parent
dea0fcc845
commit
eb4bb6925f
|
@ -90,6 +90,18 @@ def mock_state_change_event(hass, new_state, old_state=None):
|
||||||
hass.bus.fire(EVENT_STATE_CHANGED, event_data)
|
hass.bus.fire(EVENT_STATE_CHANGED, event_data)
|
||||||
|
|
||||||
|
|
||||||
|
def mock_http_component(hass):
|
||||||
|
hass.http = MockHTTP()
|
||||||
|
hass.config.components.append('http')
|
||||||
|
|
||||||
|
|
||||||
|
class MockHTTP(object):
|
||||||
|
""" Mocks the HTTP module. """
|
||||||
|
|
||||||
|
def register_path(self, method, url, callback, require_auth=True):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MockModule(object):
|
class MockModule(object):
|
||||||
""" Provides a fake module. """
|
""" Provides a fake module. """
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,15 @@ import unittest
|
||||||
import homeassistant as ha
|
import homeassistant as ha
|
||||||
import homeassistant.components.demo as demo
|
import homeassistant.components.demo as demo
|
||||||
|
|
||||||
|
from helpers import mock_http_component
|
||||||
|
|
||||||
|
|
||||||
class TestDemo(unittest.TestCase):
|
class TestDemo(unittest.TestCase):
|
||||||
""" Test the demo module. """
|
""" Test the demo module. """
|
||||||
|
|
||||||
def setUp(self): # pylint: disable=invalid-name
|
def setUp(self): # pylint: disable=invalid-name
|
||||||
self.hass = ha.HomeAssistant()
|
self.hass = ha.HomeAssistant()
|
||||||
|
mock_http_component(self.hass)
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
|
|
|
@ -11,11 +11,10 @@ import unittest
|
||||||
|
|
||||||
import homeassistant as ha
|
import homeassistant as ha
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.components import history, recorder, http
|
from homeassistant.components import history, recorder
|
||||||
|
|
||||||
from helpers import get_test_home_assistant, mock_state_change_event
|
from helpers import (
|
||||||
|
mock_http_component, mock_state_change_event, get_test_home_assistant)
|
||||||
SERVER_PORT = 8126
|
|
||||||
|
|
||||||
|
|
||||||
class TestComponentHistory(unittest.TestCase):
|
class TestComponentHistory(unittest.TestCase):
|
||||||
|
@ -42,8 +41,7 @@ class TestComponentHistory(unittest.TestCase):
|
||||||
|
|
||||||
def test_setup(self):
|
def test_setup(self):
|
||||||
""" Test setup method of history. """
|
""" Test setup method of history. """
|
||||||
http.setup(self.hass, {
|
mock_http_component(self.hass)
|
||||||
http.DOMAIN: {http.CONF_SERVER_PORT: SERVER_PORT}})
|
|
||||||
self.assertTrue(history.setup(self.hass, {}))
|
self.assertTrue(history.setup(self.hass, {}))
|
||||||
|
|
||||||
def test_last_5_states(self):
|
def test_last_5_states(self):
|
||||||
|
|
|
@ -12,11 +12,9 @@ import homeassistant as ha
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_STATE_CHANGED, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
EVENT_STATE_CHANGED, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.components import logbook, http
|
from homeassistant.components import logbook
|
||||||
|
|
||||||
from helpers import get_test_home_assistant
|
from helpers import get_test_home_assistant, mock_http_component
|
||||||
|
|
||||||
SERVER_PORT = 8127
|
|
||||||
|
|
||||||
|
|
||||||
class TestComponentHistory(unittest.TestCase):
|
class TestComponentHistory(unittest.TestCase):
|
||||||
|
@ -26,8 +24,7 @@ class TestComponentHistory(unittest.TestCase):
|
||||||
""" Test setup method. """
|
""" Test setup method. """
|
||||||
try:
|
try:
|
||||||
hass = get_test_home_assistant()
|
hass = get_test_home_assistant()
|
||||||
http.setup(hass, {
|
mock_http_component(hass)
|
||||||
http.DOMAIN: {http.CONF_SERVER_PORT: SERVER_PORT}})
|
|
||||||
self.assertTrue(logbook.setup(hass, {}))
|
self.assertTrue(logbook.setup(hass, {}))
|
||||||
finally:
|
finally:
|
||||||
hass.stop()
|
hass.stop()
|
||||||
|
|
Loading…
Reference in New Issue