Remove embedded MQTT broker (#37032)

This commit is contained in:
Erik Montnemery authored and GitHub committed 2020-06-23 09:51:50 -07:00
1 parent a004e6aa68
commit 1b3e5460a9
7 files changed
+3 -265

No files matched your search

-26
View File
@@ -670,32 +670,6 @@ async def test_restore_all_active_subscriptions_on_reconnect(
assert mqtt_client_mock.subscribe.mock_calls == expected
@pytest.fixture
def mqtt_server_start_mock(hass):
"""Mock embedded server start."""
client_config = ("localhost", 1883, "user", "pass", None, "3.1.1")
with patch(
"homeassistant.components.mqtt.server.async_start",
return_value=(True, client_config),
) as _start:
yield _start
@pytest.mark.parametrize("mqtt_config", [{}])
async def test_setup_embedded_starts_with_no_config(
hass, mqtt_server_start_mock, mqtt_mock
):
"""Test setting up embedded server with no config."""
assert mqtt_server_start_mock.call_count == 1
@pytest.mark.parametrize("mqtt_config", [{"embedded": None}])
async def test_setup_embedded_with_embedded(hass, mqtt_server_start_mock, mqtt_mock):
"""Test setting up embedded server with empty embedded config."""
assert mqtt_server_start_mock.call_count == 1
async def test_setup_logs_error_if_no_connect_broker(hass, caplog):
"""Test for setup failure if connection to broker is missing."""
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
-87
View File
@@ -1,87 +0,0 @@
"""The tests for the MQTT component embedded server."""
from unittest.mock import MagicMock, Mock
import pytest
import homeassistant.components.mqtt as mqtt
from homeassistant.const import CONF_PASSWORD
from homeassistant.setup import setup_component
from tests.async_mock import AsyncMock, patch
from tests.common import get_test_home_assistant, mock_coro
@pytest.fixture(autouse=True)
def inject_fixture(hass_storage):
"""Inject pytest fixtures."""
class TestMQTT:
"""Test the MQTT component."""
def setup_method(self, method):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def teardown_method(self, method):
"""Stop everything that was started."""
self.hass.stop()
@patch("passlib.apps.custom_app_context", Mock(return_value=""))
@patch("tempfile.NamedTemporaryFile", Mock(return_value=MagicMock()))
@patch("hbmqtt.broker.Broker", Mock(return_value=MagicMock(start=AsyncMock())))
@patch("hbmqtt.broker.Broker.start", AsyncMock(return_value=None))
@patch("homeassistant.components.mqtt.MQTT")
def test_creating_config_with_pass_and_no_http_pass(self, mock_mqtt):
"""Test if the MQTT server gets started with password.
Since 0.77, MQTT server has to set up its own password.
"""
mock_mqtt().async_connect = AsyncMock(return_value=True)
self.hass.bus.listen_once = MagicMock()
password = "mqtt_secret"
assert setup_component(
self.hass, mqtt.DOMAIN, {mqtt.DOMAIN: {CONF_PASSWORD: password}}
)
self.hass.block_till_done()
assert mock_mqtt.called
assert mock_mqtt.mock_calls[1][1][2]["username"] == "homeassistant"
assert mock_mqtt.mock_calls[1][1][2]["password"] == password
@patch("passlib.apps.custom_app_context", Mock(return_value=""))
@patch("tempfile.NamedTemporaryFile", Mock(return_value=MagicMock()))
@patch("hbmqtt.broker.Broker", Mock(return_value=MagicMock(start=AsyncMock())))
@patch("hbmqtt.broker.Broker.start", AsyncMock(return_value=None))
@patch("homeassistant.components.mqtt.MQTT")
def test_creating_config_with_pass_and_http_pass(self, mock_mqtt):
"""Test if the MQTT server gets started with password.
Since 0.77, MQTT server has to set up its own password.
"""
mock_mqtt().async_connect = AsyncMock(return_value=True)
self.hass.bus.listen_once = MagicMock()
password = "mqtt_secret"
self.hass.config.api = MagicMock(api_password="api_password")
assert setup_component(
self.hass, mqtt.DOMAIN, {mqtt.DOMAIN: {CONF_PASSWORD: password}}
)
self.hass.block_till_done()
assert mock_mqtt.called
assert mock_mqtt.mock_calls[1][1][2]["username"] == "homeassistant"
assert mock_mqtt.mock_calls[1][1][2]["password"] == password
@patch("tempfile.NamedTemporaryFile", Mock(return_value=MagicMock()))
@patch("hbmqtt.broker.Broker.start", return_value=mock_coro())
def test_broker_config_fails(self, mock_run):
"""Test if the MQTT component fails if server fails."""
from hbmqtt.broker import BrokerException
mock_run.side_effect = BrokerException
self.hass.config.api = MagicMock(api_password=None)
assert not setup_component(
self.hass, mqtt.DOMAIN, {mqtt.DOMAIN: {mqtt.CONF_EMBEDDED: {}}}
)