Use mock storage for MQTT tests (#33553)
* mock storage for MQTT * more mqtt storage mockspull/33555/head
parent
36a606f81d
commit
201e958854
|
@ -33,6 +33,7 @@ from tests.common import (
|
|||
mock_device_registry,
|
||||
mock_mqtt_component,
|
||||
mock_registry,
|
||||
mock_storage,
|
||||
threadsafe_coroutine_factory,
|
||||
)
|
||||
|
||||
|
@ -83,12 +84,15 @@ class TestMQTTComponent(unittest.TestCase):
|
|||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mock_storage = mock_storage()
|
||||
self.mock_storage.__enter__()
|
||||
mock_mqtt_component(self.hass)
|
||||
self.calls = []
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
self.mock_storage.__exit__(None, None, None)
|
||||
|
||||
@callback
|
||||
def record_calls(self, *args):
|
||||
|
@ -298,12 +302,15 @@ class TestMQTTCallbacks(unittest.TestCase):
|
|||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mock_storage = mock_storage()
|
||||
self.mock_storage.__enter__()
|
||||
mock_mqtt_client(self.hass)
|
||||
self.calls = []
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
self.mock_storage.__exit__(None, None, None)
|
||||
|
||||
@callback
|
||||
def record_calls(self, *args):
|
||||
|
|
|
@ -7,7 +7,7 @@ import homeassistant.components.mqtt as mqtt
|
|||
from homeassistant.const import CONF_PASSWORD
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_coro
|
||||
from tests.common import get_test_home_assistant, mock_coro, mock_storage
|
||||
|
||||
|
||||
class TestMQTT:
|
||||
|
@ -16,10 +16,13 @@ class TestMQTT:
|
|||
def setup_method(self, method):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mock_storage = mock_storage()
|
||||
self.mock_storage.__enter__()
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
self.mock_storage.__exit__(None, None, None)
|
||||
|
||||
@patch("passlib.apps.custom_app_context", Mock(return_value=""))
|
||||
@patch("tempfile.NamedTemporaryFile", Mock(return_value=MagicMock()))
|
||||
|
|
|
@ -15,6 +15,7 @@ from tests.common import (
|
|||
get_test_home_assistant,
|
||||
mock_mqtt_component,
|
||||
mock_state_change_event,
|
||||
mock_storage,
|
||||
)
|
||||
|
||||
|
||||
|
@ -24,11 +25,14 @@ class TestMqttEventStream:
|
|||
def setup_method(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mock_storage = mock_storage()
|
||||
self.mock_storage.__enter__()
|
||||
self.mock_mqtt = mock_mqtt_component(self.hass)
|
||||
|
||||
def teardown_method(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
self.mock_storage.__exit__(None, None, None)
|
||||
|
||||
def add_eventstream(self, sub_topic=None, pub_topic=None, ignore_event=None):
|
||||
"""Add a mqtt_eventstream component."""
|
||||
|
|
|
@ -9,6 +9,7 @@ from tests.common import (
|
|||
get_test_home_assistant,
|
||||
mock_mqtt_component,
|
||||
mock_state_change_event,
|
||||
mock_storage,
|
||||
)
|
||||
|
||||
|
||||
|
@ -18,11 +19,14 @@ class TestMqttStateStream:
|
|||
def setup_method(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mock_storage = mock_storage()
|
||||
self.mock_storage.__enter__()
|
||||
self.mock_mqtt = mock_mqtt_component(self.hass)
|
||||
|
||||
def teardown_method(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
self.mock_storage.__exit__(None, None, None)
|
||||
|
||||
def add_statestream(
|
||||
self,
|
||||
|
|
Loading…
Reference in New Issue