Commit 864e218d authored by Denis Bilenko's avatar Denis Bilenko

TestHttps: reuse setUp()

parent 25cc1b63
......@@ -482,29 +482,26 @@ class TestUseWrite(TestCase):
response.assertHeader('Content-Length', str(5+5+3))
class TestHttps(TestCase):
class HttpsTestCase(TestCase):
def setUp(self):
def get_listener(self):
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
sock = socket.socket()
socket.bind_and_listen(sock, ('', 4201))
self.sock = socket.ssl(sock, private_key_file, certificate_file)
self.g = gevent.spawn(self.get_wsgi_module().server, self.sock, validator(self.application))
def tearDown(self):
self.g.kill(block=True)
socket.bind_and_listen(sock, ('', 0))
return socket.ssl(sock, private_key_file, certificate_file)
def urlopen(self, *args, **kwargs):
req = HTTPRequest("https://localhost:4201/foo", *args, **kwargs)
req = HTTPRequest("https://localhost:%s/foo" % self.server.server_port, *args, **kwargs)
return urllib2.urlopen(req)
def application(self, environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [environ['wsgi.input'].read()]
class TestHttps(HttpsTestCase):
def test_012_ssl_server(self):
result = self.urlopen(method="POST", data='abc').read()
self.assertEquals(result, 'abc')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment