feat: add /api/llm-profiles CRUD router
This commit is contained in:
67
tests/webapp/test_llm_profiles_api.py
Normal file
67
tests/webapp/test_llm_profiles_api.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""Integration tests for /api/llm-profiles endpoints."""
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(tmp_path, monkeypatch):
|
||||
"""TestClient with a fresh ProfileManager backed by a temp file."""
|
||||
store = tmp_path / "profiles.json"
|
||||
import webapp.services.profile_manager as pm_mod
|
||||
from webapp.services.profile_manager import ProfileManager
|
||||
fresh_mgr = ProfileManager(store_path=store)
|
||||
monkeypatch.setattr(pm_mod, "profile_manager", fresh_mgr)
|
||||
import webapp.api.llm_profiles as api_mod
|
||||
monkeypatch.setattr(api_mod, "profile_manager", fresh_mgr)
|
||||
|
||||
from webapp.server import create_app
|
||||
return TestClient(create_app())
|
||||
|
||||
|
||||
def test_list_empty(client):
|
||||
resp = client.get("/api/llm-profiles")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["profiles"] == []
|
||||
|
||||
|
||||
def test_create_and_list(client):
|
||||
body = {"name": "Test", "model": "m1", "base_url": "http://x/v1", "api_key": "k"}
|
||||
resp = client.post("/api/llm-profiles", json=body)
|
||||
assert resp.status_code == 201
|
||||
data = resp.json()
|
||||
assert data["name"] == "Test"
|
||||
assert data["profile_id"] != ""
|
||||
|
||||
resp2 = client.get("/api/llm-profiles")
|
||||
assert len(resp2.json()["profiles"]) == 1
|
||||
|
||||
|
||||
def test_update_profile(client):
|
||||
body = {"name": "Old", "model": "m1", "base_url": "http://x/v1", "api_key": "k"}
|
||||
pid = client.post("/api/llm-profiles", json=body).json()["profile_id"]
|
||||
|
||||
upd = {"name": "New", "model": "m2", "base_url": "http://x/v1", "api_key": "k", "timeout_seconds": 60}
|
||||
resp = client.put(f"/api/llm-profiles/{pid}", json=upd)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["name"] == "New"
|
||||
assert resp.json()["timeout_seconds"] == 60
|
||||
|
||||
|
||||
def test_delete_profile(client):
|
||||
body = {"name": "Del", "model": "m", "base_url": "http://x/v1", "api_key": "k"}
|
||||
pid = client.post("/api/llm-profiles", json=body).json()["profile_id"]
|
||||
resp = client.delete(f"/api/llm-profiles/{pid}")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["deleted"] is True
|
||||
assert len(client.get("/api/llm-profiles").json()["profiles"]) == 0
|
||||
|
||||
|
||||
def test_update_nonexistent(client):
|
||||
resp = client.put("/api/llm-profiles/nope",
|
||||
json={"name": "X", "model": "m", "base_url": "http://x/v1", "api_key": "k"})
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
def test_delete_nonexistent(client):
|
||||
resp = client.delete("/api/llm-profiles/nope")
|
||||
assert resp.status_code == 404
|
||||
Reference in New Issue
Block a user