[英]Automated testing of routes using Python Bottle framework
我想建立一种自动化的方法来测试我的Python / Bottle Web应用程序中的所有路由,因为我目前大约有100条路由。 做这个的最好方式是什么?
我推荐WebTest ; 它功能齐全,非常易于使用。 这是一个完整的工作示例,演示了一个简单的测试:
from bottle import Bottle, response
from webtest import TestApp
# the real webapp
app = Bottle()
@app.route('/rest/<name>')
def root(name):
'''Simple example to demonstrate how to test Bottle routes'''
response.content_type = 'text/plain'
return ['you requested "{}"'.format(name)]
def test_root():
'''Test GET /'''
# wrap the real app in a TestApp object
test_app = TestApp(app)
# simulate a call (HTTP GET)
resp = test_app.get('/rest/roger')
# validate the response
assert resp.body == 'you requested "roger"'
assert resp.content_type == 'text/plain'
# run the test
test_root()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.