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)
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):
""" Provides a fake module. """

View File

@ -9,12 +9,15 @@ import unittest
import homeassistant as ha
import homeassistant.components.demo as demo
from helpers import mock_http_component
class TestDemo(unittest.TestCase):
""" Test the demo module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
mock_http_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -11,11 +11,10 @@ import unittest
import homeassistant as ha
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
SERVER_PORT = 8126
from helpers import (
mock_http_component, mock_state_change_event, get_test_home_assistant)
class TestComponentHistory(unittest.TestCase):
@ -42,8 +41,7 @@ class TestComponentHistory(unittest.TestCase):
def test_setup(self):
""" Test setup method of history. """
http.setup(self.hass, {
http.DOMAIN: {http.CONF_SERVER_PORT: SERVER_PORT}})
mock_http_component(self.hass)
self.assertTrue(history.setup(self.hass, {}))
def test_last_5_states(self):

View File

@ -12,11 +12,9 @@ import homeassistant as ha
from homeassistant.const import (
EVENT_STATE_CHANGED, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
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
SERVER_PORT = 8127
from helpers import get_test_home_assistant, mock_http_component
class TestComponentHistory(unittest.TestCase):
@ -26,8 +24,7 @@ class TestComponentHistory(unittest.TestCase):
""" Test setup method. """
try:
hass = get_test_home_assistant()
http.setup(hass, {
http.DOMAIN: {http.CONF_SERVER_PORT: SERVER_PORT}})
mock_http_component(hass)
self.assertTrue(logbook.setup(hass, {}))
finally:
hass.stop()