Fixes for mqtt config validation tests.

This commit is contained in:
Jan Harkes 2016-04-04 22:56:25 -04:00
parent 8cca2bb344
commit 58ea589f99
3 changed files with 6 additions and 10 deletions

View File

@ -129,7 +129,6 @@ def mock_mqtt_component(hass, mock_mqtt):
mqtt.CONF_BROKER: 'mock-broker',
}
})
hass.config.components.append(mqtt.DOMAIN)
return mock_mqtt

View File

@ -49,6 +49,7 @@ class TestMQTT(unittest.TestCase):
"""Test for setup failure if connection to broker is missing."""
with mock.patch('homeassistant.components.mqtt.MQTT',
side_effect=socket.error()):
self.hass.config.components = []
assert not _setup_component(self.hass, mqtt.DOMAIN, {
mqtt.DOMAIN: {
mqtt.CONF_BROKER: 'test-broker',
@ -214,12 +215,12 @@ class TestMQTTCallbacks(unittest.TestCase):
# mock_mqtt_component(self.hass)
with mock.patch('paho.mqtt.client.Client'):
_setup_component(self.hass, mqtt.DOMAIN, {
self.hass.config.components = []
assert _setup_component(self.hass, mqtt.DOMAIN, {
mqtt.DOMAIN: {
mqtt.CONF_BROKER: 'mock-broker',
}
})
self.hass.config.components.append(mqtt.DOMAIN)
def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that was started."""

View File

@ -33,13 +33,9 @@ class TestMQTT:
assert mock_mqtt.mock_calls[0][1][5] == 'homeassistant'
assert mock_mqtt.mock_calls[0][1][6] == password
@patch('homeassistant.components.mqtt.MQTT')
@patch('asyncio.gather')
@patch('asyncio.new_event_loop')
def test_creating_config_no_http_pass(self, mock_new_loop, mock_gather,
mock_mqtt):
"""Test if the MQTT server gets started and subscribe/publish msg."""
self.hass.config.components.append('http')
mock_mqtt.reset_mock()
self.hass.config.components = ['http']
self.hass.config.api = MagicMock(api_password=None)
assert _setup_component(self.hass, mqtt.DOMAIN, {})
assert mock_mqtt.called