Skip to content

Commit a2f2dda

Browse files
TechNiickScirlat Danut
andauthored
Added type annotations to test_session.py (#2466)
Co-authored-by: Scirlat Danut <[email protected]>
1 parent 801e73e commit a2f2dda

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

tests/middleware/test_session.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
import re
2+
from typing import Callable
23

34
from starlette.applications import Starlette
45
from starlette.middleware import Middleware
56
from starlette.middleware.sessions import SessionMiddleware
7+
from starlette.requests import Request
68
from starlette.responses import JSONResponse
79
from starlette.routing import Mount, Route
810
from starlette.testclient import TestClient
911

12+
TestClientFactory = Callable[..., TestClient]
1013

11-
def view_session(request):
14+
15+
def view_session(request: Request) -> JSONResponse:
1216
return JSONResponse({"session": request.session})
1317

1418

15-
async def update_session(request):
19+
async def update_session(request: Request) -> JSONResponse:
1620
data = await request.json()
1721
request.session.update(data)
1822
return JSONResponse({"session": request.session})
1923

2024

21-
async def clear_session(request):
25+
async def clear_session(request: Request) -> JSONResponse:
2226
request.session.clear()
2327
return JSONResponse({"session": request.session})
2428

2529

26-
def test_session(test_client_factory):
30+
def test_session(test_client_factory: TestClientFactory) -> None:
2731
app = Starlette(
2832
routes=[
2933
Route("/view_session", endpoint=view_session),
@@ -56,7 +60,7 @@ def test_session(test_client_factory):
5660
assert response.json() == {"session": {}}
5761

5862

59-
def test_session_expires(test_client_factory):
63+
def test_session_expires(test_client_factory: TestClientFactory) -> None:
6064
app = Starlette(
6165
routes=[
6266
Route("/view_session", endpoint=view_session),
@@ -80,7 +84,7 @@ def test_session_expires(test_client_factory):
8084
assert response.json() == {"session": {}}
8185

8286

83-
def test_secure_session(test_client_factory):
87+
def test_secure_session(test_client_factory: TestClientFactory) -> None:
8488
app = Starlette(
8589
routes=[
8690
Route("/view_session", endpoint=view_session),
@@ -119,7 +123,7 @@ def test_secure_session(test_client_factory):
119123
assert response.json() == {"session": {}}
120124

121125

122-
def test_session_cookie_subpath(test_client_factory):
126+
def test_session_cookie_subpath(test_client_factory: TestClientFactory) -> None:
123127
second_app = Starlette(
124128
routes=[
125129
Route("/update_session", endpoint=update_session, methods=["POST"]),
@@ -139,7 +143,7 @@ def test_session_cookie_subpath(test_client_factory):
139143
assert cookie_path == "/second_app"
140144

141145

142-
def test_invalid_session_cookie(test_client_factory):
146+
def test_invalid_session_cookie(test_client_factory: TestClientFactory) -> None:
143147
app = Starlette(
144148
routes=[
145149
Route("/view_session", endpoint=view_session),
@@ -158,7 +162,7 @@ def test_invalid_session_cookie(test_client_factory):
158162
assert response.json() == {"session": {}}
159163

160164

161-
def test_session_cookie(test_client_factory):
165+
def test_session_cookie(test_client_factory: TestClientFactory) -> None:
162166
app = Starlette(
163167
routes=[
164168
Route("/view_session", endpoint=view_session),
@@ -180,7 +184,7 @@ def test_session_cookie(test_client_factory):
180184
assert response.json() == {"session": {}}
181185

182186

183-
def test_domain_cookie(test_client_factory):
187+
def test_domain_cookie(test_client_factory: TestClientFactory) -> None:
184188
app = Starlette(
185189
routes=[
186190
Route("/view_session", endpoint=view_session),

0 commit comments

Comments
 (0)