Browse Source

add missing unit tests #nolog

pull/449/head
Miguel Grinberg 5 years ago
parent
commit
913c68a338
  1. 6
      socketio/asyncio_server.py
  2. 6
      socketio/server.py
  3. 9
      tests/asyncio/test_asyncio_server.py
  4. 6
      tests/common/test_server.py

6
socketio/asyncio_server.py

@ -327,10 +327,10 @@ class AsyncServer(server.Server):
"""
namespace = namespace or '/'
if ignore_queue:
do_it = self.manager.is_connected(sid, namespace)
delete_it = self.manager.is_connected(sid, namespace)
else:
do_it = await self.manager.can_disconnect(sid, namespace)
if do_it:
delete_it = await self.manager.can_disconnect(sid, namespace)
if delete_it:
self.logger.info('Disconnecting %s [%s]', sid, namespace)
self.manager.pre_disconnect(sid, namespace=namespace)
await self._send_packet(sid, packet.Packet(packet.DISCONNECT,

6
socketio/server.py

@ -518,10 +518,10 @@ class Server(object):
"""
namespace = namespace or '/'
if ignore_queue:
do_it = self.manager.is_connected(sid, namespace)
delete_it = self.manager.is_connected(sid, namespace)
else:
do_it = self.manager.can_disconnect(sid, namespace)
if do_it:
delete_it = self.manager.can_disconnect(sid, namespace)
if delete_it:
self.logger.info('Disconnecting %s [%s]', sid, namespace)
self.manager.pre_disconnect(sid, namespace=namespace)
self._send_packet(sid, packet.Packet(packet.DISCONNECT,

9
tests/asyncio/test_asyncio_server.py

@ -625,6 +625,15 @@ class TestAsyncServer(unittest.TestCase):
s.eio.send.mock.assert_any_call('123', '1', binary=False)
s.eio.disconnect.mock.assert_called_once_with('123')
def test_disconnect_ignore_queue(self, eio):
eio.return_value.send = AsyncMock()
eio.return_value.disconnect = AsyncMock()
s = asyncio_server.AsyncServer()
_run(s._handle_eio_connect('123', 'environ'))
_run(s.disconnect('123', ignore_queue=True))
s.eio.send.mock.assert_any_call('123', '1', binary=False)
s.eio.disconnect.mock.assert_called_once_with('123')
def test_disconnect_namespace(self, eio):
eio.return_value.send = AsyncMock()
eio.return_value.disconnect = AsyncMock()

6
tests/common/test_server.py

@ -553,6 +553,12 @@ class TestServer(unittest.TestCase):
s.disconnect('123')
s.eio.send.assert_any_call('123', '1', binary=False)
def test_disconnect_ignore_queue(self, eio):
s = server.Server()
s._handle_eio_connect('123', 'environ')
s.disconnect('123', ignore_queue=True)
s.eio.send.assert_any_call('123', '1', binary=False)
def test_disconnect_namespace(self, eio):
s = server.Server()
s._handle_eio_connect('123', 'environ')

Loading…
Cancel
Save