def test_subscribe_tuple(self): d = self.protocol.subscribe( ("foo/bar/baz1", 2) ) self.transport.clear() ack = SUBACK() ack.msgId = d.msgId ack.granted = [(2, False)] self.protocol.dataReceived(ack.encode()) self.assertEqual([(2, False)], self.successResultOf(d))
def test_subscribe_tuple(self): d = self.protocol.subscribe(("foo/bar/baz1", 2)) self.transport.clear() ack = SUBACK() ack.msgId = d.msgId ack.granted = [(2, False)] self.protocol.dataReceived(ack.encode()) self.assertEqual([(2, False)], self.successResultOf(d))
def test_subscribe_list(self): d = self.protocol.subscribe( [ ("foo/bar/baz1", 2), ("foo/bar/baz2", 1), ("foo/bar/baz3", 0) ] ) d.addCallback(self.assertEqual, [(2, False), (1, False), (0, False)] ) self.transport.clear() ack = SUBACK() ack.msgId = d.msgId ack.granted = [(2, False), (1, False), (0, False)] self.protocol.dataReceived(ack.encode()) self.assertEqual( [(2, False), (1, False), (0, False)], self.successResultOf(d))
def test_subscribe_list(self): d = self.protocol.subscribe([("foo/bar/baz1", 2), ("foo/bar/baz2", 1), ("foo/bar/baz3", 0)]) d.addCallback(self.assertEqual, [(2, False), (1, False), (0, False)]) self.transport.clear() ack = SUBACK() ack.msgId = d.msgId ack.granted = [(2, False), (1, False), (0, False)] self.protocol.dataReceived(ack.encode()) self.assertEqual([(2, False), (1, False), (0, False)], self.successResultOf(d))
def test_subscribe_setPubishHandler2(self): def onPublish(topic, payload, qos, dup, retain, msgId): self.called = True self._connect() self.protocol.onPublish = onPublish d = self.protocol.subscribe("foo/bar/baz1", 2 ) self.transport.clear() ack = SUBACK() ack.msgId = d.msgId ack.granted = [(2, False)] self.protocol.dataReceived(ack.encode()) self.assertEqual([(2, False)], self.successResultOf(d))
def test_subscribe_setPubishHandler2(self): def onPublish(topic, payload, qos, dup, retain, msgId): self.called = True self._connect() self.protocol.onPublish = onPublish d = self.protocol.subscribe("foo/bar/baz1", 2) self.transport.clear() ack = SUBACK() ack.msgId = d.msgId ack.granted = [(2, False)] self.protocol.dataReceived(ack.encode()) self.assertEqual([(2, False)], self.successResultOf(d))
def test_SUBACK_encdec(self): request = SUBACK() response = SUBACK() request.msgId = 5 request.granted = [(0, False), (0, True), (1, False), (1, True), (2, False), (2, True)] response.decode(request.encode()) self.assertEqual(request.msgId, response.msgId) self.assertEqual(request.granted, response.granted)
def test_SUBACK_encdec(self): request = SUBACK() response = SUBACK() request.msgId = 5 request.granted = [(0, False), (0, True), (1,False), (1,True), (2,False), (2,True)] response.decode(request.encode()) self.assertEqual(request.msgId, response.msgId) self.assertEqual(request.granted, response.granted)