Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
cce00f1
1
Parent(s): 4805965
Add test
Browse files- tests/server/test_openapi.py +30 -1
tests/server/test_openapi.py
CHANGED
|
@@ -14,7 +14,12 @@ from pydantic.networks import AnyUrl
|
|
| 14 |
|
| 15 |
from fastmcp import FastMCP
|
| 16 |
from fastmcp.client import Client
|
| 17 |
-
from fastmcp.server.openapi import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
class User(BaseModel):
|
|
@@ -128,6 +133,30 @@ async def test_create_fastapi_server_classmethod(fastapi_app: FastAPI):
|
|
| 128 |
assert server.name == "FastAPI App"
|
| 129 |
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
class TestTools:
|
| 132 |
async def test_list_tools(self, fastmcp_openapi_server: FastMCPOpenAPI):
|
| 133 |
"""
|
|
|
|
| 14 |
|
| 15 |
from fastmcp import FastMCP
|
| 16 |
from fastmcp.client import Client
|
| 17 |
+
from fastmcp.server.openapi import (
|
| 18 |
+
FastMCPOpenAPI,
|
| 19 |
+
OpenAPIResource,
|
| 20 |
+
OpenAPIResourceTemplate,
|
| 21 |
+
OpenAPITool,
|
| 22 |
+
)
|
| 23 |
|
| 24 |
|
| 25 |
class User(BaseModel):
|
|
|
|
| 133 |
assert server.name == "FastAPI App"
|
| 134 |
|
| 135 |
|
| 136 |
+
async def test_create_openapi_server_with_timeout(
|
| 137 |
+
fastapi_app: FastAPI, api_client: httpx.AsyncClient
|
| 138 |
+
):
|
| 139 |
+
server = FastMCPOpenAPI(
|
| 140 |
+
openapi_spec=fastapi_app.openapi(),
|
| 141 |
+
client=api_client,
|
| 142 |
+
name="Test App",
|
| 143 |
+
timeout=1.0,
|
| 144 |
+
)
|
| 145 |
+
assert server._timeout == 1.0
|
| 146 |
+
|
| 147 |
+
for tool in (await server.get_tools()).values():
|
| 148 |
+
assert isinstance(tool, OpenAPITool)
|
| 149 |
+
assert tool._timeout == 1.0
|
| 150 |
+
|
| 151 |
+
for resource in (await server.get_resources()).values():
|
| 152 |
+
assert isinstance(resource, OpenAPIResource)
|
| 153 |
+
assert resource._timeout == 1.0
|
| 154 |
+
|
| 155 |
+
for template in (await server.get_resource_templates()).values():
|
| 156 |
+
assert isinstance(template, OpenAPIResourceTemplate)
|
| 157 |
+
assert template._timeout == 1.0
|
| 158 |
+
|
| 159 |
+
|
| 160 |
class TestTools:
|
| 161 |
async def test_list_tools(self, fastmcp_openapi_server: FastMCPOpenAPI):
|
| 162 |
"""
|