From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Thu, 10 Feb 2022 10:22:46 +0000 (-0600) Subject: remove deprecated routing and middleware decorators from test_authentication.py ... X-Git-Tag: 0.19.0~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8538a1ce845cb5163cce81323c162931a6c7fbdc;p=thirdparty%2Fstarlette.git remove deprecated routing and middleware decorators from test_authentication.py (#1492) --- diff --git a/tests/test_authentication.py b/tests/test_authentication.py index e32567d0..65b49c3c 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -324,13 +324,6 @@ def on_auth_error(request: Request, exc: Exception): return JSONResponse({"error": str(exc)}, status_code=401) -other_app = Starlette() -other_app.add_middleware( - AuthenticationMiddleware, backend=BasicAuth(), on_error=on_auth_error -) - - -@other_app.route("/control-panel") @requires("authenticated") def control_panel(request): return JSONResponse( @@ -341,6 +334,16 @@ def control_panel(request): ) +other_app = Starlette( + routes=[Route("/control-panel", control_panel)], + middleware=[ + Middleware( + AuthenticationMiddleware, backend=BasicAuth(), on_error=on_auth_error + ) + ], +) + + def test_custom_on_error(test_client_factory): with test_client_factory(other_app) as client: response = client.get("/control-panel", auth=("tomchristie", "example"))