import warnings
import pytest
from fastapi import APIRouter, Depends, FastAPI, Response
from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient
class ResponseLevel0(JSONResponse):
media_type = "application/x-level-0"
class ResponseLevel1(JSONResponse):
media_type = "application/x-level-1"
class ResponseLevel2(JSONResponse):
media_type = "application/x-level-2"
class ResponseLevel3(JSONResponse):
media_type = "application/x-level-3"
class ResponseLevel4(JSONResponse):
media_type = "application/x-level-4"
class ResponseLevel5(JSONResponse):
media_type = "application/x-level-5"
async def dep0(response: Response):
response.headers["x-level0"] = "True"
async def dep1(response: Response):
response.headers["x-level1"] = "True"
async def dep2(response: Response):
response.headers["x-level2"] = "True"
async def dep3(response: Response):
response.headers["x-level3"] = "True"
async def dep4(response: Response):
response.headers["x-level4"] = "True"
async def dep5(response: Response):
response.headers["x-level5"] = "True"
callback_router0 = APIRouter()
@callback_router0.get("/")
async def callback0(level0: str):
pass # pragma: nocover
callback_router1 = APIRouter()
@callback_router1.get("/")
async def callback1(level1: str):
pass # pragma: nocover
callback_router2 = APIRouter()
@callback_router2.get("/")
async def callback2(level2: str):
pass # pragma: nocover
callback_router3 = APIRouter()
@callback_router3.get("/")
async def callback3(level3: str):
pass # pragma: nocover
callback_router4 = APIRouter()
@callback_router4.get("/")
async def callback4(level4: str):
pass # pragma: nocover
callback_router5 = APIRouter()
@callback_router5.get("/")
async def callback5(level5: str):
pass # pragma: nocover
app = FastAPI(
dependencies=[Depends(dep0)],
responses={
400: {"description": "Client error level 0"},
500: {"description": "Server error level 0"},
},
default_response_class=ResponseLevel0,
callbacks=callback_router0.routes,
)
router2_override = APIRouter(
prefix="/level2",
tags=["level2a", "level2b"],
dependencies=[Depends(dep2)],
responses={
402: {"description": "Client error level 2"},
502: {"description": "Server error level 2"},
},
default_response_class=ResponseLevel2,
callbacks=callback_router2.routes,
deprecated=True,
)
router2_default = APIRouter()
router4_override = APIRouter(
prefix="/level4",
tags=["level4a", "level4b"],
dependencies=[Depends(dep4)],
responses={
404: {"description": "Client error level 4"},
504: {"description": "Server error level 4"},
},
default_response_class=ResponseLevel4,
callbacks=callback_router4.routes,
deprecated=True,
)
router4_default = APIRouter()
@app.get(
"/override1",
tags=["path1a", "path1b"],
responses={
401: {"description": "Client error level 1"},
501: {"description": "Server error level 1"},
},
deprecated=True,
callbacks=callback_router1.routes,
dependencies=[Depends(dep1)],
response_class=ResponseLevel1,
)
async def path1_override(level1: str):
return level1
@app.get("/default1")
async def path1_default(level1: str):
return level1
@router2_override.get(
"/override3",
tags=["path3a", "path3b"],
responses={
403: {"description": "Client error level 3"},
503: {"description": "Server error level 3"},
},
deprecated=True,
callbacks=callback_router3.routes,
dependencies=[Depends(dep3)],
response_class=ResponseLevel3,
)
async def path3_override_router2_override(level3: str):
return level3
@router2_override.get("/default3")
async def path3_default_router2_override(level3: str):
return level3
@router2_default.get(
"/override3",
tags=["path3a", "path3b"],
responses={
403: {"description": "Client error level 3"},
503: {"description": "Server error level 3"},
},
deprecated=True,
callbacks=callback_router3.routes,
dependencies=[Depends(dep3)],
response_class=ResponseLevel3,
)
async def path3_override_router2_default(level3: str):
return level3
@router2_default.get("/default3")
async def path3_default_router2_default(level3: str):
return level3
@router4_override.get(
"/override5",
tags=["path5a", "path5b"],
responses={
405: {"description": "Client error level 5"},
505: {"description": "Server error level 5"},
},
deprecated=True,
callbacks=callback_router5.routes,
dependencies=[Depends(dep5)],
response_class=ResponseLevel5,
)
async def path5_override_router4_override(level5: str):
return level5
@router4_override.get(
"/default5",
)
async def path5_default_router4_override(level5: str):
return level5
@router4_default.get(
"/override5",
tags=["path5a", "path5b"],
responses={
405: {"description": "Client error level 5"},
505: {"description": "Server error level 5"},
},
deprecated=True,
callbacks=callback_router5.routes,
dependencies=[Depends(dep5)],
response_class=ResponseLevel5,
)
async def path5_override_router4_default(level5: str):
return level5
@router4_default.get(
"/default5",
)
async def path5_default_router4_default(level5: str):
return level5
router2_override.include_router(
router4_override,
prefix="/level3",
tags=["level3a", "level3b"],
dependencies=[Depends(dep3)],
responses={
403: {"description": "Client error level 3"},
503: {"description": "Server error level 3"},
},
default_response_class=ResponseLevel3,
callbacks=callback_router3.routes,
)
router2_override.include_router(
router4_default,
prefix="/level3",
tags=["level3a", "level3b"],
dependencies=[Depends(dep3)],
responses={
403: {"description": "Client error level 3"},
503: {"description": "Server error level 3"},
},
default_response_class=ResponseLevel3,
callbacks=callback_router3.routes,
)
router2_override.include_router(router4_override)
router2_override.include_router(router4_default)
router2_default.include_router(
router4_override,
prefix="/level3",
tags=["level3a", "level3b"],
dependencies=[Depends(dep3)],
responses={
403: {"description": "Client error level 3"},
503: {"description": "Server error level 3"},
},
default_response_class=ResponseLevel3,
callbacks=callback_router3.routes,
)
router2_default.include_router(
router4_default,
prefix="/level3",
tags=["level3a", "level3b"],
dependencies=[Depends(dep3)],
responses={
403: {"description": "Client error level 3"},
503: {"description": "Server error level 3"},
},
default_response_class=ResponseLevel3,
callbacks=callback_router3.routes,
)
router2_default.include_router(router4_override)
router2_default.include_router(router4_default)
app.include_router(
router2_override,
prefix="/level1",
tags=["level1a", "level1b"],
dependencies=[Depends(dep1)],
responses={
401: {"description": "Client error level 1"},
501: {"description": "Server error level 1"},
},
default_response_class=ResponseLevel1,
callbacks=callback_router1.routes,
)
app.include_router(
router2_default,
prefix="/level1",
tags=["level1a", "level1b"],
dependencies=[Depends(dep1)],
responses={
401: {"description": "Client error level 1"},
501: {"description": "Server error level 1"},
},
default_response_class=ResponseLevel1,
callbacks=callback_router1.routes,
)
app.include_router(router2_override)
app.include_router(router2_default)
client = TestClient(app)
def test_level1_override():
response = client.get("/override1?level1=foo")
assert response.json() == "fo
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本项目是一款基于Python和FastAPI框架,与MongoDB数据库深度集成的快速开发设计源码。项目包含2271个文件,涵盖1158个Python源代码文件、815个Markdown文档、154个PNG图片、52个YAML配置文件、47个SVG图像、11个Draw.io图表、7个文本文件、4个Shell脚本、3个CSS样式文件、3个JPEG图片文件,旨在提供高效的数据交互和API服务。该系统适用于需要快速构建和部署的Web应用程序,特别适合于数据密集型应用开发。
资源推荐
资源详情
资源评论
收起资源包目录
基于Python的FastAPI与MongoDB集成的快速开发设计源码 (2000个子文件)
custom.css 3KB
termynal.css 2KB
styles.css 25B
main.html 6KB
copyright.html 450B
item.html 235B
termynal.js 9KB
custom.js 7KB
tutorial004.js 1KB
release-notes.md 398KB
docker.md 58KB
docker.md 44KB
docker.md 43KB
async.md 40KB
alternatives.md 39KB
docker.md 39KB
query-params-str-validations.md 38KB
docker.md 37KB
python-types.md 36KB
docker.md 34KB
concepts.md 32KB
alternatives.md 32KB
docker.md 31KB
response-model.md 31KB
index.md 30KB
sql-databases.md 30KB
alternatives.md 29KB
docker.md 28KB
async.md 28KB
query-params-str-validations.md 28KB
alternatives.md 27KB
sql-databases.md 27KB
async.md 27KB
alternatives.md 27KB
async.md 27KB
index.md 26KB
index.md 26KB
query-params-str-validations.md 26KB
alternatives.md 26KB
async.md 25KB
sql-databases.md 25KB
concepts.md 24KB
index.md 24KB
sql-databases-peewee.md 24KB
alternatives.md 23KB
async.md 23KB
oauth2-scopes.md 23KB
contributing.md 23KB
help-fastapi.md 22KB
async.md 22KB
index.md 22KB
index.md 22KB
async.md 22KB
index.md 22KB
python-types.md 22KB
index.md 21KB
index.md 21KB
bigger-applications.md 21KB
async.md 21KB
index.md 21KB
concepts.md 21KB
https.md 21KB
oauth2-scopes.md 20KB
index.md 20KB
response-model.md 20KB
index.md 20KB
dependencies-with-yield.md 20KB
index.md 19KB
index.md 19KB
python-types.md 19KB
index.md 19KB
sql-databases-peewee.md 19KB
index.md 19KB
alternatives.md 19KB
async.md 19KB
index.md 19KB
bigger-applications.md 19KB
bigger-applications.md 19KB
index.md 18KB
concepts.md 18KB
response-model.md 18KB
settings.md 18KB
index.md 18KB
index.md 17KB
python-types.md 17KB
settings.md 17KB
deployment.md 17KB
contributing.md 17KB
contributing.md 16KB
features.md 16KB
classes-as-dependencies.md 16KB
concepts.md 16KB
contributing.md 16KB
help-fastapi.md 16KB
response-model.md 16KB
settings.md 16KB
bigger-applications.md 16KB
first-steps.md 15KB
request-files.md 15KB
https.md 15KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
csbysj2020
- 粉丝: 2752
- 资源: 5576
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于智慧云校园管理系统全部资料+高分项目+详细文档.zip
- 基于智慧自助餐饮系统-图像识别全部资料+高分项目+详细文档.zip
- 彩虹-DNS管理系统源码V2.0.1,SSL证书自动申请与部署.zip
- 7寸液晶屏覆膜机(含工程图bom单)sw16全套技术开发资料100%好用.zip
- AI程序源码最新,支持多个国家语言.zip
- 0.64四方针插针打弯机(sw12可编辑+cad)全套技术开发资料100%好用.zip
- 600离心清洗机sw13可编辑全套技术开发资料100%好用.zip
- 基于 Linux 的智能家居系统全部资料+详细文档+优秀项目.zip
- 基于 Yunzai 的小米智能家居控制插件全部资料+详细文档+优秀项目.zip
- 基于android的智能语音家居控制系统 安卓端1.0全部资料+详细文档+优秀项目.zip
- 基于C#的智能家居控制系统通信协议的实现全部资料+详细文档+优秀项目.zip
- 基于LLM Agent的全能管家,通过语音或文字交互,调用工具控制智能家居(HA米家)和电脑。超高拓展性,无限可能。全部资料+详细文档+优秀项目.zip
- 基于ESP32-S3的小键盘,具有时间显示、实时天气、天气预报、实时股票、快捷键、蓝牙键盘、倒计时、快捷访问网站、米家智能家居控制等功能。全部资料+详细文档+优秀项目.zip
- 基于QML智能家居UI全部资料+详细文档+优秀项目.zip
- 基于python实现智能家居物联网服务平台全部资料+详细文档+优秀项目.zip
- 基于STC89C52的智能家居系统全部资料+详细文档+优秀项目.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功