Skip to content

Commit 3f672fb

Browse files
author
Super User
committed
#94; tests passed against fastapi 0.122
1 parent f8ddf3a commit 3f672fb

File tree

7 files changed

+24
-33
lines changed

7 files changed

+24
-33
lines changed

noxfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ def test(session: AlteredSession):
382382
@session(
383383
dependency_group=None,
384384
default_posargs=[TEST_DIR, "-s", "-vv", "-n", "auto", "--dist", "worksteal"],
385+
reuse_venv=False,
385386
)
386387
@nox.parametrize("fastapi_version", FASTAPI_MINOR_MATRIX)
387388
def test_compat_fastapi(session: AlteredSession, fastapi_version: str):
@@ -391,6 +392,8 @@ def test_compat_fastapi(session: AlteredSession, fastapi_version: str):
391392
PyPI's latest release, selecting the highest patch per minor.
392393
"""
393394
session.log(f"Testing compatibility with FastAPI versions: {FASTAPI_MINOR_MATRIX}")
395+
with alter_session(session, dependency_group=None) as session:
396+
build(session)
394397
# Pin FastAPI (and extras) to the target minor's highest patch before running tests.
395398
# Install dev dependencies excluding FastAPI to avoid overriding the pinned version.
396399
pyproject = load_toml(MANIFEST_FILENAME)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ classifiers = [
4545
]
4646
requires-python = ">=3.9"
4747
dependencies = [
48-
"fastapi>=0.100.1",
48+
"fastapi>=0.115.2",
4949
"typing-extensions>=4.0.0; python_version<'3.10'",
5050
]
5151
dynamic = []
@@ -116,7 +116,7 @@ reportMissingImports = "none"
116116
[dependency-groups]
117117
dev = [
118118
"bcrypt==4.3.0",
119-
"fastapi[standard]>=0.100.1",
119+
"fastapi>=0.115.2",
120120
"httpx>=0.24.0",
121121
"isort>=6.0.1",
122122
"mypy>=1.18.2",

src/fastapi_shield/shield.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737

3838
from fastapi import HTTPException, Request, Response, status
3939
from fastapi._compat import _normalize_errors
40-
from fastapi.dependencies.utils import is_coroutine_callable
4140
from fastapi.exceptions import RequestValidationError
4241
from fastapi.params import Security
4342
from typing_extensions import Doc
4443

4544
# Import directly to make patching work correctly in tests
4645
import fastapi_shield.utils
46+
from fastapi_shield.utils import is_coroutine_callable
4747
from fastapi_shield.consts import (
4848
IS_SHIELDED_ENDPOINT_KEY,
4949
SHIELDED_ENDPOINT_PATH_FORMAT_KEY,

src/fastapi_shield/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from collections.abc import Iterator
1212
from contextlib import AsyncExitStack
1313
from inspect import Parameter, signature
14+
import inspect
1415
from typing import Any, Callable, Optional, List, Union
1516

1617
from fastapi import HTTPException, Request, params
@@ -29,6 +30,17 @@
2930
from starlette.routing import get_name
3031

3132

33+
# copied from `fastapi.dependencies.utils`
34+
def is_coroutine_callable(call: Callable[..., Any]) -> bool:
35+
if inspect.isroutine(call):
36+
return inspect.iscoroutinefunction(call)
37+
if inspect.isclass(call):
38+
return False
39+
dunder_call = getattr(call, "__call__", None) # noqa: B004
40+
return inspect.iscoroutinefunction(dunder_call)
41+
42+
43+
# copied from `fastapi.dependencies.utils`
3244
def _should_embed_body_fields(fields: List["ModelField"]) -> bool:
3345
if not fields:
3446
return False

tests/test_basics.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,8 @@ def test_unprotected_endpoint():
218218
client = TestClient(app)
219219
response = client.get("/unprotected")
220220
assert response.status_code == 200
221-
assert response.json() == {
222-
"message": "This is an unprotected endpoint",
223-
"user": {
224-
"dependency": {},
225-
"use_cache": True,
226-
"scopes": [],
227-
"shielded_dependency": {},
228-
"unblocked": False,
229-
},
230-
}, response.json()
221+
result_json = response.json()
222+
assert result_json["message"] == "This is an unprotected endpoint", response.json()
231223

232224

233225
def test_protected_endpoint_without_token():

tests/test_basics_three.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,8 @@ def test_unprotected_endpoint():
300300
client = TestClient(app)
301301
response = client.get("/unprotected")
302302
assert response.status_code == 200
303-
assert response.json() == {
304-
"message": "This is an unprotected endpoint",
305-
"user": {
306-
"dependency": {},
307-
"use_cache": True,
308-
"scopes": [],
309-
"shielded_dependency": {},
310-
"unblocked": False,
311-
},
312-
}, response.json()
303+
result_json = response.json()
304+
assert result_json["message"] == "This is an unprotected endpoint", response.json()
313305

314306

315307
def test_protected_endpoint_without_token():

tests/test_basics_two.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,8 @@ def test_unprotected_endpoint():
300300
client = TestClient(app)
301301
response = client.get("/unprotected")
302302
assert response.status_code == 200
303-
assert response.json() == {
304-
"message": "This is an unprotected endpoint",
305-
"user": {
306-
"dependency": {},
307-
"use_cache": True,
308-
"scopes": [],
309-
"shielded_dependency": {},
310-
"unblocked": False,
311-
},
312-
}, response.json()
303+
result_json = response.json()
304+
assert result_json["message"] == "This is an unprotected endpoint", response.json()
313305

314306

315307
def test_protected_endpoint_without_token():

0 commit comments

Comments
 (0)