Beispiel #1
0
def mock_mqtt_component(hass, mock_mqtt, mock_mqtt_publish):
    mqtt.setup(hass, {mqtt.DOMAIN: {
        mqtt.CONF_BROKER: 'mock-broker',
    }})
    hass.config.components.append(mqtt.DOMAIN)

    return mock_mqtt_publish
def mock_mqtt_component(hass):
    with mock.patch('homeassistant.components.mqtt.MQTT'):
        mqtt.setup(hass, {
            mqtt.DOMAIN: {
                mqtt.CONF_BROKER: 'mock-broker',
            }
        })
        hass.config.components.append(mqtt.DOMAIN)
Beispiel #3
0
def mock_mqtt_component(hass, mock_mqtt):
    mqtt.setup(hass, {
        mqtt.DOMAIN: {
            mqtt.CONF_BROKER: 'mock-broker',
        }
    })
    hass.config.components.append(mqtt.DOMAIN)
    return mock_mqtt
Beispiel #4
0
def mock_mqtt_component(hass):
    with mock.patch('homeassistant.components.mqtt.MQTT'):
        mqtt.setup(hass, {
            mqtt.DOMAIN: {
                mqtt.CONF_BROKER: 'mock-broker',
            }
        })
        hass.config.components.append(mqtt.DOMAIN)
Beispiel #5
0
def mock_mqtt_component(hass, mock_mqtt):
    """Mock the MQTT component."""
    mqtt.setup(hass, {
        mqtt.DOMAIN: {
            mqtt.CONF_BROKER: 'mock-broker',
        }
    })
    hass.config.components.append(mqtt.DOMAIN)
    return mock_mqtt
Beispiel #6
0
    def setUp(self):  # pylint: disable=invalid-name
        self.hass = get_test_home_assistant(1)
        # mock_mqtt_component(self.hass)

        with mock.patch('paho.mqtt.client.Client'):
            mqtt.setup(self.hass,
                       {mqtt.DOMAIN: {
                           mqtt.CONF_BROKER: 'mock-broker',
                       }})
            self.hass.config.components.append(mqtt.DOMAIN)
    def setUp(self):  # pylint: disable=invalid-name
        self.hass = get_test_home_assistant(1)
        # mock_mqtt_component(self.hass)

        with mock.patch('paho.mqtt.client.Client'):
            mqtt.setup(self.hass, {
                mqtt.DOMAIN: {
                    mqtt.CONF_BROKER: 'mock-broker',
                }
            })
            self.hass.config.components.append(mqtt.DOMAIN)
Beispiel #8
0
 def test_setup_fails_if_no_connect_broker(self):
     """Test for setup failure if connection to broker is missing."""
     with mock.patch('homeassistant.components.mqtt.MQTT',
                     side_effect=socket.error()):
         self.assertFalse(mqtt.setup(self.hass, {mqtt.DOMAIN: {
             mqtt.CONF_BROKER: 'test-broker',
         }}))
Beispiel #9
0
 def test_setup_fails_if_no_connect_broker(self):
     with mock.patch('homeassistant.components.mqtt.MQTT',
                     side_effect=socket.error()):
         self.assertFalse(
             mqtt.setup(self.hass,
                        {mqtt.DOMAIN: {
                            mqtt.CONF_BROKER: 'test-broker',
                        }}))
Beispiel #10
0
    def test_broker_config_fails(self, mock_new_loop, mock_gather):
        """Test if the MQTT component fails if server fails."""
        self.hass.config.components.append('http')
        from hbmqtt.broker import BrokerException

        mock_gather.side_effect = BrokerException

        self.hass.config.api = MagicMock(api_password=None)
        assert not mqtt.setup(self.hass, {'mqtt': {'embedded': {}}})
Beispiel #11
0
    def test_creating_config_with_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')
        password = '******'

        self.hass.config.api = MagicMock(api_password=password)
        assert mqtt.setup(self.hass, {})
        assert mock_mqtt.called
        assert mock_mqtt.mock_calls[0][1][5] == 'homeassistant'
        assert mock_mqtt.mock_calls[0][1][6] == password

        mock_mqtt.reset_mock()

        self.hass.config.api = MagicMock(api_password=None)
        assert mqtt.setup(self.hass, {})
        assert mock_mqtt.called
        assert mock_mqtt.mock_calls[0][1][5] is None
        assert mock_mqtt.mock_calls[0][1][6] is None
Beispiel #12
0
    def test_creating_config_with_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')
        password = '******'

        self.hass.config.api = MagicMock(api_password=password)
        assert mqtt.setup(self.hass, {})
        assert mock_mqtt.called
        assert mock_mqtt.mock_calls[0][1][5] == 'homeassistant'
        assert mock_mqtt.mock_calls[0][1][6] == password

        mock_mqtt.reset_mock()

        self.hass.config.api = MagicMock(api_password=None)
        assert mqtt.setup(self.hass, {})
        assert mock_mqtt.called
        assert mock_mqtt.mock_calls[0][1][5] is None
        assert mock_mqtt.mock_calls[0][1][6] is None
Beispiel #13
0
    def test_broker_config_fails(self, mock_new_loop, mock_gather):
        """Test if the MQTT component fails if server fails."""
        self.hass.config.components.append('http')
        from hbmqtt.broker import BrokerException

        mock_gather.side_effect = BrokerException

        self.hass.config.api = MagicMock(api_password=None)
        assert not mqtt.setup(self.hass, {
            'mqtt': {'embedded': {}}
        })
Beispiel #14
0
 def test_setup_fails_if_no_broker_config(self):
     self.assertFalse(mqtt.setup(self.hass, {mqtt.DOMAIN: {}}))
Beispiel #15
0
 def test_setup_fails_if_no_broker_config(self):
     """Test for setup failure if broker configuration is missing."""
     self.assertFalse(mqtt.setup(self.hass, {mqtt.DOMAIN: {}}))
Beispiel #16
0
 def test_setup_fails_if_no_broker_config(self):
     """Test for setup failure if broker configuration is missing."""
     self.assertFalse(mqtt.setup(self.hass, {mqtt.DOMAIN: {}}))
 def test_setup_fails_if_no_broker_config(self):
     self.assertFalse(mqtt.setup(self.hass, {mqtt.DOMAIN: {}}))