def test_handle_event(self):
     c = asyncio_client.AsyncClient()
     c._trigger_event = AsyncMock()
     _run(c._handle_event('/', None, ['foo', ('bar', 'baz')]))
     c._trigger_event.mock.assert_called_once_with('foo', '/',
                                                   ('bar', 'baz'))
 def test_handle_error(self):
     c = asyncio_client.AsyncClient()
     c.namespaces = ['/foo', '/bar']
     c._handle_error('/bar')
     self.assertEqual(c.namespaces, ['/foo'])
 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)
 def test_handle_disconnect(self):
     c = asyncio_client.AsyncClient()
     c._trigger_event = AsyncMock()
     _run(c._handle_disconnect('/'))
     c._trigger_event.mock.assert_called_once_with('disconnect',
                                                   namespace='/')
 def test_is_asyncio_based(self):
     c = asyncio_client.AsyncClient()
     self.assertEqual(c.is_asyncio_based(), True)
 def test_sleep(self):
     c = asyncio_client.AsyncClient()
     c.eio.sleep = AsyncMock()
     _run(c.sleep(1.23))
     c.eio.sleep.mock.assert_called_once_with(1.23)
예제 #7
0
 def test_trigger_event(self):
     c = asyncio_client.AsyncClient()
     handler = mock.MagicMock()
     c.on('foo', handler)
     _run(c._trigger_event('foo', '/', 1, '2'))
     handler.assert_called_once_with(1, '2')
예제 #8
0
 def test_trigger_event_namespace(self):
     c = asyncio_client.AsyncClient()
     handler = AsyncMock()
     c.on('foo', handler, namespace='/bar')
     _run(c._trigger_event('foo', '/bar', 1, '2'))
     handler.mock.assert_called_once_with(1, '2')
예제 #9
0
 def test_emit_unknown_namespace(self):
     c = asyncio_client.AsyncClient()
     c.namespaces = {'/foo': '1'}
     with pytest.raises(exceptions.BadNamespaceError):
         _run(c.emit('foo', namespace='/bar'))
예제 #10
0
 def test_is_asyncio_based(self):
     c = asyncio_client.AsyncClient()
     assert c.is_asyncio_based()
예제 #11
0
 def test_eio_disconnect_no_reconnect(self):
     c = asyncio_client.AsyncClient(reconnection=False)
     c.start_background_task = mock.MagicMock()
     c.eio.state = 'connected'
     _run(c._handle_eio_disconnect())
     c.start_background_task.assert_not_called()
 def test_eio_connect(self):
     c = asyncio_client.AsyncClient()
     c.eio.sid = 'foo'
     self.assertIsNone(c.sid)
     c._handle_eio_connect()
     self.assertEqual(c.sid, 'foo')
 def test_emit_unknown_namespace(self):
     c = asyncio_client.AsyncClient()
     c.namespaces = ['/foo']
     self.assertRaises(exceptions.BadNamespaceError, _run,
                       c.emit('foo', namespace='/bar'))
 def test_eio_connect(self):
     c = asyncio_client.AsyncClient()
     c.eio.sid = 'foo'
     assert c.sid is None
     c._handle_eio_connect()
     assert c.sid == 'foo'
예제 #15
0
 def test_send_with_defaults(self):
     c = asyncio_client.AsyncClient()
     c.emit = AsyncMock()
     _run(c.send('data'))
     c.emit.mock.assert_called_once_with(
         'message', data='data', namespace=None, callback=None)