feat: python

This commit is contained in:
heyong.fu
2026-05-06 11:21:42 +08:00
commit 0abf1ad3c4
62 changed files with 7598 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
# 导入FastAPI的TestClient,用于测试FastAPI
# from fastapi.testclient import TestClient
# # 从main模块导入app对象
# from main import app
# # 创建TestClient实例,传入FastAPI应用
# client = TestClient(app)
# def test_read_root():
# # 使用客户端发起请求
# response = client.get("/")
# # 断言返回200状态码,表示请求成功
# assert response.status_code == 200
# # 断言返回的json数据
# assert response.json() == {"message": "Hello World"}
# 导入FastAPI的TestClient,用于测试FastAPI应用
from fastapi.testclient import TestClient
# 从main模块导入app对象(FastAPI实例)
from main import app
# 创建TestClient实例,传入FastAPI应用
client = TestClient(app)
# 定义测试根路径的函数
def test_read_root():
# 使用测试客户端发起GET请求到根路径
response = client.get("/")
# 断言返回状态码为200,表示请求成功
assert response.status_code == 200
# 断言返回的JSON数据为{"message": "Hello World"}
assert response.json() == {"message": "Hello World"}