diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-03-24 19:45:17 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-03-24 20:25:01 +0000 |
commit | 7bc36edb7b15cae90bbfa81187b63821466cdd59 (patch) | |
tree | 0c96857d0e77eee107ed792ddcea286e0fd14816 /tests/middleware/test_catch_exceptions.py | |
parent | f29abe40fb1eb063ef67651361a2f3f851b25ed1 (diff) | |
download | paste-7bc36edb7b15cae90bbfa81187b63821466cdd59.tar.gz paste-7bc36edb7b15cae90bbfa81187b63821466cdd59.tar.xz paste-7bc36edb7b15cae90bbfa81187b63821466cdd59.zip |
add middleware tests
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) |