我正在尝试使用WebTest(版本2.0.20)来测试python bottle应用程序中的一个简单的健康检查端点,但我一直在收到AppError 404响应。我错过了什么吗?
在我的服务器文件中:
from bottle import Bottle
application = Bottle()
@application.route("/check")
def check():
return "Up and running!"
在我的测试文件中:
import httplib
import unittest
import webtest
from should_dsl import should
from nose.plugins.attrib import attr
from myservice.server import application
@attr("component_test")
class ServerComponentTests(unittest.TestCase):
def test_health_check_should_return_OK(self):
""" test health check endpoint should return OK"""
app = webtest.TestApp(application)
app.get(url="/health")
response.status | should | equal_to(httplib.OK)
运行nosetests
会产生以下结果:
E
======================================================================
ERROR: test health check endpoint should return OK
----------------------------------------------------------------------
Traceback (most recent call last):
File "..../myservice_env/myservice/test/__init__.py", line 41, in test_health_check_should_return_OK
app.get(url="/health")
File "..../myservice_env/local/lib/python2.7/site-packages/webtest/app.py", line 323, in get
expect_errors=expect_errors)
File "..../myservice_env/local/lib/python2.7/site-packages/webtest/app.py", line 632, in do_request
self._check_status(status, res)
File "..../myservice_env/local/lib/python2.7/site-packages/webtest/app.py", line 664, in _check_status
res)
AppError: Bad response: 404 Not Found (not 200 OK or 3xx redirect for http://localhost/health)
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>Error: 404 Not Found</title>
<style type="text/css">
html {background-color: #eee; font-family: sans;}
body {background-color: #fff; border: 1px solid #ddd;
padding: 15px; margin: 15px;}
pre {background-color: #eee; border: 1px solid #ddd; padding: 5px;}
</style>
</head>
<body>
<h1>Error: 404 Not Found</h1>
<p>Sorry, the requested URL <tt>'http://localhost:80/health'</tt>
caused an error:</p>
<pre>Not found: '/health'</pre>
</body>
</html>
----------------------------------------------------------------------
Ran 1 test in 0.010s
FAILED (errors=1)