from bottle import Bottle, redirect
from webtest import TestApp
# the real webapp
app = Bottle()
@app.route('/mypage')
def mypage():
'''Redirect'''
redirect('https://some/other/url')
def test_redirect():
'''Test that GET /mypage redirects'''
# wrap the real app in a TestApp object
test_app = TestApp(app)
# simulate a call (HTTP GET)
resp = test_app.get('/mypage', status=[302])
# validate the response
assert resp.headers['Location'] == 'https://some/other/url'
# run the test
test_redirect()
WebTest是测试WSGI应用程序的功能齐全且简单的方法。下面是一个检查重定向的示例:
相关问题 更多 >
编程相关推荐