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(
)
+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"))