I'm trying to use WebTest (version 2.0.20) to test a simple health-check endpoint in a python bottle application, but I'm getting AppError 404 response all the time. Am I missing something?
in my server file:
from bottle import Bottle
application = Bottle()
@application.route("/check")
def check():
return "Up and running!"
in my test file:
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)
running nosetests yields the following:
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)
Aucun commentaire:
Enregistrer un commentaire