]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a convenience method for synchronous fetches in AsyncHTTPTestCase
authorBen Darnell <ben@bendarnell.com>
Tue, 19 Oct 2010 19:26:10 +0000 (12:26 -0700)
committerBen Darnell <ben@bendarnell.com>
Tue, 19 Oct 2010 19:28:36 +0000 (12:28 -0700)
tornado/testing.py

index d7d81074263f7902daef48ae3bfd176cc8bb9996..485f840c724d1e7b52454034a885a68e559f8324 100644 (file)
@@ -198,6 +198,10 @@ class AsyncHTTPTestCase(AsyncTestCase):
                 return Application([('/', MyHandler)...])
 
             def test_homepage(self):
+                # The following two lines are equivalent to
+                #   response = self.fetch('/')
+                # but are shown in full here to demonstrate explicit use
+                # of self.stop and self.wait.
                 self.http_client.fetch(self.get_url('/'), self.stop)
                 response = self.wait()
                 # test contents of response
@@ -218,6 +222,17 @@ class AsyncHTTPTestCase(AsyncTestCase):
         """
         raise NotImplementedError()
 
+    def fetch(self, path, **kwargs):
+        """Convenience method to synchronously fetch a url.
+
+        The given path will be appended to the local server's host and port.
+        Any additional kwargs will be passed directly to
+        AsyncHTTPClient.fetch (and so could be used to pass method="POST",
+        body="...", etc).
+        """
+        self.http_client.fetch(self.get_url(path), self.stop, **kwargs)
+        return self.wait()
+
     def get_httpserver_options(self):
         """May be overridden by subclasses to return additional
         keyword arguments for HTTPServer.