Stub http component in tests

pull/202/head
Paulus Schoutsen 2015-07-11 00:02:52 -07:00
parent dea0fcc845
commit eb4bb6925f
4 changed files with 22 additions and 12 deletions

View File

@ -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. """

View File

@ -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. """

View File

@ -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):

View File

@ -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()