Exemple #1
0
 def server_mock(reader, writer):
     try:
         packet = yield from PublishPacket.from_stream(reader)
         self.assertEqual(packet.variable_header.topic_name, '/topic')
         self.assertEqual(packet.qos, QOS_0)
         self.assertIsNone(packet.packet_id)
     except Exception as ae:
         future.set_exception(ae)
Exemple #2
0
 def server_mock(reader, writer):
     try:
         packet = yield from PublishPacket.from_stream(reader)
         self.assertEquals(packet.variable_header.topic_name, "/topic")
         self.assertEquals(packet.qos, QOS_0)
         self.assertIsNone(packet.packet_id)
     except Exception as ae:
         future.set_exception(ae)
Exemple #3
0
 def test_from_stream_qos_2(self):
     data = b'\x37\x13\x00\x05topic\x00\x0a0123456789'
     stream = BufferReader(data)
     message = self.loop.run_until_complete(PublishPacket.from_stream(stream))
     self.assertEqual(message.variable_header.topic_name, 'topic')
     self.assertEqual(message.variable_header.packet_id, 10)
     self.assertTrue((message.fixed_header.flags >> 1) & 0x03)
     self.assertTrue(message.fixed_header.flags & 0x01)
     self.assertTrue(message.payload.data, b'0123456789')
Exemple #4
0
 def test_from_stream_qos_2(self):
     data = b'\x37\x13\x00\x05topic\x00\x0a0123456789'
     stream = BufferReader(data)
     message = self.loop.run_until_complete(
         PublishPacket.from_stream(stream))
     self.assertEqual(message.variable_header.topic_name, 'topic')
     self.assertEqual(message.variable_header.packet_id, 10)
     self.assertTrue((message.fixed_header.flags >> 1) & 0x03)
     self.assertTrue(message.fixed_header.flags & 0x01)
     self.assertTrue(message.payload.data, b'0123456789')
Exemple #5
0
 def test_from_stream_qos_0(self):
     data = b"\x31\x11\x00\x05topic0123456789"
     stream = BufferReader(data)
     message = self.loop.run_until_complete(
         PublishPacket.from_stream(stream))
     self.assertEqual(message.variable_header.topic_name, "topic")
     self.assertEqual(message.variable_header.packet_id, None)
     self.assertFalse((message.fixed_header.flags >> 1) & 0x03)
     assert message.fixed_header.flags & 0x01
     assert message.payload.data, b"0123456789"
Exemple #6
0
 def server_mock(reader, writer):
     packet = yield from PublishPacket.from_stream(reader)
     try:
         self.assertEqual(packet.topic_name, '/topic')
         self.assertEqual(packet.qos, QOS_1)
         self.assertIsNotNone(packet.packet_id)
         self.assertIn(packet.packet_id, self.session.inflight_out)
         self.assertIn(packet.packet_id, self.handler._puback_waiters)
         puback = PubackPacket.build(packet.packet_id)
         yield from puback.to_stream(writer)
     except Exception as ae:
         future.set_exception(ae)
Exemple #7
0
 def test_from_stream(self):
     data = b"\x3f\x09\x00\x05topic\x00\x0a0123456789"
     stream = asyncio.StreamReader(loop=self.loop)
     stream.feed_data(data)
     stream.feed_eof()
     message = self.loop.run_until_complete(PublishPacket.from_stream(stream))
     self.assertEqual(message.variable_header.topic_name, "topic")
     self.assertEqual(message.variable_header.packet_id, 10)
     self.assertEqual(message.fixed_header.qos, 0x03)
     self.assertTrue(message.fixed_header.dup_flag)
     self.assertTrue(message.fixed_header.retain_flag)
     self.assertTrue(message.payload.data, b"0123456789")
Exemple #8
0
 def server_mock(reader, writer):
     packet = yield from PublishPacket.from_stream(reader)
     try:
         self.assertEquals(packet.topic_name, "/topic")
         self.assertEquals(packet.qos, QOS_1)
         self.assertIsNotNone(packet.packet_id)
         self.assertIn(packet.packet_id, self.session.inflight_out)
         self.assertIn(packet.packet_id, self.handler._puback_waiters)
         puback = PubackPacket.build(packet.packet_id)
         yield from puback.to_stream(writer)
     except Exception as ae:
         future.set_exception(ae)
Exemple #9
0
        def server_mock(reader, writer):
            try:
                packet = yield from PublishPacket.from_stream(reader)
                self.assertEquals(packet.topic_name, '/topic')
                self.assertEquals(packet.qos, QOS_2)
                self.assertIsNotNone(packet.packet_id)
                self.assertIn(packet.packet_id, self.session.inflight_out)
                self.assertIn(packet.packet_id, self.handler._pubrec_waiters)
                pubrec = PubrecPacket.build(packet.packet_id)
                yield from pubrec.to_stream(writer)

                pubrel = yield from PubrelPacket.from_stream(reader)
                self.assertIn(packet.packet_id, self.handler._pubcomp_waiters)
                pubcomp = PubcompPacket.build(packet.packet_id)
                yield from pubcomp.to_stream(writer)
            except Exception as ae:
                future.set_exception(ae)
Exemple #10
0
        def server_mock(reader, writer):
            try:
                packet = yield from PublishPacket.from_stream(reader)
                self.assertEqual(packet.topic_name, '/topic')
                self.assertEqual(packet.qos, QOS_2)
                self.assertIsNotNone(packet.packet_id)
                self.assertIn(packet.packet_id, self.session.inflight_out)
                self.assertIn(packet.packet_id, self.handler._pubrec_waiters)
                pubrec = PubrecPacket.build(packet.packet_id)
                yield from pubrec.to_stream(writer)

                yield from PubrelPacket.from_stream(reader)
                self.assertIn(packet.packet_id, self.handler._pubcomp_waiters)
                pubcomp = PubcompPacket.build(packet.packet_id)
                yield from pubcomp.to_stream(writer)
            except Exception as ae:
                future.set_exception(ae)