Beispiel #1
0
 def setUp(self):
     logger.info('-------------- %s starting...', self._testMethodName)
     self.rcv_message = None
     try:
         self.connector = MQTTConnector(broker=self.BROKER_HOST,
                                        port=61613,
                                        logger=logger.getChild('connector'))
         self.connector.run()
     except Exception:
         logger.error('Ignoring test : Apollo is not running')
         self.skipTest('%s skipped' % self._testMethodName)
Beispiel #2
0
 def setUp(self):
     logger.info('-------------- %s starting...', self._testMethodName)
     self.rcv_message = None
     try:
         self.connector = MQTTConnector(broker=self.BROKER_HOST, port=61613, logger=logger.getChild('connector'))
         self.connector.run()
     except Exception:
         logger.error('Ignoring test : Apollo is not running')
         self.skipTest('%s skipped' % self._testMethodName)
Beispiel #3
0
class MQTTConnectorTestCase(unittest.TestCase):
    BROKER_HOST = 'wisdom-cloud.local'
    TOPIC = 'test'
    rcv_message = None

    def setUp(self):
        logger.info('-------------- %s starting...', self._testMethodName)
        self.rcv_message = None
        try:
            self.connector = MQTTConnector(broker=self.BROKER_HOST, port=61613, logger=logger.getChild('connector'))
            self.connector.run()
        except Exception:
            logger.error('Ignoring test : Apollo is not running')
            self.skipTest('%s skipped' % self._testMethodName)

    def tearDown(self):
        self.connector.shutdown()

    def test_01_publish(self):
        logger.debug('first publish')
        result, mid = self.connector.publish(self.TOPIC, 'Hello')
        self.assertEqual(result, mqtt_client.MQTT_ERR_SUCCESS)

        logger.debug('shutdown')
        self.connector.shutdown()

        logger.debug('second publish (should fail)')
        with self.assertRaises(MQTTNotConnectedError):
            self.connector.publish(self.TOPIC, 'Hello')

    def test_02_subscribe(self):
        result, mid = self.connector.subscribe(self.TOPIC)
        self.assertEqual(result, mqtt_client.MQTT_ERR_SUCCESS)

        self.connector.on_message = self._msg_handler

        data = 'Hello'
        result, mid = self.connector.publish(self.TOPIC, data)
        self.assertEqual(result, mqtt_client.MQTT_ERR_SUCCESS)

        time.sleep(0.1)
        self.assertEqual(self.rcv_message, data)

        result, mid = self.connector.unsubscribe(self.TOPIC)
        self.assertEqual(result, mqtt_client.MQTT_ERR_SUCCESS)

    def _msg_handler(self, client, userdata, message):
        self.rcv_message = message.payload
Beispiel #4
0
class MQTTConnectorTestCase(unittest.TestCase):
    BROKER_HOST = 'wisdom-cloud.local'
    TOPIC = 'test'
    rcv_message = None

    def setUp(self):
        logger.info('-------------- %s starting...', self._testMethodName)
        self.rcv_message = None
        try:
            self.connector = MQTTConnector(broker=self.BROKER_HOST,
                                           port=61613,
                                           logger=logger.getChild('connector'))
            self.connector.run()
        except Exception:
            logger.error('Ignoring test : Apollo is not running')
            self.skipTest('%s skipped' % self._testMethodName)

    def tearDown(self):
        self.connector.shutdown()

    def test_01_publish(self):
        logger.debug('first publish')
        result, mid = self.connector.publish(self.TOPIC, 'Hello')
        self.assertEqual(result, mqtt_client.MQTT_ERR_SUCCESS)

        logger.debug('shutdown')
        self.connector.shutdown()

        logger.debug('second publish (should fail)')
        with self.assertRaises(MQTTNotConnectedError):
            self.connector.publish(self.TOPIC, 'Hello')

    def test_02_subscribe(self):
        result, mid = self.connector.subscribe(self.TOPIC)
        self.assertEqual(result, mqtt_client.MQTT_ERR_SUCCESS)

        self.connector.on_message = self._msg_handler

        data = 'Hello'
        result, mid = self.connector.publish(self.TOPIC, data)
        self.assertEqual(result, mqtt_client.MQTT_ERR_SUCCESS)

        time.sleep(0.1)
        self.assertEqual(self.rcv_message, data)

        result, mid = self.connector.unsubscribe(self.TOPIC)
        self.assertEqual(result, mqtt_client.MQTT_ERR_SUCCESS)

    def _msg_handler(self, client, userdata, message):
        self.rcv_message = message.payload