From d22a6123229fd7493c5bff45ff7917329c9a2702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Rubin?= Date: Mon, 18 Dec 2023 17:21:55 +0100 Subject: [PATCH] fix: Fix tests after adding type annotations to Middleware. --- tests/middleware/test_middleware.py | 4 +++- tests/test_authentication.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/middleware/test_middleware.py b/tests/middleware/test_middleware.py index f4d7a32f0..938250f08 100644 --- a/tests/middleware/test_middleware.py +++ b/tests/middleware/test_middleware.py @@ -1,8 +1,10 @@ from starlette.middleware import Middleware +from starlette.types import ASGIApp class CustomMiddleware: - pass + def __init__(self, app: ASGIApp) -> None: + self.app = app # pragma: no cover def test_middleware_repr(): diff --git a/tests/test_authentication.py b/tests/test_authentication.py index af0beafd0..150482a1b 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -15,7 +15,7 @@ from starlette.endpoints import HTTPEndpoint from starlette.middleware import Middleware from starlette.middleware.authentication import AuthenticationMiddleware -from starlette.requests import Request +from starlette.requests import HTTPConnection from starlette.responses import JSONResponse from starlette.routing import Route, WebSocketRoute from starlette.websockets import WebSocketDisconnect @@ -327,7 +327,7 @@ def test_authentication_redirect(test_client_factory): assert response.json() == {"authenticated": True, "user": "tomchristie"} -def on_auth_error(request: Request, exc: Exception): +def on_auth_error(request: HTTPConnection, exc: AuthenticationError): return JSONResponse({"error": str(exc)}, status_code=401)