Esempio n. 1
0
    def test_publish_success(self, _mock_utils, mock_paho, _mock_json):
        """
        Should publish a message successfully
        """
        mock_paho.Client().publish.return_value = (0, MagicMock())
        client = MQTTClient("123", "987", False, False)

        client.publish()

        mock_paho.Client().publish.assert_called_once()
        keys_len = len(client.pubmmap.keys())
        self.assertGreater(keys_len, 0)
Esempio n. 2
0
    def test_publish_error(self, mock_utils, mock_paho, _mock_json):
        """
        Should not publish a message successfully
        """
        mock_paho.Client().publish.return_value = (10, MagicMock())
        client = MQTTClient("123", "987", False, False)

        client.publish()
        mock_utils.error_message.assert_called_once_with(10)
        mock_utils.fire_locust_failure.assert_called_once()

        keys_len = len(client.pubmmap.keys())
        self.assertEqual(keys_len, 0)