Browse Source

Added transport method to server class

pull/5/head
Miguel Grinberg 10 years ago
parent
commit
37cd746a8e
  1. 10
      socketio/server.py
  2. 7
      tests/test_server.py

10
socketio/server.py

@ -278,6 +278,16 @@ class Server(object):
self._trigger_event('disconnect', namespace, sid)
self.manager.disconnect(sid, namespace=namespace)
def transport(self, sid):
"""Return the name of the transport used by the client.
The two possible values returned by this function are ``'polling'``
and ``'websocket'``.
:param sid: The session of the client.
"""
return self.eio.transport(sid)
def handle_request(self, environ, start_response):
"""Handle an HTTP request from the client.

7
tests/test_server.py

@ -144,6 +144,13 @@ class TestServer(unittest.TestCase):
s._emit_internal('123', u'my event', b'my binary data')
self.assertEqual(s.eio.send.call_count, 2)
def test_transport(self, eio):
s = server.Server()
s.eio.transport = mock.MagicMock(return_value='polling')
s._handle_eio_connect('foo', 'environ')
self.assertEqual(s.transport('foo'), 'polling')
s.eio.transport.assert_called_once_with('foo')
def test_handle_connect(self, eio):
mgr = mock.MagicMock()
s = server.Server(client_manager_class=mgr)

Loading…
Cancel
Save