Browse Source

unit tests

pull/1515/head
Miguel Grinberg 8 months ago
parent
commit
72b0079351
Failed to extract signature
  1. 2
      src/socketio/async_server.py
  2. 2
      src/socketio/server.py
  3. 15
      tests/async/test_server.py
  4. 14
      tests/common/test_server.py

2
src/socketio/async_server.py

@ -561,7 +561,7 @@ class AsyncServer(base_server.BaseServer):
except exceptions.ConnectionRefusedError as exc:
fail_reason = exc.error_args
success = False
except ConnectionRefusedError as exc:
except ConnectionRefusedError:
fail_reason = {"message": "Connection refused by server"}
success = False

2
src/socketio/server.py

@ -543,7 +543,7 @@ class Server(base_server.BaseServer):
except exceptions.ConnectionRefusedError as exc:
fail_reason = exc.error_args
success = False
except ConnectionRefusedError as exc:
except ConnectionRefusedError:
fail_reason = {"message": "Connection refused by server"}
success = False

15
tests/async/test_server.py

@ -482,6 +482,21 @@ class TestAsyncServer:
'123', '4{"message":"fail_reason"}')
assert s.environ == {'123': 'environ'}
async def test_handle_connect_rejected_with_python_exception(self, eio):
eio.return_value.send = mock.AsyncMock()
s = async_server.AsyncServer()
handler = mock.MagicMock(
side_effect=ConnectionRefusedError()
)
s.on('connect', handler)
await s._handle_eio_connect('123', 'environ')
await s._handle_eio_message('123', '0')
assert not s.manager.is_connected('1', '/')
handler.assert_called_once_with('1', 'environ')
s.eio.send.assert_awaited_once_with(
'123', '4{"message":"Connection refused by server"}')
assert s.environ == {'123': 'environ'}
async def test_handle_connect_rejected_with_empty_exception(self, eio):
eio.return_value.send = mock.AsyncMock()
s = async_server.AsyncServer()

14
tests/common/test_server.py

@ -462,6 +462,20 @@ class TestServer:
s.eio.send.assert_called_once_with('123', '4{"message":"fail_reason"}')
assert s.environ == {'123': 'environ'}
def test_handle_connect_rejected_with_python_exception(self, eio):
s = server.Server()
handler = mock.MagicMock(
side_effect=ConnectionRefusedError()
)
s.on('connect', handler)
s._handle_eio_connect('123', 'environ')
s._handle_eio_message('123', '0')
assert not s.manager.is_connected('1', '/')
handler.assert_called_once_with('1', 'environ')
s.eio.send.assert_called_once_with(
'123', '4{"message":"Connection refused by server"}')
assert s.environ == {'123': 'environ'}
def test_handle_connect_rejected_with_empty_exception(self, eio):
s = server.Server()
handler = mock.MagicMock(

Loading…
Cancel
Save