diff options
Diffstat (limited to 'tests/middleware/test_catch_exceptions.py')
-rw-r--r-- | tests/middleware/test_catch_exceptions.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/middleware/test_catch_exceptions.py b/tests/middleware/test_catch_exceptions.py new file mode 100644 index 0000000..5042f7f --- /dev/null +++ b/tests/middleware/test_catch_exceptions.py @@ -0,0 +1,37 @@ +from wsgiref.validate import validator + +from paste import catch_exceptions + +from ..common_wsgi import call_app + + +def test_no_exception(): + @validator + @catch_exceptions + @validator + def app(_, start_response): + start_response("200 OK", [("Content-Type", "text/plain")]) + return [b"Hello, world!"] + + response = call_app(app) + assert response.data == b"Hello, world!" + assert response.status == "200 OK" + assert ("Content-Type", "text/plain") in response.headers + + +def test_exception(capfd): + @validator + @catch_exceptions + @validator + def app(_, start_response): + start_response("200 OK", [("Content-Type", "text/plain")]) + raise Exception("Something went wrong") + + response = call_app(app) + assert response.data == b"500 Internal Server Error\n" + assert response.status == "500 Internal Server Error" + assert ("Content-Type", "text/plain") in response.headers + out, _ = capfd.readouterr() + assert "Exception: Something went wrong\n" in out + assert response.exc_info is not None + assert isinstance(response.exc_info[1], Exception) |