diff --git a/tests/middleware/test_session.py b/tests/middleware/test_session.py index dc1094117..4fbeec88c 100644 --- a/tests/middleware/test_session.py +++ b/tests/middleware/test_session.py @@ -1,29 +1,33 @@ import re +from typing import Callable from starlette.applications import Starlette from starlette.middleware import Middleware from starlette.middleware.sessions import SessionMiddleware +from starlette.requests import Request from starlette.responses import JSONResponse from starlette.routing import Mount, Route from starlette.testclient import TestClient +TestClientFactory = Callable[..., TestClient] -def view_session(request): + +def view_session(request: Request) -> JSONResponse: return JSONResponse({"session": request.session}) -async def update_session(request): +async def update_session(request: Request) -> JSONResponse: data = await request.json() request.session.update(data) return JSONResponse({"session": request.session}) -async def clear_session(request): +async def clear_session(request: Request) -> JSONResponse: request.session.clear() return JSONResponse({"session": request.session}) -def test_session(test_client_factory): +def test_session(test_client_factory: TestClientFactory) -> None: app = Starlette( routes=[ Route("/view_session", endpoint=view_session), @@ -56,7 +60,7 @@ def test_session(test_client_factory): assert response.json() == {"session": {}} -def test_session_expires(test_client_factory): +def test_session_expires(test_client_factory: TestClientFactory) -> None: app = Starlette( routes=[ Route("/view_session", endpoint=view_session), @@ -80,7 +84,7 @@ def test_session_expires(test_client_factory): assert response.json() == {"session": {}} -def test_secure_session(test_client_factory): +def test_secure_session(test_client_factory: TestClientFactory) -> None: app = Starlette( routes=[ Route("/view_session", endpoint=view_session), @@ -119,7 +123,7 @@ def test_secure_session(test_client_factory): assert response.json() == {"session": {}} -def test_session_cookie_subpath(test_client_factory): +def test_session_cookie_subpath(test_client_factory: TestClientFactory) -> None: second_app = Starlette( routes=[ Route("/update_session", endpoint=update_session, methods=["POST"]), @@ -139,7 +143,7 @@ def test_session_cookie_subpath(test_client_factory): assert cookie_path == "/second_app" -def test_invalid_session_cookie(test_client_factory): +def test_invalid_session_cookie(test_client_factory: TestClientFactory) -> None: app = Starlette( routes=[ Route("/view_session", endpoint=view_session), @@ -158,7 +162,7 @@ def test_invalid_session_cookie(test_client_factory): assert response.json() == {"session": {}} -def test_session_cookie(test_client_factory): +def test_session_cookie(test_client_factory: TestClientFactory) -> None: app = Starlette( routes=[ Route("/view_session", endpoint=view_session), @@ -180,7 +184,7 @@ def test_session_cookie(test_client_factory): assert response.json() == {"session": {}} -def test_domain_cookie(test_client_factory): +def test_domain_cookie(test_client_factory: TestClientFactory) -> None: app = Starlette( routes=[ Route("/view_session", endpoint=view_session),