Exemplo n.º 1
0
 def test_async_mode_invalid(self, import_module):
     with pytest.raises(ValueError):
         server.Server(async_mode='foo')
Exemplo n.º 2
0
 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')
Exemplo n.º 3
0
 def test_is_asyncio_based(self):
     s = server.Server()
     self.assertEqual(s.is_asyncio_based(), False)
Exemplo n.º 4
0
 def test_generate_id(self):
     s = server.Server()
     self.assertNotEqual(s._generate_id(), s._generate_id())
Exemplo n.º 5
0
 def test_bad_session(self):
     s = server.Server()
     s.sockets['foo'] = 'client'
     self.assertRaises(KeyError, s._get_socket, 'bar')
Exemplo n.º 6
0
 def test_create_ignores_kwargs(self):
     server.Server(foo='bar')  # this should not raise
Exemplo n.º 7
0
 def test_async_mode_auto_gevent(self, import_module):
     s = server.Server()
     self.assertEqual(s.async_mode, 'gevent')
Exemplo n.º 8
0
 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')
Exemplo n.º 9
0
 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'
Exemplo n.º 10
0
 def test_on_event_invalid(self):
     s = server.Server()
     with pytest.raises(ValueError):
         s.on('invalid')
Exemplo n.º 11
0
 def test_bad_session(self):
     s = server.Server()
     s.sockets['foo'] = 'client'
     with pytest.raises(KeyError):
         s._get_socket('bar')
Exemplo n.º 12
0
 def test_generate_id(self):
     s = server.Server()
     assert s._generate_id() != s._generate_id()
Exemplo n.º 13
0
 def test_async_mode_auto_threading(self, import_module):
     s = server.Server()
     assert s.async_mode == 'threading'
Exemplo n.º 14
0
 def test_async_mode_auto_gevent(self, import_module):
     s = server.Server()
     assert s.async_mode == 'gevent'
Exemplo n.º 15
0
 def test_send_unknown_socket(self):
     s = server.Server()
     # just ensure no exceptions are raised
     s.send('foo', 'hello')
Exemplo n.º 16
0
 def test_is_asyncio_based(self):
     s = server.Server()
     assert not s.is_asyncio_based()
Exemplo n.º 17
0
 def test_async_modes(self):
     s = server.Server()
     self.assertEqual(s.async_modes(),
                      ['eventlet', 'gevent_uwsgi', 'gevent', 'threading'])
Exemplo n.º 18
0
 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'
Exemplo n.º 19
0
 def test_sleep(self):
     s = server.Server()
     t = time.time()
     s.sleep(0.1)
     self.assertTrue(time.time() - t > 0.1)
Exemplo n.º 20
0
 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
Exemplo n.º 21
0
 def test_async_mode_auto_threading(self, import_module):
     s = server.Server()
     self.assertEqual(s.async_mode, 'threading')
Exemplo n.º 22
0
 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)
Exemplo n.º 23
0
 def test_on_event_invalid(self):
     s = server.Server()
     self.assertRaises(ValueError, s.on, 'invalid')
Exemplo n.º 24
0
 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')
Exemplo n.º 25
0
 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')
Exemplo n.º 26
0
 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)
Exemplo n.º 27
0
 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')
Exemplo n.º 28
0
 def test_create_event(self):
     s = server.Server()
     e = s.create_event()
     self.assertFalse(e.is_set())
     e.set()
     self.assertTrue(e.is_set())
Exemplo n.º 29
0
 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')
Exemplo n.º 30
0
 def test_async_mode_aiohttp(self, import_module):
     sys.modules['aiohttp'] = mock.MagicMock()
     with pytest.raises(ValueError):
         server.Server(async_mode='aiohttp')