]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
remove deprecated routing and middleware decorators from test_authentication.py ...
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Thu, 10 Feb 2022 10:22:46 +0000 (04:22 -0600)
committerGitHub <noreply@github.com>
Thu, 10 Feb 2022 10:22:46 +0000 (11:22 +0100)
tests/test_authentication.py

index e32567d0519d967eabcf4283db3e885b3e566a98..65b49c3ca50c6e715f857528cbca5758c8183f4c 100644 (file)
@@ -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"))