Skip to content

Commit 3f7e70d

Browse files
committed
refactor(router): 移除废弃的graph兼容性接口并合并测试
将废弃的lightrag兼容性接口从graph_router.py中移除 删除单独的test_graph_router.py测试文件 在test_unified_graph_router.py中添加相关测试
1 parent ac848ea commit 3f7e70d

File tree

3 files changed

+12
-74
lines changed

3 files changed

+12
-74
lines changed

server/routers/graph_router.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -209,51 +209,6 @@ async def get_graph_stats(
209209
raise HTTPException(status_code=500, detail=f"Failed to get stats: {str(e)}")
210210

211211

212-
# =============================================================================
213-
# === 兼容性接口 (Deprecated/Compatibility) ===
214-
# =============================================================================
215-
216-
217-
@graph.get("/lightrag/subgraph")
218-
async def get_lightrag_subgraph(
219-
db_id: str = Query(..., description="数据库ID"),
220-
node_label: str = Query(..., description="节点标签或实体名称"),
221-
max_depth: int = Query(2, description="最大深度", ge=1, le=5),
222-
max_nodes: int = Query(100, description="最大节点数", ge=1, le=1000),
223-
current_user: User = Depends(get_admin_user),
224-
):
225-
"""(Deprecated) Use /graph/subgraph instead"""
226-
return await get_subgraph(
227-
db_id=db_id, node_label=node_label, max_depth=max_depth, max_nodes=max_nodes, current_user=current_user
228-
)
229-
230-
231-
@graph.get("/lightrag/databases")
232-
async def get_lightrag_databases(current_user: User = Depends(get_admin_user)):
233-
"""(Deprecated) Use /graph/list instead"""
234-
try:
235-
lightrag_databases = knowledge_base.get_lightrag_databases()
236-
return {"success": True, "data": {"databases": lightrag_databases}}
237-
except Exception as e:
238-
raise HTTPException(status_code=500, detail=str(e))
239-
240-
241-
@graph.get("/lightrag/labels")
242-
async def get_lightrag_labels(
243-
db_id: str = Query(..., description="数据库ID"), current_user: User = Depends(get_admin_user)
244-
):
245-
"""(Deprecated) Use /graph/labels instead"""
246-
return await get_graph_labels(db_id=db_id, current_user=current_user)
247-
248-
249-
@graph.get("/lightrag/stats")
250-
async def get_lightrag_stats(
251-
db_id: str = Query(..., description="数据库ID"), current_user: User = Depends(get_admin_user)
252-
):
253-
"""(Deprecated) Use /graph/stats instead"""
254-
return await get_graph_stats(db_id=db_id, current_user=current_user)
255-
256-
257212
@graph.get("/neo4j/nodes")
258213
async def get_neo4j_nodes(
259214
kgdb_name: str = Query(..., description="知识图谱数据库名称"),

test/api/test_graph_router.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

test/api/test_unified_graph_router.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
1010

1111

12+
async def test_graph_routes_require_auth(test_client):
13+
"""Test that graph endpoints require authentication."""
14+
response = await test_client.get("/api/graph/list")
15+
assert response.status_code == 401
16+
17+
18+
async def test_standard_user_cannot_access_graph_endpoints(test_client, standard_user):
19+
"""Test that standard users cannot access graph endpoints."""
20+
response = await test_client.get("/api/graph/list", headers=standard_user["headers"])
21+
assert response.status_code == 403
22+
23+
1224
async def test_get_graphs_list(test_client, admin_headers):
1325
"""Test retrieving the list of all graphs."""
1426
response = await test_client.get("/api/graph/list", headers=admin_headers)

0 commit comments

Comments
 (0)