Пример #1
0
 def test_decode_text_event_packet(self):
     pkt = packet.Packet(encoded_packet='2["foo"]')
     assert pkt.packet_type == packet.EVENT
     assert pkt.data == ['foo']
     assert pkt.encode() == '2["foo"]'
Пример #2
0
 def test_data_is_binary_list(self):
     pkt = packet.Packet()
     self.assertFalse(pkt._data_is_binary([six.text_type('foo')]))
     self.assertFalse(pkt._data_is_binary([]))
     self.assertTrue(pkt._data_is_binary([b'foo']))
     self.assertTrue(pkt._data_is_binary([six.text_type('foo'), b'bar']))
Пример #3
0
 def test_decode_text_event_packet(self):
     pkt = packet.Packet(encoded_packet='2["foo"]')
     self.assertEqual(pkt.packet_type, packet.EVENT)
     self.assertEqual(pkt.data, ['foo'])
     self.assertEqual(pkt.encode(), '2["foo"]')
Пример #4
0
 def test_encode_id(self):
     pkt = packet.Packet(packet_type=packet.EVENT,
                         data=[six.text_type('foo')], id=123)
     self.assertEqual(pkt.id, 123)
     self.assertEqual(pkt.encode(), '2123["foo"]')
Пример #5
0
 def test_decode_namespace_and_id(self):
     pkt = packet.Packet(encoded_packet='2/bar,123["foo"]')
     self.assertEqual(pkt.namespace, '/bar')
     self.assertEqual(pkt.id, 123)
     self.assertEqual(pkt.encode(), '2/bar,123["foo"]')
Пример #6
0
 def test_encode_namespace_with_hyphens(self):
     pkt = packet.Packet(packet_type=packet.EVENT,
                         data=[six.text_type('foo')], namespace='/b-a-r')
     self.assertEqual(pkt.namespace, '/b-a-r')
     self.assertEqual(pkt.encode(), '2/b-a-r,["foo"]')
Пример #7
0
 def test_encode_event_with_hyphens(self):
     pkt = packet.Packet(packet_type=packet.EVENT,
                         data=[six.text_type('f-o-o')])
     self.assertEqual(pkt.namespace, None)
     self.assertEqual(pkt.encode(), '2["f-o-o"]')
Пример #8
0
 def test_decode_namespace(self):
     pkt = packet.Packet(encoded_packet='2/bar,["foo"]')
     assert pkt.namespace == '/bar'
     assert pkt.encode() == '2/bar,["foo"]'
Пример #9
0
 def test_send_packet_default_binary_py3(self):
     c = client.Client()
     c.eio.send = mock.MagicMock()
     c._send_packet(packet.Packet(packet.EVENT, 'foo'))
     c.eio.send.assert_called_once_with('2"foo"', binary=False)
Пример #10
0
 def test_decode_binary_ack_packet(self):
     pkt = packet.Packet(encoded_packet='61-{"_placeholder":true,"num":0}')
     assert pkt.add_attachment(b'1234')
     assert pkt.packet_type == packet.BINARY_ACK
     assert pkt.data == b'1234'
Пример #11
0
 def test_invalid_binary_packet(self):
     with pytest.raises(ValueError):
         packet.Packet(packet_type=packet.CONNECT_ERROR, data=b'123')
Пример #12
0
 def test_decode_text_ack_packet(self):
     pkt = packet.Packet(encoded_packet='3["foo"]')
     assert pkt.packet_type == packet.ACK
     assert pkt.data == ['foo']
     assert pkt.encode() == '3["foo"]'
Пример #13
0
 def test_encode_text_ack_packet(self):
     pkt = packet.Packet(packet_type=packet.ACK, data=['foo'])
     assert pkt.packet_type == packet.ACK
     assert pkt.data == ['foo']
     assert pkt.encode() == '3["foo"]'
Пример #14
0
 def test_decode_empty_event_packet(self):
     pkt = packet.Packet(encoded_packet='1')
     assert pkt.packet_type == packet.DISCONNECT
     # same thing, but with a numeric payload
     pkt = packet.Packet(encoded_packet=1)
     assert pkt.packet_type == packet.DISCONNECT
