/ tests / test_tools.py
test_tools.py
 1  import pytest
 2  from fastapi.testclient import TestClient
 3  
 4  from restai.config import RESTAI_DEFAULT_PASSWORD
 5  from restai.main import app
 6  
 7  
 8  @pytest.fixture(scope="module")
 9  def client():
10      with TestClient(app) as c:
11          yield c
12  
13  
14  def test_get_agent_tools(client):
15      response = client.get("/tools/agent", auth=("admin", RESTAI_DEFAULT_PASSWORD))
16      assert response.status_code == 200
17      data = response.json()
18      assert isinstance(data, list)
19      for tool in data:
20          assert "name" in tool
21          assert "description" in tool
22  
23  
24  def test_get_agent_tools_no_auth(client):
25      response = client.get("/tools/agent")
26      assert response.status_code == 401
27  
28  
29  def test_mcp_probe_invalid_host(client):
30      response = client.post(
31          "/tools/mcp/probe",
32          json={"host": "http://localhost:99999"},
33          auth=("admin", RESTAI_DEFAULT_PASSWORD),
34      )
35      # Should fail to connect — 502 or 500
36      assert response.status_code in (500, 502)
37  
38  
39  def test_mcp_probe_no_auth(client):
40      response = client.post(
41          "/tools/mcp/probe",
42          json={"host": "http://localhost:99999"},
43      )
44      assert response.status_code == 401