Skip to content

Commit 72b0079

Browse files
unit tests
1 parent 3b39c64 commit 72b0079

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/socketio/async_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ async def _handle_connect(self, eio_sid, namespace, data):
561561
except exceptions.ConnectionRefusedError as exc:
562562
fail_reason = exc.error_args
563563
success = False
564-
except ConnectionRefusedError as exc:
564+
except ConnectionRefusedError:
565565
fail_reason = {"message": "Connection refused by server"}
566566
success = False
567567

src/socketio/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def _handle_connect(self, eio_sid, namespace, data):
543543
except exceptions.ConnectionRefusedError as exc:
544544
fail_reason = exc.error_args
545545
success = False
546-
except ConnectionRefusedError as exc:
546+
except ConnectionRefusedError:
547547
fail_reason = {"message": "Connection refused by server"}
548548
success = False
549549

tests/async/test_server.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,21 @@ async def test_handle_connect_rejected_with_exception(self, eio):
482482
'123', '4{"message":"fail_reason"}')
483483
assert s.environ == {'123': 'environ'}
484484

485+
async def test_handle_connect_rejected_with_python_exception(self, eio):
486+
eio.return_value.send = mock.AsyncMock()
487+
s = async_server.AsyncServer()
488+
handler = mock.MagicMock(
489+
side_effect=ConnectionRefusedError()
490+
)
491+
s.on('connect', handler)
492+
await s._handle_eio_connect('123', 'environ')
493+
await s._handle_eio_message('123', '0')
494+
assert not s.manager.is_connected('1', '/')
495+
handler.assert_called_once_with('1', 'environ')
496+
s.eio.send.assert_awaited_once_with(
497+
'123', '4{"message":"Connection refused by server"}')
498+
assert s.environ == {'123': 'environ'}
499+
485500
async def test_handle_connect_rejected_with_empty_exception(self, eio):
486501
eio.return_value.send = mock.AsyncMock()
487502
s = async_server.AsyncServer()

tests/common/test_server.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,20 @@ def test_handle_connect_rejected_with_exception(self, eio):
462462
s.eio.send.assert_called_once_with('123', '4{"message":"fail_reason"}')
463463
assert s.environ == {'123': 'environ'}
464464

465+
def test_handle_connect_rejected_with_python_exception(self, eio):
466+
s = server.Server()
467+
handler = mock.MagicMock(
468+
side_effect=ConnectionRefusedError()
469+
)
470+
s.on('connect', handler)
471+
s._handle_eio_connect('123', 'environ')
472+
s._handle_eio_message('123', '0')
473+
assert not s.manager.is_connected('1', '/')
474+
handler.assert_called_once_with('1', 'environ')
475+
s.eio.send.assert_called_once_with(
476+
'123', '4{"message":"Connection refused by server"}')
477+
assert s.environ == {'123': 'environ'}
478+
465479
def test_handle_connect_rejected_with_empty_exception(self, eio):
466480
s = server.Server()
467481
handler = mock.MagicMock(

0 commit comments

Comments
 (0)