Last active
May 2, 2017 04:16
-
-
Save shau-lok/559c1b93d2bb53e1c48aebbcaacebc2d to your computer and use it in GitHub Desktop.
tornado单元测试
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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