def test_async_mode_invalid(self, import_module): with pytest.raises(ValueError): server.Server(async_mode='foo')
def test_jsonp_not_supported(self): s = server.Server() environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'j=abc'} start_response = mock.MagicMock() s.handle_request(environ, start_response) self.assertEqual(start_response.call_args[0][0], '400 BAD REQUEST')
def test_is_asyncio_based(self): s = server.Server() self.assertEqual(s.is_asyncio_based(), False)
def test_generate_id(self): s = server.Server() self.assertNotEqual(s._generate_id(), s._generate_id())
def test_bad_session(self): s = server.Server() s.sockets['foo'] = 'client' self.assertRaises(KeyError, s._get_socket, 'bar')
def test_create_ignores_kwargs(self): server.Server(foo='bar') # this should not raise
def test_async_mode_auto_gevent(self, import_module): s = server.Server() self.assertEqual(s.async_mode, 'gevent')
def test_closed_socket(self): s = server.Server() s.sockets['foo'] = self._get_mock_socket() s.sockets['foo'].closed = True with pytest.raises(KeyError): s._get_socket('foo')
def test_jsonp_with_bad_index(self): s = server.Server() environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'j=abc'} start_response = mock.MagicMock() s.handle_request(environ, start_response) assert start_response.call_args[0][0] == '400 BAD REQUEST'
def test_on_event_invalid(self): s = server.Server() with pytest.raises(ValueError): s.on('invalid')
def test_bad_session(self): s = server.Server() s.sockets['foo'] = 'client' with pytest.raises(KeyError): s._get_socket('bar')
def test_generate_id(self): s = server.Server() assert s._generate_id() != s._generate_id()
def test_async_mode_auto_threading(self, import_module): s = server.Server() assert s.async_mode == 'threading'
def test_async_mode_auto_gevent(self, import_module): s = server.Server() assert s.async_mode == 'gevent'
def test_send_unknown_socket(self): s = server.Server() # just ensure no exceptions are raised s.send('foo', 'hello')
def test_is_asyncio_based(self): s = server.Server() assert not s.is_asyncio_based()
def test_async_modes(self): s = server.Server() self.assertEqual(s.async_modes(), ['eventlet', 'gevent_uwsgi', 'gevent', 'threading'])
def test_method_not_found(self): s = server.Server() environ = {'REQUEST_METHOD': 'PUT', 'QUERY_STRING': ''} start_response = mock.MagicMock() s.handle_request(environ, start_response) assert start_response.call_args[0][0] == '405 METHOD NOT FOUND'
def test_sleep(self): s = server.Server() t = time.time() s.sleep(0.1) self.assertTrue(time.time() - t > 0.1)
def test_create_with_grace_period(self): s = server.Server(ping_interval=(1, 2)) assert s.ping_interval == 1 assert s.ping_interval_grace_period == 2
def test_async_mode_auto_threading(self, import_module): s = server.Server() self.assertEqual(s.async_mode, 'threading')
def test_create_with_grace_period(self): s = server.Server(ping_interval=(1, 2)) self.assertEqual(s.ping_interval, 1) self.assertEqual(s.ping_interval_grace_period, 2)
def test_on_event_invalid(self): s = server.Server() self.assertRaises(ValueError, s.on, 'invalid')
def test_connect_bad_poll(self, poll): s = server.Server() environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': ''} start_response = mock.MagicMock() s.handle_request(environ, start_response) self.assertEqual(start_response.call_args[0][0], '400 BAD REQUEST')
def test_closed_socket(self): s = server.Server() s.sockets['foo'] = self._get_mock_socket() s.sockets['foo'].closed = True self.assertRaises(KeyError, s._get_socket, 'foo')
def test_create_queue(self): s = server.Server() q = s.create_queue() empty = s.get_queue_empty_exception() self.assertRaises(empty, q.get, timeout=0.01)
def test_connect_transport_invalid(self): s = server.Server() environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'transport=foo'} start_response = mock.MagicMock() s.handle_request(environ, start_response) self.assertEqual(start_response.call_args[0][0], '400 BAD REQUEST')
def test_create_event(self): s = server.Server() e = s.create_event() self.assertFalse(e.is_set()) e.set() self.assertTrue(e.is_set())
def test_get_request_with_bad_sid(self): s = server.Server() environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=foo'} start_response = mock.MagicMock() s.handle_request(environ, start_response) self.assertEqual(start_response.call_args[0][0], '400 BAD REQUEST')
def test_async_mode_aiohttp(self, import_module): sys.modules['aiohttp'] = mock.MagicMock() with pytest.raises(ValueError): server.Server(async_mode='aiohttp')