first
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from .conftest import build_sample_app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
app, _ = build_sample_app(expose_http_endpoints=True, add_composite=True)
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_http_list_tools(client):
|
||||
res = client.get("/apipilot/tools")
|
||||
assert res.status_code == 200
|
||||
names = {t["name"] for t in res.json()}
|
||||
assert "list_items" in names
|
||||
assert "get_item" in names
|
||||
assert "create_item" in names
|
||||
assert "find_cheapest_item" in names
|
||||
|
||||
|
||||
def test_http_execute_success(client):
|
||||
res = client.post(
|
||||
"/apipilot/execute",
|
||||
json={"name": "list_items", "arguments": {"category": "active"}},
|
||||
)
|
||||
assert res.status_code == 200
|
||||
body = res.json()
|
||||
assert body["success"] is True
|
||||
assert body["data"]["total"] == 2
|
||||
|
||||
|
||||
def test_http_execute_tool_not_found_via_unknown_tool(client):
|
||||
res = client.post(
|
||||
"/apipilot/execute",
|
||||
json={"name": "does_not_exist", "arguments": {}},
|
||||
)
|
||||
assert res.status_code == 500
|
||||
|
||||
|
||||
def test_http_execute_invalid_args(client):
|
||||
res = client.post(
|
||||
"/apipilot/execute",
|
||||
json={"name": "get_item", "arguments": {"item_id": "not-a-number"}},
|
||||
)
|
||||
assert res.status_code == 422
|
||||
body = res.json()
|
||||
assert body["success"] is False
|
||||
assert body["error"]["code"] == "INVALID_ARGUMENTS"
|
||||
Reference in New Issue
Block a user