1
1
import re
2
+ from typing import Callable
2
3
3
4
from starlette .applications import Starlette
4
5
from starlette .middleware import Middleware
5
6
from starlette .middleware .sessions import SessionMiddleware
7
+ from starlette .requests import Request
6
8
from starlette .responses import JSONResponse
7
9
from starlette .routing import Mount , Route
8
10
from starlette .testclient import TestClient
9
11
12
+ TestClientFactory = Callable [..., TestClient ]
10
13
11
- def view_session (request ):
14
+
15
+ def view_session (request : Request ) -> JSONResponse :
12
16
return JSONResponse ({"session" : request .session })
13
17
14
18
15
- async def update_session (request ) :
19
+ async def update_session (request : Request ) -> JSONResponse :
16
20
data = await request .json ()
17
21
request .session .update (data )
18
22
return JSONResponse ({"session" : request .session })
19
23
20
24
21
- async def clear_session (request ) :
25
+ async def clear_session (request : Request ) -> JSONResponse :
22
26
request .session .clear ()
23
27
return JSONResponse ({"session" : request .session })
24
28
25
29
26
- def test_session (test_client_factory ) :
30
+ def test_session (test_client_factory : TestClientFactory ) -> None :
27
31
app = Starlette (
28
32
routes = [
29
33
Route ("/view_session" , endpoint = view_session ),
@@ -56,7 +60,7 @@ def test_session(test_client_factory):
56
60
assert response .json () == {"session" : {}}
57
61
58
62
59
- def test_session_expires (test_client_factory ) :
63
+ def test_session_expires (test_client_factory : TestClientFactory ) -> None :
60
64
app = Starlette (
61
65
routes = [
62
66
Route ("/view_session" , endpoint = view_session ),
@@ -80,7 +84,7 @@ def test_session_expires(test_client_factory):
80
84
assert response .json () == {"session" : {}}
81
85
82
86
83
- def test_secure_session (test_client_factory ) :
87
+ def test_secure_session (test_client_factory : TestClientFactory ) -> None :
84
88
app = Starlette (
85
89
routes = [
86
90
Route ("/view_session" , endpoint = view_session ),
@@ -119,7 +123,7 @@ def test_secure_session(test_client_factory):
119
123
assert response .json () == {"session" : {}}
120
124
121
125
122
- def test_session_cookie_subpath (test_client_factory ) :
126
+ def test_session_cookie_subpath (test_client_factory : TestClientFactory ) -> None :
123
127
second_app = Starlette (
124
128
routes = [
125
129
Route ("/update_session" , endpoint = update_session , methods = ["POST" ]),
@@ -139,7 +143,7 @@ def test_session_cookie_subpath(test_client_factory):
139
143
assert cookie_path == "/second_app"
140
144
141
145
142
- def test_invalid_session_cookie (test_client_factory ) :
146
+ def test_invalid_session_cookie (test_client_factory : TestClientFactory ) -> None :
143
147
app = Starlette (
144
148
routes = [
145
149
Route ("/view_session" , endpoint = view_session ),
@@ -158,7 +162,7 @@ def test_invalid_session_cookie(test_client_factory):
158
162
assert response .json () == {"session" : {}}
159
163
160
164
161
- def test_session_cookie (test_client_factory ) :
165
+ def test_session_cookie (test_client_factory : TestClientFactory ) -> None :
162
166
app = Starlette (
163
167
routes = [
164
168
Route ("/view_session" , endpoint = view_session ),
@@ -180,7 +184,7 @@ def test_session_cookie(test_client_factory):
180
184
assert response .json () == {"session" : {}}
181
185
182
186
183
- def test_domain_cookie (test_client_factory ) :
187
+ def test_domain_cookie (test_client_factory : TestClientFactory ) -> None :
184
188
app = Starlette (
185
189
routes = [
186
190
Route ("/view_session" , endpoint = view_session ),
0 commit comments