Пример #15
0
 def test_decode_binary_ack_packet(self):
     pkt = packet.Packet(encoded_packet='61-{"_placeholder":true,"num":0}')
     self.assertTrue(pkt.add_attachment(b'1234'))
     self.assertEqual(pkt.packet_type, packet.BINARY_ACK)
     self.assertEqual(pkt.data, b'1234')
 def test_send_packet_default_binary_py3(self):
     c = asyncio_client.AsyncClient()
     c.eio.send = AsyncMock()
     _run(c._send_packet(packet.Packet(packet.EVENT, 'foo')))
     c.eio.send.mock.assert_called_once_with('2"foo"', binary=False)
Пример #17
0
 def test_decode_namespace_no_data(self):
     pkt = packet.Packet(encoded_packet='2/bar')
     self.assertEqual(pkt.namespace, '/bar')
     self.assertEqual(pkt.encode(), '2/bar')
Пример #18
0
 def test_decode_namespace_with_query_string(self):
     # some Socket.IO clients mistakenly attach the query string to the
     # namespace
     pkt = packet.Packet(encoded_packet='2/bar?a=b,["foo"]')
     self.assertEqual(pkt.namespace, '/bar')
     self.assertEqual(pkt.encode(), '2/bar,["foo"]')
Пример #19
0
 def test_decode_namespace_with_hyphens(self):
     pkt = packet.Packet(encoded_packet='2/b-a-r,["foo"]')
     self.assertEqual(pkt.namespace, '/b-a-r')
     self.assertEqual(pkt.encode(), '2/b-a-r,["foo"]')
Пример #20
0
 def test_encode_namespace_no_data(self):
     pkt = packet.Packet(packet_type=packet.EVENT, namespace='/bar')
     self.assertEqual(pkt.encode(), '2/bar')
Пример #21
0
 def test_decode_event_with_hyphens(self):
     pkt = packet.Packet(encoded_packet='2["f-o-o"]')
     self.assertEqual(pkt.namespace, None)
     self.assertEqual(pkt.encode(), '2["f-o-o"]')
Пример #22
0
 def test_encode_id_no_data(self):
     pkt = packet.Packet(packet_type=packet.EVENT, id=123)
     self.assertEqual(pkt.id, 123)
     self.assertIsNone(pkt.data)
     self.assertEqual(pkt.encode(), '2123')
Пример #23
0
 def test_decode_id(self):
     pkt = packet.Packet(encoded_packet='2123["foo"]')
     self.assertEqual(pkt.id, 123)
     self.assertEqual(pkt.encode(), '2123["foo"]')
Пример #24
0
 def test_decode_id_no_data(self):
     pkt = packet.Packet(encoded_packet='2123')
     self.assertEqual(pkt.id, 123)
     self.assertIsNone(pkt.data)
     self.assertEqual(pkt.encode(), '2123')
Пример #25
0
 def test_decode_default_packet(self):
     pkt = packet.Packet(encoded_packet='2')
     self.assertTrue(pkt.encode(), '2')
Пример #26
0
 def test_encode_text_ack_packet(self):
     pkt = packet.Packet(packet_type=packet.ACK,
                         data=[six.text_type('foo')])
     self.assertEqual(pkt.packet_type, packet.ACK)
     self.assertEqual(pkt.data, ['foo'])
     self.assertEqual(pkt.encode(), '3["foo"]')
Пример #27
0
 def test_encode_text_event_packet(self):
     pkt = packet.Packet(packet_type=packet.EVENT,
                         data=[six.text_type('foo')])
     self.assertEqual(pkt.packet_type, packet.EVENT)
     self.assertEqual(pkt.data, ['foo'])
     self.assertEqual(pkt.encode(), '2["foo"]')
Пример #28
0
 def test_decode_text_ack_packet(self):
     pkt = packet.Packet(encoded_packet='3["foo"]')
     self.assertEqual(pkt.packet_type, packet.ACK)
     self.assertEqual(pkt.data, ['foo'])
     self.assertEqual(pkt.encode(), '3["foo"]')
Пример #29
0
 def test_decode_empty_event_packet(self):
     pkt = packet.Packet(encoded_packet='1')
     self.assertEqual(pkt.packet_type, packet.DISCONNECT)
     # same thing, but with a numeric payload
     pkt = packet.Packet(encoded_packet=1)
     self.assertEqual(pkt.packet_type, packet.DISCONNECT)
Пример #30
0
 def test_data_is_binary_dict(self):
     pkt = packet.Packet()
     assert not pkt._data_is_binary({'a': 'foo'})
     assert not pkt._data_is_binary({})
     assert pkt._data_is_binary({'a': b'foo'})
     assert pkt._data_is_binary({'a': 'foo', 'b': b'bar'})