Browse Source

allow events to be sent from the connect handler

pull/5/head
Miguel Grinberg 10 years ago
parent
commit
19042e1570
  1. 3
      socketio/server.py
  2. 6
      tests/test_server.py

3
socketio/server.py

@ -290,12 +290,13 @@ class Server(object):
def _handle_connect(self, sid, namespace):
"""Handle a client connection request."""
namespace = namespace or '/'
self.manager.connect(sid, namespace)
if self._trigger_event('connect', namespace, sid,
self.environ[sid]) is False:
self.manager.disconnect(sid, namespace)
self._send_packet(sid, packet.Packet(packet.ERROR,
namespace=namespace))
else:
self.manager.connect(sid, namespace)
self._send_packet(sid, packet.Packet(packet.CONNECT,
namespace=namespace))

6
tests/test_server.py

@ -167,7 +167,8 @@ class TestServer(unittest.TestCase):
s.on('connect', handler)
s._handle_eio_connect('123', 'environ')
handler.assert_called_once_with('123', 'environ')
self.assertEqual(s.manager.connect.call_count, 0)
self.assertEqual(s.manager.connect.call_count, 1)
self.assertEqual(s.manager.disconnect.call_count, 1)
s.eio.send.assert_called_once_with('123', '4', binary=False)
def test_handle_connect_namespace_rejected(self, eio):
@ -177,7 +178,8 @@ class TestServer(unittest.TestCase):
s.on('connect', handler, namespace='/foo')
s._handle_eio_connect('123', 'environ')
s._handle_eio_message('123', '0/foo')
self.assertEqual(s.manager.connect.call_count, 1)
self.assertEqual(s.manager.connect.call_count, 2)
self.assertEqual(s.manager.disconnect.call_count, 1)
s.eio.send.assert_any_call('123', '4/foo', binary=False)
def test_handle_disconnect(self, eio):

Loading…
Cancel
Save