mirror of https://github.com/tiangolo/fastapi.git
Remove code examples for Python 3.8 in `dependency_testing`
This commit is contained in:
parent
1aa9bc0792
commit
0eb7661fe8
|
|
@ -1,60 +0,0 @@
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import Depends, FastAPI
|
|
||||||
from fastapi.testclient import TestClient
|
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
async def common_parameters(
|
|
||||||
q: Union[str, None] = None, skip: int = 0, limit: int = 100
|
|
||||||
):
|
|
||||||
return {"q": q, "skip": skip, "limit": limit}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/items/")
|
|
||||||
async def read_items(commons: Annotated[dict, Depends(common_parameters)]):
|
|
||||||
return {"message": "Hello Items!", "params": commons}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/users/")
|
|
||||||
async def read_users(commons: Annotated[dict, Depends(common_parameters)]):
|
|
||||||
return {"message": "Hello Users!", "params": commons}
|
|
||||||
|
|
||||||
|
|
||||||
client = TestClient(app)
|
|
||||||
|
|
||||||
|
|
||||||
async def override_dependency(q: Union[str, None] = None):
|
|
||||||
return {"q": q, "skip": 5, "limit": 10}
|
|
||||||
|
|
||||||
|
|
||||||
app.dependency_overrides[common_parameters] = override_dependency
|
|
||||||
|
|
||||||
|
|
||||||
def test_override_in_items():
|
|
||||||
response = client.get("/items/")
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json() == {
|
|
||||||
"message": "Hello Items!",
|
|
||||||
"params": {"q": None, "skip": 5, "limit": 10},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test_override_in_items_with_q():
|
|
||||||
response = client.get("/items/?q=foo")
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json() == {
|
|
||||||
"message": "Hello Items!",
|
|
||||||
"params": {"q": "foo", "skip": 5, "limit": 10},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test_override_in_items_with_params():
|
|
||||||
response = client.get("/items/?q=foo&skip=100&limit=200")
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json() == {
|
|
||||||
"message": "Hello Items!",
|
|
||||||
"params": {"q": "foo", "skip": 5, "limit": 10},
|
|
||||||
}
|
|
||||||
|
|
@ -3,16 +3,15 @@ from types import ModuleType
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ...utils import needs_py39, needs_py310
|
from ...utils import needs_py310
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
name="test_module",
|
name="test_module",
|
||||||
params=[
|
params=[
|
||||||
"tutorial001",
|
pytest.param("tutorial001_py39"),
|
||||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||||
"tutorial001_an",
|
pytest.param("tutorial001_an_py39"),
|
||||||
pytest.param("tutorial001_an_py39", marks=needs_py39),
|
|
||||||
pytest.param("tutorial001_an_py310", marks=needs_py310),
|
pytest.param("tutorial001_an_py310", marks=needs_py310),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue