Add test for bad-parameters-give-500-error
This commit is contained in:
parent
5970cd85cf
commit
62354b4dce
|
@ -39,7 +39,7 @@ def chunked_response(func):
|
|||
def workaround_cp_bug_1200(func): # pragma: no cover (just a workaround)
|
||||
"""Decorator to work around CherryPy bug #1200 in a response
|
||||
generator"""
|
||||
# Even if chunked responses are disabled, you may still miss miss
|
||||
# Even if chunked responses are disabled, you may still miss
|
||||
# LookupError, or UnicodeError exceptions due to CherryPy bug
|
||||
# #1200. This throws them as generic Exceptions insteads.
|
||||
import traceback
|
||||
|
@ -53,10 +53,15 @@ def workaround_cp_bug_1200(func): # pragma: no cover (just a workaround)
|
|||
traceback.format_exc())
|
||||
return wrapper
|
||||
|
||||
# Note that this decorator can't be used directly on a CherryPy
|
||||
# reequest handler, because CherryPy does tricks with introspection to
|
||||
# figure out whether the function parameters match the HTTP request.
|
||||
# A decorator would result in mismatched parameters giving a 500
|
||||
# response, when it should be 404. To keep things happy, use this
|
||||
# to decorate a function inside the handler.
|
||||
def exception_to_httperror(*expected):
|
||||
"""Return a decorator that catches expected errors and throws a
|
||||
HTTPError describing it instead. This lets us still raise proper
|
||||
500 Internal Server Errors when it's something unexpected."""
|
||||
HTTPError describing it instead."""
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
|
|
|
@ -70,6 +70,10 @@ class TestClient(object):
|
|||
eq_(distutils.version.StrictVersion(version),
|
||||
distutils.version.StrictVersion(test_server.version))
|
||||
|
||||
# Bad URLs should give 404, not 500
|
||||
with assert_raises(ClientError):
|
||||
client.http.get("/stream/create")
|
||||
|
||||
def test_client_2_createlist(self):
|
||||
# Basic stream tests, like those in test_nilmdb:test_stream
|
||||
client = nilmdb.Client(url = "http://localhost:12380/")
|
||||
|
|
Loading…
Reference in New Issue
Block a user