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)
|
||||
|
||||
|
||||
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. """
|
||||
|
||||
|
|
|
@ -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. """
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue