|
|
@ -56,7 +56,7 @@ class TestAsyncServer: |
|
|
|
def foo(): |
|
|
|
pass |
|
|
|
|
|
|
|
def bar(): |
|
|
|
def bar(reason): |
|
|
|
pass |
|
|
|
|
|
|
|
s.on('disconnect', bar) |
|
|
@ -537,8 +537,36 @@ class TestAsyncServer: |
|
|
|
s.on('disconnect', handler) |
|
|
|
await s._handle_eio_connect('123', 'environ') |
|
|
|
await s._handle_eio_message('123', '0') |
|
|
|
await s._handle_eio_disconnect('123') |
|
|
|
handler.assert_called_once_with('1') |
|
|
|
await s._handle_eio_disconnect('123', 'foo') |
|
|
|
handler.assert_called_once_with('1', 'foo') |
|
|
|
s.manager.disconnect.assert_awaited_once_with( |
|
|
|
'1', '/', ignore_queue=True) |
|
|
|
assert s.environ == {} |
|
|
|
|
|
|
|
async def test_handle_legacy_disconnect(self, eio): |
|
|
|
eio.return_value.send = mock.AsyncMock() |
|
|
|
s = async_server.AsyncServer() |
|
|
|
s.manager.disconnect = mock.AsyncMock() |
|
|
|
handler = mock.MagicMock(side_effect=[TypeError, None]) |
|
|
|
s.on('disconnect', handler) |
|
|
|
await s._handle_eio_connect('123', 'environ') |
|
|
|
await s._handle_eio_message('123', '0') |
|
|
|
await s._handle_eio_disconnect('123', 'foo') |
|
|
|
handler.assert_called_with('1') |
|
|
|
s.manager.disconnect.assert_awaited_once_with( |
|
|
|
'1', '/', ignore_queue=True) |
|
|
|
assert s.environ == {} |
|
|
|
|
|
|
|
async def test_handle_legacy_disconnect_async(self, eio): |
|
|
|
eio.return_value.send = mock.AsyncMock() |
|
|
|
s = async_server.AsyncServer() |
|
|
|
s.manager.disconnect = mock.AsyncMock() |
|
|
|
handler = mock.AsyncMock(side_effect=[TypeError, None]) |
|
|
|
s.on('disconnect', handler) |
|
|
|
await s._handle_eio_connect('123', 'environ') |
|
|
|
await s._handle_eio_message('123', '0') |
|
|
|
await s._handle_eio_disconnect('123', 'foo') |
|
|
|
handler.assert_awaited_with('1') |
|
|
|
s.manager.disconnect.assert_awaited_once_with( |
|
|
|
'1', '/', ignore_queue=True) |
|
|
|
assert s.environ == {} |
|
|
@ -552,9 +580,9 @@ class TestAsyncServer: |
|
|
|
s.on('disconnect', handler_namespace, namespace='/foo') |
|
|
|
await s._handle_eio_connect('123', 'environ') |
|
|
|
await s._handle_eio_message('123', '0/foo,') |
|
|
|
await s._handle_eio_disconnect('123') |
|
|
|
await s._handle_eio_disconnect('123', 'foo') |
|
|
|
handler.assert_not_called() |
|
|
|
handler_namespace.assert_called_once_with('1') |
|
|
|
handler_namespace.assert_called_once_with('1', 'foo') |
|
|
|
assert s.environ == {} |
|
|
|
|
|
|
|
async def test_handle_disconnect_only_namespace(self, eio): |
|
|
@ -568,13 +596,14 @@ class TestAsyncServer: |
|
|
|
await s._handle_eio_message('123', '0/foo,') |
|
|
|
await s._handle_eio_message('123', '1/foo,') |
|
|
|
assert handler.call_count == 0 |
|
|
|
handler_namespace.assert_called_once_with('1') |
|
|
|
handler_namespace.assert_called_once_with( |
|
|
|
'1', s.reason.CLIENT_DISCONNECT) |
|
|
|
assert s.environ == {'123': 'environ'} |
|
|
|
|
|
|
|
async def test_handle_disconnect_unknown_client(self, eio): |
|
|
|
mgr = self._get_mock_manager() |
|
|
|
s = async_server.AsyncServer(client_manager=mgr) |
|
|
|
await s._handle_eio_disconnect('123') |
|
|
|
await s._handle_eio_disconnect('123', 'foo') |
|
|
|
|
|
|
|
async def test_handle_event(self, eio): |
|
|
|
eio.return_value.send = mock.AsyncMock() |
|
|
@ -624,7 +653,7 @@ class TestAsyncServer: |
|
|
|
await s._handle_eio_message('123', '2/bar,["msg","a","b"]') |
|
|
|
await s._handle_eio_message('123', '2/foo,["my message","a","b","c"]') |
|
|
|
await s._handle_eio_message('123', '2/bar,["my message","a","b","c"]') |
|
|
|
await s._trigger_event('disconnect', '/bar', sid_bar) |
|
|
|
await s._trigger_event('disconnect', '/bar', sid_bar, s.reason.UNKNOWN) |
|
|
|
connect_star_handler.assert_called_once_with('/bar', sid_bar) |
|
|
|
msg_foo_handler.assert_called_once_with(sid_foo, 'a', 'b') |
|
|
|
msg_star_handler.assert_called_once_with('/bar', sid_bar, 'a', 'b') |
|
|
@ -884,8 +913,8 @@ class TestAsyncServer: |
|
|
|
def on_connect(self, sid, environ): |
|
|
|
result['result'] = (sid, environ) |
|
|
|
|
|
|
|
async def on_disconnect(self, sid): |
|
|
|
result['result'] = ('disconnect', sid) |
|
|
|
async def on_disconnect(self, sid, reason): |
|
|
|
result['result'] = ('disconnect', sid, reason) |
|
|
|
|
|
|
|
async def on_foo(self, sid, data): |
|
|
|
result['result'] = (sid, data) |
|
|
@ -908,7 +937,8 @@ class TestAsyncServer: |
|
|
|
await s._handle_eio_message('123', '2/foo,["baz","a","b"]') |
|
|
|
assert result['result'] == ('a', 'b') |
|
|
|
await s.disconnect('1', '/foo') |
|
|
|
assert result['result'] == ('disconnect', '1') |
|
|
|
assert result['result'] == ('disconnect', '1', |
|
|
|
s.reason.SERVER_DISCONNECT) |
|
|
|
|
|
|
|
async def test_catchall_namespace_handler(self, eio): |
|
|
|
eio.return_value.send = mock.AsyncMock() |
|
|
|