Tie the example for AsyncHTTPTestCase to real code.

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.
This commit is contained in:
Greg Ward 2015-06-21 10:29:45 -04:00
parent 177e03415a
commit 41c5f6646f
1 changed files with 8 additions and 3 deletions

View 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``::
class MyHTTPTest(AsyncHTTPTestCase):
import hello
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 ::