GIT-37: fix blueprint middleware application (#1690)
* GIT-37: fix blueprint middleware application 1. If you register a middleware via `@blueprint.middleware` then it will apply only to the routes defined by the blueprint. 2. If you register a middleware via `@blueprint_group.middleware` then it will apply to all blueprint based routes that are part of the group. 3. If you define a middleware via `@app.middleware` then it will be applied on all available routes Fixes #37 Signed-off-by: Harsha Narayana <harsha2k4@gmail.com> * GIT-37: add changelog Signed-off-by: Harsha Narayana <harsha2k4@gmail.com>
This commit is contained in:
committed by
Stephen Sadowski
parent
179a07942e
commit
a6077a1790
@@ -94,7 +94,7 @@ def test_app_route_raise_value_error(app):
|
||||
|
||||
def test_app_handle_request_handler_is_none(app, monkeypatch):
|
||||
def mockreturn(*args, **kwargs):
|
||||
return None, [], {}, ""
|
||||
return None, [], {}, "", ""
|
||||
|
||||
# Not sure how to make app.router.get() return None, so use mock here.
|
||||
monkeypatch.setattr(app.router, "get", mockreturn)
|
||||
|
||||
@@ -83,7 +83,7 @@ def test_bp_group_with_additional_route_params(app: Sanic):
|
||||
_, response = app.test_client.patch("/api/bp2/route/bp2", headers=header)
|
||||
assert response.text == "PATCH_bp2"
|
||||
|
||||
_, response = app.test_client.get("/v2/api/bp1/request_path")
|
||||
_, response = app.test_client.put("/v2/api/bp1/request_path")
|
||||
assert response.status == 401
|
||||
|
||||
|
||||
@@ -141,8 +141,8 @@ def test_bp_group(app: Sanic):
|
||||
_, response = app.test_client.get("/api/bp3")
|
||||
assert response.text == "BP3_OK"
|
||||
|
||||
assert MIDDLEWARE_INVOKE_COUNTER["response"] == 4
|
||||
assert MIDDLEWARE_INVOKE_COUNTER["request"] == 4
|
||||
assert MIDDLEWARE_INVOKE_COUNTER["response"] == 3
|
||||
assert MIDDLEWARE_INVOKE_COUNTER["request"] == 2
|
||||
|
||||
|
||||
def test_bp_group_list_operations(app: Sanic):
|
||||
|
||||
@@ -268,7 +268,7 @@ def test_bp_middleware(app):
|
||||
request, response = app.test_client.get("/")
|
||||
|
||||
assert response.status == 200
|
||||
assert response.text == "OK"
|
||||
assert response.text == "FAIL"
|
||||
|
||||
|
||||
def test_bp_exception_handler(app):
|
||||
|
||||
Reference in New Issue
Block a user