Skip to content

Instantly share code, notes, and snippets.

@shau-lok
Last active May 2, 2017 04:16
Show Gist options
  • Save shau-lok/559c1b93d2bb53e1c48aebbcaacebc2d to your computer and use it in GitHub Desktop.
Save shau-lok/559c1b93d2bb53e1c48aebbcaacebc2d to your computer and use it in GitHub Desktop.
tornado单元测试
from tornado.httpclient import AsyncHTTPClient
from tornado.testing import AsyncTestCase, gen_test
URL = 'http://www.tornadoweb.org'
class MyTestCase(AsyncTestCase):
@gen_test
def test_http_fetch(self):
client = AsyncHTTPClient(self.io_loop)
response = yield client.fetch(URL)
body = response.body.decode('utf-8')
print(body)
self.assertIn('FriendFeed', body)
class MyTestCase2(AsyncTestCase):
def test_http_fetch(self):
client = AsyncHTTPClient(self.io_loop)
client.fetch(URL, self.stop)
response = self.wait()
self.assertIn('FriendFeed', response.body.decode('utf-8'))
class MyTestCase3(AsyncTestCase):
def test_http_fetch(self):
client = AsyncHTTPClient(self.io_loop)
client.fetch(URL, self.handle_fetch)
self.wait()
def handle_fetch(self, response):
self.assertIn("FriendFeed", response.body.decode('utf-8'))
self.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment