예제 #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'})