【发布时间】:2016-08-03 13:01:55
【问题描述】:
我是使用脚本进行单元测试的新手。我尝试使用帖子数据中的参数验证登录,但我得到登录页面作为响应并且没有登录。由于@tornado.web.authenticated 我无法在没有登录的情况下访问其他功能并且它响应登录页面
import tornado
from tornado.testing import AsyncTestCase
from tornado.web import Application, RequestHandler
import app
import urllib
class MyTestCase(AsyncTestCase):
@tornado.testing.gen_test
def test_http_fetch_login(self):
data = urllib.urlencode(dict(username='admin', password=''))
client = AsyncHTTPClient(self.io_loop)
response = yield client.fetch("http://localhost:8888/console/login/?", method="POST",body=data)
# Test contents of response
self.assertIn("Automaton web console", response.body)
@tornado.testing.gen_test
def test_http_fetch_config(self):
client = AsyncHTTPClient(self.io_loop)
response = yield client.fetch("http://localhost:8888/console/configuration/?")
self.assertIn("server-version",response.body)
【问题讨论】:
标签: python unit-testing web-applications tornado