8000 Update starlette to 0.21.0. · fastapi/fastapi@54ca46f · GitHub
[go: up one dir, main page]

Skip to content

Commit 54ca46f

Browse files
author
Paweł Rubin
committed
Update starlette to 0.21.0.
- Adapt tests suite after breaking changes to the starlette's TestClient - Fix issues found by mypy caused by more precise type annotations in starlette
1 parent c6aa28b commit 54ca46f

26 files changed

+79
-71
lines changed

fastapi/security/api_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
self.auto_error = auto_error
5555

5656
async def __call__(self, request: Request) -> Optional[str]:
57-
api_key: str = request.headers.get(self.model.name)
57+
api_key = request.headers.get(self.model.name)
5858
if not api_key:
5959
if self.auto_error:
6060
raise HTTPException(

fastapi/security/http.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(
3838
async def __call__(
3939
self, request: Request
4040
) -> Optional[HTTPAuthorizationCredentials]:
41-
authorization: str = request.headers.get("Authorization")
41+
authorization = request.headers.get("Authorization")
4242
scheme, credentials = get_authorization_scheme_param(authorization)
4343
if not (authorization and scheme and credentials):
4444
if self.auto_error:
@@ -67,7 +67,7 @@ def __init__(
6767
async def __call__( # type: ignore
6868
self, request: Request
6969
) -> Optional[HTTPBasicCredentials]:
70-
authorization: str = request.headers.get("Authorization")
70+
authorization = request.headers.get("Authorization")
7171
scheme, param = get_authorization_scheme_param(authorization)
7272
if self.realm:
7373
unauthorized_headers = {"WWW-Authenticate": f' 6DB6 Basic realm="{self.realm}"'}
@@ -113,7 +113,7 @@ def __init__(
113113
async def __call__(
114114
self, request: Request
115115
) -> Optional[HTTPAuthorizationCredentials]:
116-
authorization: str = request.headers.get("Authorization")
116+
authorization = request.headers.get("Authorization")
117117
scheme, credentials = get_authorization_scheme_param(authorization)
118118
if not (authorization and scheme and credentials):
119119
if self.auto_error:
@@ -148,7 +148,7 @@ def __init__(
148148
async def __call__(
149149
self, request: Request
150150
) -> Optional[HTTPAuthorizationCredentials]:
151-
authorization: str = request.headers.get("Authorization")
151+
authorization = request.headers.get("Authorization")
152152
scheme, credentials = get_authorization_scheme_param(authorization)
153153
if not (authorization and scheme and credentials):
154154< 9E0A /code>
if self.auto_error:

fastapi/security/oauth2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __init__(
126126
self.auto_error = auto_error
127127

128128
async def __call__(self, request: Request) -> Optional[str]:
129-
authorization: str = request.headers.get("Authorization")
129+
authorization = request.headers.get("Authorization")
130130
if not authorization:
131131
if self.auto_error:
132132
raise HTTPException(
@@ -157,7 +157,7 @@ def __init__(
157157
)
158158

159159
async def __call__(self, request: Request) -> Optional[str]:
160-
authorization: str = request.headers.get("Authorization")
160+
authorization = request.headers.get("Authorization")
161161
scheme, param = get_authorization_scheme_param(authorization)
162162
if not authorization or scheme.lower() != "bearer":
163163
if self.auto_error:
@@ -200,7 +200,7 @@ def __init__(
200200
)
201201

202202
async def __call__(self, request: Request) -> Optional[str]:
203-
authorization: str = request.headers.get("Authorization")
203+
authorization = request.headers.get("Authorization")
204204
scheme, param = get_authorization_scheme_param(authorization)
205205
if not authorization or scheme.lower() != "bearer":
206206
if self.auto_error:

fastapi/security/open_id_connect_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(
2323
self.auto_error = auto_error
2424

2525
async def __call__(self, request: Request) -> Optional[str]:
26-
authorization: str = request.headers.get("Authorization")
26+
authorization = request.headers.get("Authorization")
2727
if not authorization:
2828
if self.auto_error:
2929
raise HTTPException(

fastapi/security/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from typing import Tuple
1+
from typing import Optional, Tuple
22

33

4-
def get_authorization_scheme_param(authorization_header_value: str) -> Tuple[str, str]:
4+
def get_authorization_scheme_param(
5+
authorization_header_value: Optional[str],
6+
) -> Tuple[str, str]:
57
if not authorization_header_value:
68
return "", ""
79
scheme, _, param = authorization_header_value.partition(" ")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ classifiers = [
3838
"Topic :: Internet :: WWW/HTTP",
3939
]
4040
dependencies = [
41-
"starlette==0.20.4",
41+
"starlette==0.21.0",
4242
"pydantic >=1.6.2,!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0",
4343
]
4444
dynamic = ["version"]

tests/test_enforce_once_required_parameter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_schema():
101101

102102

103103
def test_get_invalid():
104-
response = client.get("/foo", params={"client_id": None})
104+
response = client.get("/foo")
105105
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
106106

107107

tests/test_extra_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def test_get_api_route_not_decorated():
333333

334334

335335
def test_delete():
336-
response = client.delete("/items/foo", json={"name": "Foo"})
336+
response = client.request("DELETE", "/items/foo", json={"name": "Foo"})
337337
assert response.status_code == 200, response.text
338338
assert response.json() == {"item_id": "foo", "item": {"name": "Foo", "price": None}}
339339

tests/test_get_request_body.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ def test_openapi_schema():
104104

105105
def test_get_with_body():
106106
body = {"name": "Foo", "description": "Some description", "price": 5.5}
107-
response = client.get("/product", json=body)
107+
response = client.request("GET", "/product", json=body)
108108
assert response.json() == body

tests/test_param_include_in_schema.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ async def hidden_query(
3333
return {"hidden_query": hidden_query}
3434

3535

36-
client = TestClient(app)
37-
3836
openapi_shema = {
3937
"openapi": "3.0.2",
4038
"info": {"title": "FastAPI", "version": "0.1.0"},
@@ -161,6 +159,7 @@ async def hidden_query(
161159

162160

163161
def test_openapi_schema():
162+
client = TestClient(app)
164163
response = client.get("/openapi.json")
165164
assert response.status_code == 200
166165
assert response.json() == openapi_shema
@@ -184,7 +183,8 @@ def test_openapi_schema():
184183
],
185184
)
186185
def test_hidden_cookie(path, cookies, expected_status, expected_response):
187-
response = client.get(path, cookies=cookies)
186+
client = TestClient(app, cookies=cookies)
187+
response = client.get(path)
188188
assert response.status_code == expected_status
189189
assert response.json() == expected_response
190190

@@ -207,12 +207,14 @@ def test_hidden_cookie(path, cookies, expected_status, expected_response):
207207
],
208208
)
209209
def test_hidden_header(path, headers, expected_status, expected_response):
210+
client = TestClient(app)
210211
response = client.get(path, headers=headers)
211212
assert response.status_code == expected_status
212213
assert response.json() == expected_response
213214

214215

215216
def test_hidden_path():
217+
client = TestClient(app)
216218
response = client.get("/hidden_path/hidden_path")
217219
assert response.status_code == 200
218220
assert response.json() == {"hidden_path": "hidden_path"}
@@ -234,6 +236,7 @@ def test_hidden_path():
234236
],
235237
)
236238
def test_hidden_query(path, expected_status, expected_response):
239+
client = TestClient(app)
237240
response = client.get(path)
238241
assert response.status_code == expected_status
239242
assert response.json() == expected_response

0 commit comments

Comments
 (0)
0