|
|
@ -21,13 +21,15 @@ class TestServer(unittest.TestCase): |
|
|
|
|
|
|
|
def test_create(self, eio): |
|
|
|
mgr = mock.MagicMock() |
|
|
|
s = server.Server(client_manager=mgr, binary=True, foo='bar') |
|
|
|
s = server.Server(client_manager=mgr, binary=True, |
|
|
|
async_handlers=True, foo='bar') |
|
|
|
s.handle_request({}, None) |
|
|
|
s.handle_request({}, None) |
|
|
|
eio.assert_called_once_with(**{'foo': 'bar'}) |
|
|
|
eio.assert_called_once_with(**{'foo': 'bar', 'async_handlers': False}) |
|
|
|
self.assertEqual(s.manager, mgr) |
|
|
|
self.assertEqual(s.eio.on.call_count, 3) |
|
|
|
self.assertEqual(s.binary, True) |
|
|
|
self.assertEqual(s.async_handlers, True) |
|
|
|
self.assertEqual(mgr.initialize.call_count, 1) |
|
|
|
|
|
|
|
def test_on_event(self, eio): |
|
|
@ -428,6 +430,8 @@ class TestServer(unittest.TestCase): |
|
|
|
self.assertRaises(ValueError, s.register_namespace, 123) |
|
|
|
self.assertRaises(ValueError, s.register_namespace, Dummy) |
|
|
|
self.assertRaises(ValueError, s.register_namespace, Dummy()) |
|
|
|
self.assertRaises(ValueError, s.register_namespace, |
|
|
|
namespace.Namespace) |
|
|
|
|
|
|
|
def test_logger(self, eio): |
|
|
|
s = server.Server(logger=False) |
|
|
@ -444,7 +448,8 @@ class TestServer(unittest.TestCase): |
|
|
|
|
|
|
|
def test_engineio_logger(self, eio): |
|
|
|
server.Server(engineio_logger='foo') |
|
|
|
eio.assert_called_once_with(**{'logger': 'foo'}) |
|
|
|
eio.assert_called_once_with(**{'logger': 'foo', |
|
|
|
'async_handlers': False}) |
|
|
|
|
|
|
|
def test_custom_json(self, eio): |
|
|
|
# Warning: this test cannot run in parallel with other tests, as it |
|
|
@ -460,7 +465,8 @@ class TestServer(unittest.TestCase): |
|
|
|
return '+++ decoded +++' |
|
|
|
|
|
|
|
server.Server(json=CustomJSON) |
|
|
|
eio.assert_called_once_with(**{'json': CustomJSON}) |
|
|
|
eio.assert_called_once_with(**{'json': CustomJSON, |
|
|
|
'async_handlers': False}) |
|
|
|
|
|
|
|
pkt = packet.Packet(packet_type=packet.EVENT, |
|
|
|
data={six.text_type('foo'): six.text_type('bar')}) |
|
|
@ -471,6 +477,13 @@ class TestServer(unittest.TestCase): |
|
|
|
# restore the default JSON module |
|
|
|
packet.Packet.json = json |
|
|
|
|
|
|
|
def test_async_handlers(self, eio): |
|
|
|
s = server.Server(async_handlers=True) |
|
|
|
s._handle_eio_message('123', '2["my message","a","b","c"]') |
|
|
|
s.eio.start_background_task.assert_called_once_with( |
|
|
|
s._handle_event_internal, s, '123', ['my message', 'a', 'b', 'c'], |
|
|
|
'/', None) |
|
|
|
|
|
|
|
def test_start_background_task(self, eio): |
|
|
|
s = server.Server() |
|
|
|
s.start_background_task('foo', 'bar', baz='baz') |
|
|
|