From eb4bb6925f73270b9addb337e0c383d7e617d25d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 11 Jul 2015 00:02:52 -0700 Subject: [PATCH] Stub http component in tests --- tests/helpers.py | 12 ++++++++++++ tests/test_component_demo.py | 3 +++ tests/test_component_history.py | 10 ++++------ tests/test_component_logbook.py | 9 +++------ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/helpers.py b/tests/helpers.py index c6799defe21..65fd0659108 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -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. """ diff --git a/tests/test_component_demo.py b/tests/test_component_demo.py index 3077b20a4da..d7a64167622 100644 --- a/tests/test_component_demo.py +++ b/tests/test_component_demo.py @@ -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. """ diff --git a/tests/test_component_history.py b/tests/test_component_history.py index b6ae8dab33f..7ad657f54b5 100644 --- a/tests/test_component_history.py +++ b/tests/test_component_history.py @@ -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): diff --git a/tests/test_component_logbook.py b/tests/test_component_logbook.py index 2f8f6b8c513..33b7b5f915b 100644 --- a/tests/test_component_logbook.py +++ b/tests/test_component_logbook.py @@ -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()