mirror of https://github.com/tiangolo/fastapi.git
Add tests for class (not instance) dependency
This commit is contained in:
parent
62ae08d4a3
commit
e430ff352a
|
|
@ -48,6 +48,34 @@ async_callable_gen_dependency = AsyncCallableGenDependency()
|
||||||
methods_dependency = MethodsDependency()
|
methods_dependency = MethodsDependency()
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/callable-dependency-class")
|
||||||
|
async def get_callable_dependency_class(
|
||||||
|
value: str, instance: CallableDependency = Depends()
|
||||||
|
):
|
||||||
|
return instance(value)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/callable-gen-dependency-class")
|
||||||
|
async def get_callable_gen_dependency_class(
|
||||||
|
value: str, instance: CallableGenDependency = Depends()
|
||||||
|
):
|
||||||
|
return next(instance(value))
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/async-callable-dependency-class")
|
||||||
|
async def get_async_callable_dependency_class(
|
||||||
|
value: str, instance: AsyncCallableDependency = Depends()
|
||||||
|
):
|
||||||
|
return await instance(value)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/async-callable-gen-dependency-class")
|
||||||
|
async def get_async_callable_gen_dependency_class(
|
||||||
|
value: str, instance: AsyncCallableGenDependency = Depends()
|
||||||
|
):
|
||||||
|
return await instance(value).__anext__()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/callable-dependency")
|
@app.get("/callable-dependency")
|
||||||
async def get_callable_dependency(value: str = Depends(callable_dependency)):
|
async def get_callable_dependency(value: str = Depends(callable_dependency)):
|
||||||
return value
|
return value
|
||||||
|
|
@ -114,6 +142,10 @@ client = TestClient(app)
|
||||||
("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"),
|
("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"),
|
||||||
("/asynchronous-method-dependency", "asynchronous-method-dependency"),
|
("/asynchronous-method-dependency", "asynchronous-method-dependency"),
|
||||||
("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"),
|
("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"),
|
||||||
|
("/callable-dependency-class", "callable-dependency-class"),
|
||||||
|
("/callable-gen-dependency-class", "callable-gen-dependency-class"),
|
||||||
|
("/async-callable-dependency-class", "async-callable-dependency-class"),
|
||||||
|
("/async-callable-gen-dependency-class", "async-callable-gen-dependency-class"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_class_dependency(route, value):
|
def test_class_dependency(route, value):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue