]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Rename AsyncSSLTestCase to AsyncHTTPTestCase.
authorBen Darnell <ben@bendarnell.com>
Fri, 8 Jun 2012 19:04:52 +0000 (12:04 -0700)
committerBen Darnell <ben@bendarnell.com>
Fri, 8 Jun 2012 19:04:52 +0000 (12:04 -0700)
Move get_ssl_version to the httpserver_test subclasses.
Add some quick docs.

tornado/test/httpserver_test.py
tornado/testing.py

index f761fd94976f78eb5402e7b7681ab4eeb46f15b0..de09f234e6ff81e0f5ee79d4c53cb6ba67c7398a 100644 (file)
@@ -8,7 +8,7 @@ from tornado.httpserver import HTTPServer
 from tornado.httputil import HTTPHeaders
 from tornado.iostream import IOStream
 from tornado.simple_httpclient import SimpleAsyncHTTPClient
-from tornado.testing import AsyncHTTPTestCase, AsyncSSLTestCase, AsyncTestCase, LogTrapTestCase
+from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, LogTrapTestCase
 from tornado.util import b, bytes_type
 from tornado.web import Application, RequestHandler
 import os
@@ -45,13 +45,20 @@ class HelloWorldRequestHandler(RequestHandler):
         self.finish("Got %d bytes in POST" % len(self.request.body))
 
 
-class BaseSSLTest(AsyncSSLTestCase, LogTrapTestCase):
+class BaseSSLTest(AsyncHTTPSTestCase, LogTrapTestCase):
     def get_app(self):
         return Application([('/', HelloWorldRequestHandler,
                              dict(protocol="https"))])
 
 
 class SSLTestMixin(object):
+    def get_ssl_options(self):
+        return dict(ssl_version = self.get_ssl_version(),
+                    **AsyncHTTPSTestCase.get_ssl_options())
+
+    def get_ssl_version(self):
+        raise NotImplementedError()
+
     def test_ssl(self):
         response = self.fetch('/')
         self.assertEqual(response.body, b("Hello world"))
@@ -94,8 +101,9 @@ class TLSv1Test(BaseSSLTest, SSLTestMixin):
 
 
 class SSLv2Test(BaseSSLTest):
-    def get_ssl_version(self):
-        return ssl.PROTOCOL_SSLv2
+    def get_ssl_options(self):
+        return dict(ssl_version=ssl.PROTOCOL_SSLv2,
+                    **AsyncHTTPSTestCase.get_ssl_options(self))
 
     def test_sslv2_fail(self):
         # This is really more of a client test, but run it here since
index b31ec4465bc004c9e357a92b17d81daae9a5ff4e..e809123e03aad8cfe4e1e2c764a7ba6f505e3293 100644 (file)
@@ -294,10 +294,11 @@ class AsyncHTTPTestCase(AsyncTestCase):
         super(AsyncHTTPTestCase, self).tearDown()
 
 
-class AsyncSSLTestCase(AsyncHTTPTestCase):
-    def get_ssl_version(self):
-        raise NotImplementedError()
+class AsyncHTTPSTestCase(AsyncHTTPTestCase):
+    """A test case that starts an HTTPS server.
 
+    Interface is generally the same as `AsyncHTTPTestCase`.
+    """
     def get_http_client(self):
         # Some versions of libcurl have deadlock bugs with ssl,
         # so always run these tests with SimpleAsyncHTTPClient.
@@ -307,13 +308,16 @@ class AsyncSSLTestCase(AsyncHTTPTestCase):
         return dict(ssl_options=self.get_ssl_options())
 
     def get_ssl_options(self):
+        """May be overridden by subclasses to select SSL options.
+
+        By default includes a self-signed testing certificate.
+        """
         # Testing keys were generated with:
         # openssl req -new -keyout tornado/test/test.key -out tornado/test/test.crt -nodes -days 3650 -x509
         module_dir = os.path.dirname(__file__)
         return dict(
                 certfile=os.path.join(module_dir, 'test', 'test.crt'),
-                keyfile=os.path.join(module_dir, 'test', 'test.key'),
-                ssl_version=self.get_ssl_version())
+                keyfile=os.path.join(module_dir, 'test', 'test.key'))
 
     def get_protocol(self):
         return 'https'