2017-08-06 22:46:15 +00:00
|
|
|
import asyncio
|
2015-06-18 08:22:46 +00:00
|
|
|
import unittest
|
|
|
|
|
2021-03-27 12:16:42 +00:00
|
|
|
from amqtt.adapters import BufferReader
|
2024-12-21 10:52:26 +00:00
|
|
|
from amqtt.mqtt.packet import PacketIdVariableHeader
|
|
|
|
from amqtt.mqtt.unsubscribe import UnsubscribePacket, UnubscribePayload
|
2015-06-18 08:22:46 +00:00
|
|
|
|
2015-07-31 21:01:32 +00:00
|
|
|
|
2015-06-29 20:37:01 +00:00
|
|
|
class UnsubscribePacketTest(unittest.TestCase):
|
2015-06-18 08:22:46 +00:00
|
|
|
def setUp(self):
|
|
|
|
self.loop = asyncio.new_event_loop()
|
|
|
|
|
|
|
|
def test_from_stream(self):
|
2021-03-14 20:44:41 +00:00
|
|
|
data = b"\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d"
|
2015-07-31 21:01:32 +00:00
|
|
|
stream = BufferReader(data)
|
2015-06-18 08:22:46 +00:00
|
|
|
message = self.loop.run_until_complete(UnsubscribePacket.from_stream(stream))
|
2024-12-21 10:52:26 +00:00
|
|
|
assert message.payload.topics[0] == "a/b"
|
|
|
|
assert message.payload.topics[1] == "c/d"
|
2015-06-18 08:22:46 +00:00
|
|
|
|
|
|
|
def test_to_stream(self):
|
|
|
|
variable_header = PacketIdVariableHeader(10)
|
2021-03-14 20:44:41 +00:00
|
|
|
payload = UnubscribePayload(["a/b", "c/d"])
|
2015-06-18 08:22:46 +00:00
|
|
|
publish = UnsubscribePacket(variable_header=variable_header, payload=payload)
|
|
|
|
out = publish.to_bytes()
|
2024-12-21 10:52:26 +00:00
|
|
|
assert out == b"\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d"
|