Account for BP with exception handler but no routes (#2246)

This commit is contained in:
Adam Hopkins
2021-09-29 13:47:31 +03:00
committed by GitHub
parent 6ffc4d9756
commit ba2670e99c
2 changed files with 59 additions and 7 deletions

View File

@@ -83,7 +83,6 @@ def test_versioned_routes_get(app, method):
return text("OK")
else:
print(func)
raise Exception(f"{func} is not callable")
app.blueprint(bp)
@@ -477,6 +476,58 @@ def test_bp_exception_handler(app):
assert response.status == 200
def test_bp_exception_handler_applied(app):
class Error(Exception):
pass
handled = Blueprint("handled")
nothandled = Blueprint("nothandled")
@handled.exception(Error)
def handle_error(req, e):
return text("handled {}".format(e))
@handled.route("/ok")
def ok(request):
raise Error("uh oh")
@nothandled.route("/notok")
def notok(request):
raise Error("uh oh")
app.blueprint(handled)
app.blueprint(nothandled)
_, response = app.test_client.get("/ok")
assert response.status == 200
assert response.text == "handled uh oh"
_, response = app.test_client.get("/notok")
assert response.status == 500
def test_bp_exception_handler_not_applied(app):
class Error(Exception):
pass
handled = Blueprint("handled")
nothandled = Blueprint("nothandled")
@handled.exception(Error)
def handle_error(req, e):
return text("handled {}".format(e))
@nothandled.route("/notok")
def notok(request):
raise Error("uh oh")
app.blueprint(handled)
app.blueprint(nothandled)
_, response = app.test_client.get("/notok")
assert response.status == 500
def test_bp_listeners(app):
app.route("/")(lambda x: x)
blueprint = Blueprint("test_middleware")