def test_app_using_router(self): greetings = 'Hello, World!!!' @webob.dec.wsgify def hello(req): return greetings mapper = routes.Mapper() mapper.connect(None, "/v1.0/{path_info:.*}", controller=hello) router = wsgi.Router(mapper) server = wsgi.Service(router, 0) server.start() response = urllib2.urlopen('http://127.0.0.1:%d/v1.0/' % server.port) self.assertEqual(greetings, response.read()) server.stop()
def test_app(self): greetings = 'Hello, World!!!' def hello_world(env, start_response): if env['PATH_INFO'] != '/': start_response('404 Not Found', [('Content-Type', 'text/plain')]) return ['Not Found\r\n'] start_response('200 OK', [('Content-Type', 'text/plain')]) return [greetings] server = wsgi.Service(hello_world, 0) server.start() response = urllib2.urlopen('http://127.0.0.1:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop()
def test_ipv6_listen_called_with_scope(self): with mock.patch.object(wsgi.eventlet, 'listen') as mock_listen: with mock.patch.object(socket, 'getaddrinfo') as mock_get_addr: mock_get_addr.return_value = [ (socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP, '', ('fe80::204:acff:fe96:da87%eth0', 1234, 0, 2)) ] wsgi.Service("test_app", 1234, host="fe80::204:acff:fe96:da87%eth0") mock_get_addr.assert_called_once_with( "fe80::204:acff:fe96:da87%eth0", 1234, socket.AF_UNSPEC, socket.SOCK_STREAM) mock_listen.assert_called_once_with( ('fe80::204:acff:fe96:da87%eth0', 1234, 0, 2), backlog=4096, family=socket.AF_INET6)
def test_app_using_router_ipv6_and_ssl(self): self.config(cert_file=os.path.join(TEST_VAR_DIR, 'certificate.crt'), group="ssl") self.config(key_file=os.path.join(TEST_VAR_DIR, 'privatekey.key'), group="ssl") greetings = 'Hello, World!!!' @webob.dec.wsgify def hello(req): return greetings mapper = routes.Mapper() mapper.connect(None, "/v1.0/{path_info:.*}", controller=hello) router = wsgi.Router(mapper) server = wsgi.Service(router, 0, host="::1") server.start() response = urllib2.urlopen('https://[::1]:%d/v1.0/' % server.port) self.assertEqual(greetings, response.read()) server.stop()
def test_start_random_port_with_ipv6(self): server = wsgi.Service('test_random_port', 0, host="::1") server.start() self.assertEqual("::1", server.host) self.assertNotEqual(0, server.port) server.stop()
def test_start_random_port(self): server = wsgi.Service('test_random_port', 0) server.start() self.assertEqual("0.0.0.0", server.host) self.assertNotEqual(0, server.port) server.stop()
def test_pool(self): server = wsgi.Service('fake', 9000) self.assertTrue(server.tg) self.assertTrue(server.tg.pool) self.assertEqual(server.tg.pool.free(), 1000)