mirror of
https://github.com/TencentCloud/Octop.git
synced 2026-09-28 19:33:02 +08:00
Separate instance KB toggle from page CRUD with knowledge_settings, probe embedding endpoints correctly, and polish ONNX download/settings UX. Co-authored-by: Cursor <cursoragent@cursor.com>
93 lines
2.7 KiB
Python
93 lines
2.7 KiB
Python
"""tests/integration/test_providers_api.py"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
async def test_list_providers(env):
|
|
"""GET /providers returns all providers (read-only endpoint for any user)."""
|
|
c, _, auth = env
|
|
r = await c.post(
|
|
"/api/admin/providers",
|
|
headers=auth,
|
|
json={"name": "openai", "kind": "openai", "api_key": "k"},
|
|
)
|
|
assert r.status_code == 201
|
|
|
|
r = await c.get("/api/providers", headers=auth)
|
|
assert r.status_code == 200
|
|
assert any(p["name"] == "openai" for p in r.json())
|
|
|
|
|
|
async def test_admin_creates_provider(env):
|
|
"""POST /admin/providers creates a provider."""
|
|
c, _, auth = env
|
|
r = await c.post(
|
|
"/api/admin/providers",
|
|
headers=auth,
|
|
json={"name": "openai", "kind": "openai", "api_key": "k"},
|
|
)
|
|
assert r.status_code == 201
|
|
body = r.json()
|
|
assert body["name"] == "openai"
|
|
assert "user_id" not in body
|
|
|
|
|
|
async def test_regular_user_cannot_create_provider(env):
|
|
"""POST /admin/providers is admin-only."""
|
|
c, _, admin_auth = env
|
|
await c.post(
|
|
"/api/users",
|
|
headers=admin_auth,
|
|
json={"username": "regular", "password": "TestPass12", "role": "user"},
|
|
)
|
|
tok = (
|
|
await c.post("/api/auth/login", json={"username": "regular", "password": "TestPass12"})
|
|
).json()["access_token"]
|
|
user_auth = {"Authorization": f"Bearer {tok}"}
|
|
|
|
r = await c.post(
|
|
"/api/admin/providers",
|
|
headers=user_auth,
|
|
json={"name": "should-fail", "kind": "openai"},
|
|
)
|
|
assert r.status_code == 403
|
|
|
|
|
|
async def test_admin_delete_provider(env):
|
|
"""DELETE /admin/providers/{id} removes the provider."""
|
|
c, _, auth = env
|
|
r = await c.post(
|
|
"/api/admin/providers",
|
|
headers=auth,
|
|
json={"name": "to-delete", "kind": "openai"},
|
|
)
|
|
assert r.status_code == 201
|
|
pid = r.json()["id"]
|
|
|
|
r = await c.delete(f"/api/admin/providers/{pid}", headers=auth)
|
|
assert r.status_code in (200, 204)
|
|
|
|
r = await c.get("/api/admin/providers", headers=auth)
|
|
ids = [p["id"] for p in r.json()]
|
|
assert pid not in ids
|
|
|
|
|
|
async def test_admin_cannot_delete_local_runtime_provider(env):
|
|
"""DELETE /admin/providers/{id} keeps ONNX / Ollama local rows."""
|
|
c, _, auth = env
|
|
r = await c.post(
|
|
"/api/admin/providers",
|
|
headers=auth,
|
|
json={"name": "ONNX (Local)", "kind": "openai", "api_key": "onnx"},
|
|
)
|
|
assert r.status_code == 201
|
|
pid = r.json()["id"]
|
|
|
|
r = await c.delete(f"/api/admin/providers/{pid}", headers=auth)
|
|
assert r.status_code == 409
|
|
assert r.json()["error"]["code"] == "PROVIDER_LOCAL_PROTECTED"
|
|
|
|
r = await c.get("/api/admin/providers", headers=auth)
|
|
ids = [p["id"] for p in r.json()]
|
|
assert pid in ids
|