|
@ -313,17 +313,16 @@ class TestAsyncServer(unittest.TestCase): |
|
|
s.eio.send.mock.assert_any_call('123', '0/foo', binary=False) |
|
|
s.eio.send.mock.assert_any_call('123', '0/foo', binary=False) |
|
|
|
|
|
|
|
|
def test_handle_connect_rejected(self, eio): |
|
|
def test_handle_connect_rejected(self, eio): |
|
|
eio.return_value.send = AsyncMock() |
|
|
|
|
|
mgr = self._get_mock_manager() |
|
|
mgr = self._get_mock_manager() |
|
|
s = asyncio_server.AsyncServer(client_manager=mgr) |
|
|
s = asyncio_server.AsyncServer(client_manager=mgr) |
|
|
handler = mock.MagicMock(return_value=False) |
|
|
handler = mock.MagicMock(return_value=False) |
|
|
s.on('connect', handler) |
|
|
s.on('connect', handler) |
|
|
_run(s._handle_eio_connect('123', 'environ')) |
|
|
ret = _run(s._handle_eio_connect('123', 'environ')) |
|
|
|
|
|
self.assertFalse(ret) |
|
|
handler.assert_called_once_with('123', 'environ') |
|
|
handler.assert_called_once_with('123', 'environ') |
|
|
self.assertEqual(s.manager.connect.call_count, 1) |
|
|
self.assertEqual(s.manager.connect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.environ, {}) |
|
|
self.assertEqual(s.environ, {}) |
|
|
s.eio.send.mock.assert_called_once_with('123', '4', binary=False) |
|
|
|
|
|
|
|
|
|
|
|
def test_handle_connect_namespace_rejected(self, eio): |
|
|
def test_handle_connect_namespace_rejected(self, eio): |
|
|
eio.return_value.send = AsyncMock() |
|
|
eio.return_value.send = AsyncMock() |
|
@ -331,11 +330,12 @@ class TestAsyncServer(unittest.TestCase): |
|
|
s = asyncio_server.AsyncServer(client_manager=mgr) |
|
|
s = asyncio_server.AsyncServer(client_manager=mgr) |
|
|
handler = mock.MagicMock(return_value=False) |
|
|
handler = mock.MagicMock(return_value=False) |
|
|
s.on('connect', handler, namespace='/foo') |
|
|
s.on('connect', handler, namespace='/foo') |
|
|
_run(s._handle_eio_connect('123', 'environ')) |
|
|
ret = _run(s._handle_eio_connect('123', 'environ')) |
|
|
_run(s._handle_eio_message('123', '0/foo')) |
|
|
_run(s._handle_eio_message('123', '0/foo')) |
|
|
|
|
|
self.assertIsNone(ret) |
|
|
self.assertEqual(s.manager.connect.call_count, 2) |
|
|
self.assertEqual(s.manager.connect.call_count, 2) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.environ, {}) |
|
|
self.assertEqual(s.environ, {'123': 'environ'}) |
|
|
s.eio.send.mock.assert_any_call('123', '4/foo', binary=False) |
|
|
s.eio.send.mock.assert_any_call('123', '4/foo', binary=False) |
|
|
|
|
|
|
|
|
def test_handle_connect_rejected_always_connect(self, eio): |
|
|
def test_handle_connect_rejected_always_connect(self, eio): |
|
@ -345,7 +345,8 @@ class TestAsyncServer(unittest.TestCase): |
|
|
always_connect=True) |
|
|
always_connect=True) |
|
|
handler = mock.MagicMock(return_value=False) |
|
|
handler = mock.MagicMock(return_value=False) |
|
|
s.on('connect', handler) |
|
|
s.on('connect', handler) |
|
|
_run(s._handle_eio_connect('123', 'environ')) |
|
|
ret = _run(s._handle_eio_connect('123', 'environ')) |
|
|
|
|
|
self.assertFalse(ret) |
|
|
handler.assert_called_once_with('123', 'environ') |
|
|
handler.assert_called_once_with('123', 'environ') |
|
|
self.assertEqual(s.manager.connect.call_count, 1) |
|
|
self.assertEqual(s.manager.connect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
@ -360,11 +361,12 @@ class TestAsyncServer(unittest.TestCase): |
|
|
always_connect=True) |
|
|
always_connect=True) |
|
|
handler = mock.MagicMock(return_value=False) |
|
|
handler = mock.MagicMock(return_value=False) |
|
|
s.on('connect', handler, namespace='/foo') |
|
|
s.on('connect', handler, namespace='/foo') |
|
|
_run(s._handle_eio_connect('123', 'environ')) |
|
|
ret = _run(s._handle_eio_connect('123', 'environ')) |
|
|
_run(s._handle_eio_message('123', '0/foo')) |
|
|
_run(s._handle_eio_message('123', '0/foo')) |
|
|
|
|
|
self.assertFalse(ret) |
|
|
self.assertEqual(s.manager.connect.call_count, 2) |
|
|
self.assertEqual(s.manager.connect.call_count, 2) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.environ, {}) |
|
|
self.assertEqual(s.environ, {'123': 'environ'}) |
|
|
s.eio.send.mock.assert_any_call('123', '0/foo', binary=False) |
|
|
s.eio.send.mock.assert_any_call('123', '0/foo', binary=False) |
|
|
s.eio.send.mock.assert_any_call('123', '1/foo', binary=False) |
|
|
s.eio.send.mock.assert_any_call('123', '1/foo', binary=False) |
|
|
|
|
|
|
|
@ -375,11 +377,24 @@ class TestAsyncServer(unittest.TestCase): |
|
|
handler = mock.MagicMock( |
|
|
handler = mock.MagicMock( |
|
|
side_effect=exceptions.ConnectionRefusedError('fail_reason')) |
|
|
side_effect=exceptions.ConnectionRefusedError('fail_reason')) |
|
|
s.on('connect', handler) |
|
|
s.on('connect', handler) |
|
|
_run(s._handle_eio_connect('123', 'environ')) |
|
|
ret = _run(s._handle_eio_connect('123', 'environ')) |
|
|
|
|
|
self.assertEqual(ret, 'fail_reason') |
|
|
|
|
|
self.assertEqual(s.manager.connect.call_count, 1) |
|
|
|
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
|
|
|
self.assertEqual(s.environ, {}) |
|
|
|
|
|
|
|
|
|
|
|
def test_handle_connect_rejected_with_empty_exception(self, eio): |
|
|
|
|
|
eio.return_value.send = AsyncMock() |
|
|
|
|
|
mgr = self._get_mock_manager() |
|
|
|
|
|
s = asyncio_server.AsyncServer(client_manager=mgr) |
|
|
|
|
|
handler = mock.MagicMock( |
|
|
|
|
|
side_effect=exceptions.ConnectionRefusedError()) |
|
|
|
|
|
s.on('connect', handler) |
|
|
|
|
|
ret = _run(s._handle_eio_connect('123', 'environ')) |
|
|
|
|
|
self.assertFalse(ret) |
|
|
self.assertEqual(s.manager.connect.call_count, 1) |
|
|
self.assertEqual(s.manager.connect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.environ, {}) |
|
|
self.assertEqual(s.environ, {}) |
|
|
s.eio.send.mock.assert_any_call('123', '4"fail_reason"', binary=False) |
|
|
|
|
|
|
|
|
|
|
|
def test_handle_connect_namespace_rejected_with_exception(self, eio): |
|
|
def test_handle_connect_namespace_rejected_with_exception(self, eio): |
|
|
eio.return_value.send = AsyncMock() |
|
|
eio.return_value.send = AsyncMock() |
|
@ -388,14 +403,30 @@ class TestAsyncServer(unittest.TestCase): |
|
|
handler = mock.MagicMock( |
|
|
handler = mock.MagicMock( |
|
|
side_effect=exceptions.ConnectionRefusedError('fail_reason', 1)) |
|
|
side_effect=exceptions.ConnectionRefusedError('fail_reason', 1)) |
|
|
s.on('connect', handler, namespace='/foo') |
|
|
s.on('connect', handler, namespace='/foo') |
|
|
_run(s._handle_eio_connect('123', 'environ')) |
|
|
ret = _run(s._handle_eio_connect('123', 'environ')) |
|
|
_run(s._handle_eio_message('123', '0/foo')) |
|
|
_run(s._handle_eio_message('123', '0/foo')) |
|
|
|
|
|
self.assertIsNone(ret) |
|
|
self.assertEqual(s.manager.connect.call_count, 2) |
|
|
self.assertEqual(s.manager.connect.call_count, 2) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
self.assertEqual(s.environ, {}) |
|
|
self.assertEqual(s.environ, {'123': 'environ'}) |
|
|
s.eio.send.mock.assert_any_call('123', '4/foo,["fail_reason",1]', |
|
|
s.eio.send.mock.assert_any_call('123', '4/foo,["fail_reason",1]', |
|
|
binary=False) |
|
|
binary=False) |
|
|
|
|
|
|
|
|
|
|
|
def test_handle_connect_namespace_rejected_with_empty_exception(self, eio): |
|
|
|
|
|
eio.return_value.send = AsyncMock() |
|
|
|
|
|
mgr = self._get_mock_manager() |
|
|
|
|
|
s = asyncio_server.AsyncServer(client_manager=mgr) |
|
|
|
|
|
handler = mock.MagicMock( |
|
|
|
|
|
side_effect=exceptions.ConnectionRefusedError()) |
|
|
|
|
|
s.on('connect', handler, namespace='/foo') |
|
|
|
|
|
ret = _run(s._handle_eio_connect('123', 'environ')) |
|
|
|
|
|
_run(s._handle_eio_message('123', '0/foo')) |
|
|
|
|
|
self.assertIsNone(ret) |
|
|
|
|
|
self.assertEqual(s.manager.connect.call_count, 2) |
|
|
|
|
|
self.assertEqual(s.manager.disconnect.call_count, 1) |
|
|
|
|
|
self.assertEqual(s.environ, {'123': 'environ'}) |
|
|
|
|
|
s.eio.send.mock.assert_any_call('123', '4/foo', binary=False) |
|
|
|
|
|
|
|
|
def test_handle_disconnect(self, eio): |
|
|
def test_handle_disconnect(self, eio): |
|
|
eio.return_value.send = AsyncMock() |
|
|
eio.return_value.send = AsyncMock() |
|
|
mgr = self._get_mock_manager() |
|
|
mgr = self._get_mock_manager() |
|
|