summaryrefslogtreecommitdiff
path: root/tests/test_exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_exceptions.py')
-rw-r--r--tests/test_exceptions.py80
1 files changed, 42 insertions, 38 deletions
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py
index 7bb19a28..616b39c8 100644
--- a/tests/test_exceptions.py
+++ b/tests/test_exceptions.py
@@ -15,41 +15,44 @@
import pytest
from werkzeug import exceptions
+from werkzeug._compat import text_type
from werkzeug.datastructures import WWWAuthenticate
from werkzeug.wrappers import Response
-from werkzeug._compat import text_type
def test_proxy_exception():
- orig_resp = Response('Hello World')
+ orig_resp = Response("Hello World")
with pytest.raises(exceptions.HTTPException) as excinfo:
exceptions.abort(orig_resp)
resp = excinfo.value.get_response({})
assert resp is orig_resp
- assert resp.get_data() == b'Hello World'
-
-
-@pytest.mark.parametrize('test', [
- (exceptions.BadRequest, 400),
- (exceptions.Unauthorized, 401, 'Basic "test realm"'),
- (exceptions.Forbidden, 403),
- (exceptions.NotFound, 404),
- (exceptions.MethodNotAllowed, 405, ['GET', 'HEAD']),
- (exceptions.NotAcceptable, 406),
- (exceptions.RequestTimeout, 408),
- (exceptions.Gone, 410),
- (exceptions.LengthRequired, 411),
- (exceptions.PreconditionFailed, 412),
- (exceptions.RequestEntityTooLarge, 413),
- (exceptions.RequestURITooLarge, 414),
- (exceptions.UnsupportedMediaType, 415),
- (exceptions.UnprocessableEntity, 422),
- (exceptions.Locked, 423),
- (exceptions.InternalServerError, 500),
- (exceptions.NotImplemented, 501),
- (exceptions.BadGateway, 502),
- (exceptions.ServiceUnavailable, 503)
-])
+ assert resp.get_data() == b"Hello World"
+
+
+@pytest.mark.parametrize(
+ "test",
+ [
+ (exceptions.BadRequest, 400),
+ (exceptions.Unauthorized, 401, 'Basic "test realm"'),
+ (exceptions.Forbidden, 403),
+ (exceptions.NotFound, 404),
+ (exceptions.MethodNotAllowed, 405, ["GET", "HEAD"]),
+ (exceptions.NotAcceptable, 406),
+ (exceptions.RequestTimeout, 408),
+ (exceptions.Gone, 410),
+ (exceptions.LengthRequired, 411),
+ (exceptions.PreconditionFailed, 412),
+ (exceptions.RequestEntityTooLarge, 413),
+ (exceptions.RequestURITooLarge, 414),
+ (exceptions.UnsupportedMediaType, 415),
+ (exceptions.UnprocessableEntity, 422),
+ (exceptions.Locked, 423),
+ (exceptions.InternalServerError, 500),
+ (exceptions.NotImplemented, 501),
+ (exceptions.BadGateway, 502),
+ (exceptions.ServiceUnavailable, 503),
+ ],
+)
def test_aborter_general(test):
exc_type = test[0]
args = test[1:]
@@ -72,25 +75,26 @@ def test_aborter_custom():
def test_exception_repr():
exc = exceptions.NotFound()
assert text_type(exc) == (
- '404 Not Found: The requested URL was not found '
- 'on the server. If you entered the URL manually please check your '
- 'spelling and try again.')
+ "404 Not Found: The requested URL was not found on the server."
+ " If you entered the URL manually please check your spelling"
+ " and try again."
+ )
assert repr(exc) == "<NotFound '404: Not Found'>"
- exc = exceptions.NotFound('Not There')
- assert text_type(exc) == '404 Not Found: Not There'
+ exc = exceptions.NotFound("Not There")
+ assert text_type(exc) == "404 Not Found: Not There"
assert repr(exc) == "<NotFound '404: Not Found'>"
- exc = exceptions.HTTPException('An error message')
- assert text_type(exc) == '??? Unknown Error: An error message'
+ exc = exceptions.HTTPException("An error message")
+ assert text_type(exc) == "??? Unknown Error: An error message"
assert repr(exc) == "<HTTPException '???: Unknown Error'>"
def test_method_not_allowed_methods():
- exc = exceptions.MethodNotAllowed(['GET', 'HEAD', 'POST'])
+ exc = exceptions.MethodNotAllowed(["GET", "HEAD", "POST"])
h = dict(exc.get_headers({}))
- assert h['Allow'] == 'GET, HEAD, POST'
- assert 'The method is not allowed' in exc.get_description()
+ assert h["Allow"] == "GET, HEAD, POST"
+ assert "The method is not allowed" in exc.get_description()
def test_unauthorized_www_authenticate():
@@ -101,8 +105,8 @@ def test_unauthorized_www_authenticate():
exc = exceptions.Unauthorized(www_authenticate=basic)
h = dict(exc.get_headers({}))
- assert h['WWW-Authenticate'] == str(basic)
+ assert h["WWW-Authenticate"] == str(basic)
exc = exceptions.Unauthorized(www_authenticate=[digest, basic])
h = dict(exc.get_headers({}))
- assert h['WWW-Authenticate'] == ', '.join((str(digest), str(basic)))
+ assert h["WWW-Authenticate"] == ", ".join((str(digest), str(basic)))