Esempio n. 1
0
    def test_packet_dec_bad_type(self):
        packets = [
            SIO_TYPE_BIN_ACK,
            SIO_TYPE_BIN_EVENT,
        ]

        for i, packet in enumerate(packets):
            with self.assertRaisesRegex(NotImplementedError, r'^binary Socket\.IO packets are currently unsupported$', msg='packet[{}]: {!r}'.format(i, packet)):
                decsiopacket(packet)

        packets = [
            SIO_TYPE_EVENT,
        ]

        for i, packet in enumerate(packets):
            with self.assertRaisesRegex(PayloadDecodeError, r'^packet type is ".*", but payload is binary$', msg='packet[{}]: {!r}'.format(i, packet)):
                decsiopacket(packet)

        packets = [
            PacketsTestCase.BAD_TYPE_STR_PACKET,
        ]

        for i, packet in enumerate(packets):
            with self.assertRaisesRegex(PayloadDecodeError, r'^unrecognized packet type ".*"$', msg='packet[{}]: {!r}'.format(i, packet)):
                decsiopacket(packet)

        packets = [
            PacketsTestCase.BAD_PACKET_STR_BIN_ACK,
            PacketsTestCase.BAD_PACKET_STR_BIN_EVENT,
        ]

        for i, packet in enumerate(packets):
            with self.assertRaisesRegex(PayloadDecodeError, r'^packet type is ".*", but payload is not binary$', msg='packet[{}]: {!r}'.format(i, packet)):
                decsiopacket(packet)

        packets = [
            None,
            42,
            (),
            [],
            {},
        ]

        for i, packet in enumerate(packets):
            with self.assertRaisesRegex(TypeError, r'^packet type must be one of bytes or str, not .*', msg='packet[{}]: {!r}'.format(i, packet)):
                decsiopacket(packet)
Esempio n. 2
0
    def test_packet_dec(self):
        packets = (
            encsiopacket(SIO_TYPE_EVENT, None, None, None),
            encsiopacket(SIO_TYPE_EVENT, '',   None, None),
            encsiopacket(SIO_TYPE_EVENT, None, '',   None),
            encsiopacket(SIO_TYPE_EVENT, '',   '',   None),
            encsiopacket(SIO_TYPE_EVENT, None, '/',  None),
            encsiopacket(SIO_TYPE_EVENT, '',   '/',  None),
            SIO_TYPE_EVENT.decode('utf_8'),
        )

        expected = ( SIO_TYPE_EVENT, '', '/', None )

        for i, packet in enumerate(packets):
            actual = decsiopacket(packet)
            self.assertEqual(expected, actual, msg='packet[{}]: {!r}'.format(i, packet))
Esempio n. 3
0
 def test_enc_dec(self, packet_type, packet_obj, packet_path, packet_id):
     packet_path = '/' + packet_path
     args = ( packet_type, packet_obj, packet_path, packet_id )
     self.assertEqual(args, decsiopacket(encsiopacket(*args)))
Esempio n. 4
0
 def test_packet_dec_bad_len(self):
     with self.assertRaisesRegex(PayloadDecodeError, r'^packet truncated$'):
         decsiopacket(PacketsTestCase.BAD_TRUNC_PACKET)