]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Tie the example for AsyncHTTPTestCase to real code. 1456/head
authorGreg Ward <greg@gerg.ca>
Sun, 21 Jun 2015 14:29:45 +0000 (10:29 -0400)
committerGreg Ward <greg@gerg.ca>
Sun, 21 Jun 2015 14:29:45 +0000 (10:29 -0400)
Now all the reader has to do is copy one of the "Hello, world"
examples to hello.py, copy the test example to test_hello.py, import
AsyncHTTPTestCase, and run the test. It's still not entirely seamless
and idiot-proof, but it's progress!

Of note: the example test can now actually assert things about the
response it receives.

tornado/testing.py

index 5bac5de7063a8dccfff05bf2681b39c5d2924af3..40509956b22e9084e2ba3f9d4bb903942b33123d 100644 (file)
@@ -331,14 +331,19 @@ class AsyncHTTPTestCase(AsyncTestCase):
     Tests will typically use the provided ``self.http_client`` to fetch
     URLs from this server.
 
-    Example::
+    Example, assuming the "Hello, world" example from the user guide is in
+    ``hello.py``::
+
+        import hello
 
-        class MyHTTPTest(AsyncHTTPTestCase):
+        class TestHelloApp(AsyncHTTPTestCase):
             def get_app(self):
-                return Application([('/', MyHandler)...])
+                return hello.make_app()
 
             def test_homepage(self):
                 response = self.fetch('/')
+                self.assertEqual(response.code, 200)
+                self.assertEqual(response.body, 'Hello, world')
 
     That call to ``self.fetch()`` is equivalent to ::