我是新來的單元測試使用的腳本。我試圖驗證與POST數據參數登錄,但是我得到的登錄頁面的響應,並登錄不上去的@tornado.web.authenticated
in.Because沒有登錄我無法訪問其它功能,它響應到登錄頁面如何使用tornado.testing測試`@ 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)