def test_publish_recv_qos2(self): self.called = False def onPublish(topic, payload, qos, dup, retain, msgId): self.called = True self.topic = topic self.payload = payload.decode('utf-8') self.qos = qos self.retain = retain self.msgId = msgId self.dup = dup self.protocol.onPublish = onPublish pub =PUBLISH() pub.qos = 2 pub.dup = False pub.retain = False pub.topic = "foo/bar/baz2" pub.msgId = 1 pub.payload = "Hello world 2" self.protocol.dataReceived(pub.encode()) self.transport.clear() self.assertEqual(self.called, False) rel = PUBREL() rel.msgId = pub.msgId self.protocol.dataReceived(rel.encode()) self.assertEqual(self.topic, pub.topic) self.assertEqual(self.payload, pub.payload) self.assertEqual(self.qos, pub.qos) self.assertEqual(self.retain, pub.retain) self.assertEqual(self.msgId, pub.msgId ) self.assertEqual(self.dup, pub.dup )
def test_publish_recv_qos2(self): self.called = False def onPublish(topic, payload, qos, dup, retain, msgId): self.called = True self.topic = topic self.payload = payload.decode('utf-8') self.qos = qos self.retain = retain self.msgId = msgId self.dup = dup self.protocol.onPublish = onPublish pub = PUBLISH() pub.qos = 2 pub.dup = False pub.retain = False pub.topic = "foo/bar/baz2" pub.msgId = 1 pub.payload = "Hello world 2" self.protocol.dataReceived(pub.encode()) self.transport.clear() self.assertEqual(self.called, False) rel = PUBREL() rel.msgId = pub.msgId self.protocol.dataReceived(rel.encode()) self.assertEqual(self.topic, pub.topic) self.assertEqual(self.payload, pub.payload) self.assertEqual(self.qos, pub.qos) self.assertEqual(self.retain, pub.retain) self.assertEqual(self.msgId, pub.msgId) self.assertEqual(self.dup, pub.dup)
def test_PUBREL_encdec(self): request = PUBREL() response = PUBREL() request.msgId = 30002 response.decode(request.encode()) self.assertEqual(request.msgId, response.msgId)