Browse Source

Merge branch 'master' into middlewares

Resolved conflicts with master

Conflicts:
	socketio/namespace.py
	socketio/server.py
	tests/test_namespace.py
pull/45/head
Robert Schindler 9 years ago
parent
commit
ed38d63afa
  1. 4
      socketio/namespace.py
  2. 4
      socketio/server.py
  3. 30
      tests/test_namespace.py

4
socketio/namespace.py

@ -15,7 +15,7 @@ class Namespace(object):
self.server = None
self.middlewares = []
def set_server(self, server):
def _set_server(self, server):
self.server = server
def emit(self, event, data=None, room=None, skip_sid=None, namespace=None,
@ -91,7 +91,7 @@ class Namespace(object):
return self.server.disconnect(sid,
namespace=namespace or self.name)
def get_event_handler(self, event_name):
def _get_event_handler(self, event_name):
"""Returns the event handler for given ``event`` in this namespace or
``None``, if none exists.

4
socketio/server.py

@ -167,7 +167,7 @@ class Server(object):
"""
if not isinstance(namespace_handler, namespace.Namespace):
raise ValueError('Not a namespace instance')
namespace_handler.set_server(self)
namespace_handler._set_server(self)
self.namespace_handlers[namespace_handler.name] = \
namespace_handler
@ -453,7 +453,7 @@ class Server(object):
elif namespace in self.namespace_handlers:
ns = self.namespace_handlers[namespace]
middlewares.extend(ns.middlewares)
handler = ns.get_event_handler(event)
handler = ns._get_event_handler(event)
if handler is not None:
middlewares.extend(getattr(handler, '_sio_middlewares', []))
handler = self._apply_middlewares(middlewares, event, namespace,

30
tests/test_namespace.py

@ -17,8 +17,8 @@ class TestNamespace(unittest.TestCase):
result['result'] = (sid, environ)
ns = MyNamespace('/foo')
ns.set_server(mock.MagicMock())
ns.get_event_handler('connect')('sid', {'foo': 'bar'})
ns._set_server(mock.MagicMock())
ns._get_event_handler('connect')('sid', {'foo': 'bar'})
self.assertEqual(result['result'], ('sid', {'foo': 'bar'}))
def test_disconnect_event(self):
@ -29,8 +29,8 @@ class TestNamespace(unittest.TestCase):
result['result'] = sid
ns = MyNamespace('/foo')
ns.set_server(mock.MagicMock())
ns.get_event_handler('disconnect')('sid')
ns._set_server(mock.MagicMock())
ns._get_event_handler('disconnect')('sid')
self.assertEqual(result['result'], 'sid')
def test_event(self):
@ -41,8 +41,8 @@ class TestNamespace(unittest.TestCase):
result['result'] = (sid, data)
ns = MyNamespace('/foo')
ns.set_server(mock.MagicMock())
ns.get_event_handler('custom_message')('sid', {'data': 'data'})
ns._set_server(mock.MagicMock())
ns._get_event_handler('custom_message')('sid', {'data': 'data'})
self.assertEqual(result['result'], ('sid', {'data': 'data'}))
def test_event_not_found(self):
@ -53,13 +53,13 @@ class TestNamespace(unittest.TestCase):
result['result'] = (sid, data)
ns = MyNamespace('/foo')
ns.set_server(mock.MagicMock())
self.assertIsNone(ns.get_event_handler('another_custom_message'))
ns._set_server(mock.MagicMock())
self.assertIsNone(ns._get_event_handler('another_custom_message'))
self.assertEqual(result, {})
def test_emit(self):
ns = namespace.Namespace('/foo')
ns.set_server(mock.MagicMock())
ns._set_server(mock.MagicMock())
ns.emit('ev', data='data', room='room', skip_sid='skip',
callback='cb')
ns.server.emit.assert_called_with(
@ -73,7 +73,7 @@ class TestNamespace(unittest.TestCase):
def test_send(self):
ns = namespace.Namespace('/foo')
ns.set_server(mock.MagicMock())
ns._set_server(mock.MagicMock())
ns.send(data='data', room='room', skip_sid='skip', callback='cb')
ns.server.send.assert_called_with(
'data', room='room', skip_sid='skip', namespace='/foo',
@ -86,7 +86,7 @@ class TestNamespace(unittest.TestCase):
def test_enter_room(self):
ns = namespace.Namespace('/foo')
ns.set_server(mock.MagicMock())
ns._set_server(mock.MagicMock())
ns.enter_room('sid', 'room')
ns.server.enter_room.assert_called_with('sid', 'room',
namespace='/foo')
@ -96,7 +96,7 @@ class TestNamespace(unittest.TestCase):
def test_leave_room(self):
ns = namespace.Namespace('/foo')
ns.set_server(mock.MagicMock())
ns._set_server(mock.MagicMock())
ns.leave_room('sid', 'room')
ns.server.leave_room.assert_called_with('sid', 'room',
namespace='/foo')
@ -106,7 +106,7 @@ class TestNamespace(unittest.TestCase):
def test_close_room(self):
ns = namespace.Namespace('/foo')
ns.set_server(mock.MagicMock())
ns._set_server(mock.MagicMock())
ns.close_room('room')
ns.server.close_room.assert_called_with('room', namespace='/foo')
ns.close_room('room', namespace='/bar')
@ -114,7 +114,7 @@ class TestNamespace(unittest.TestCase):
def test_rooms(self):
ns = namespace.Namespace('/foo')
ns.set_server(mock.MagicMock())
ns._set_server(mock.MagicMock())
ns.rooms('sid')
ns.server.rooms.assert_called_with('sid', namespace='/foo')
ns.rooms('sid', namespace='/bar')
@ -122,7 +122,7 @@ class TestNamespace(unittest.TestCase):
def test_disconnect(self):
ns = namespace.Namespace('/foo')
ns.set_server(mock.MagicMock())
ns._set_server(mock.MagicMock())
ns.disconnect('sid')
ns.server.disconnect.assert_called_with('sid', namespace='/foo')
ns.disconnect('sid', namespace='/bar')

Loading…
Cancel
Save