File: test_msgpack_packet.py

package info (click to toggle)
python-socketio 5.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,140 kB
  • sloc: python: 11,460; makefile: 13; sh: 7
file content (34 lines) | stat: -rw-r--r-- 1,398 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from socketio import msgpack_packet
from socketio import packet


class TestMsgPackPacket:
    def test_encode_decode(self):
        p = msgpack_packet.MsgPackPacket(
            packet.CONNECT, data={'auth': {'token': '123'}}, namespace='/foo')
        p2 = msgpack_packet.MsgPackPacket(encoded_packet=p.encode())
        assert p.packet_type == p2.packet_type
        assert p.data == p2.data
        assert p.id == p2.id
        assert p.namespace == p2.namespace

    def test_encode_decode_with_id(self):
        p = msgpack_packet.MsgPackPacket(
            packet.EVENT, data=['ev', 42], id=123, namespace='/foo')
        p2 = msgpack_packet.MsgPackPacket(encoded_packet=p.encode())
        assert p.packet_type == p2.packet_type
        assert p.data == p2.data
        assert p.id == p2.id
        assert p.namespace == p2.namespace

    def test_encode_binary_event_packet(self):
        p = msgpack_packet.MsgPackPacket(packet.EVENT, data={'foo': b'bar'})
        assert p.packet_type == packet.EVENT
        p2 = msgpack_packet.MsgPackPacket(encoded_packet=p.encode())
        assert p2.data == {'foo': b'bar'}

    def test_encode_binary_ack_packet(self):
        p = msgpack_packet.MsgPackPacket(packet.ACK, data={'foo': b'bar'})
        assert p.packet_type == packet.ACK
        p2 = msgpack_packet.MsgPackPacket(encoded_packet=p.encode())
        assert p2.data == {'foo': b'bar'}