Skip to content

Commit

Permalink
Add a convenience method for synchronous fetches in AsyncHTTPTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Oct 19, 2010
1 parent c410292 commit 11fdd47
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tornado/testing.py
Expand Up @@ -198,6 +198,10 @@ def get_app(self):
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
Expand All @@ -218,6 +222,17 @@ def get_app(self):
"""
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.
Expand Down

0 comments on commit 11fdd47

Please sign in to comment.