Skip to content

Commit 2a1a7a9

Browse files
Fix: Update tests to use handler functions directly
1 parent 2c2ef90 commit 2a1a7a9

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

tests/test_server.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# tests/test_server.py
21
import pytest
3-
from mysql_mcp_server.server import app
2+
from mysql_mcp_server.server import app, list_tools, list_resources, read_resource, call_tool
3+
from pydantic import AnyUrl
44

55
def test_server_initialization():
66
"""Test that the server initializes correctly."""
@@ -9,6 +9,38 @@ def test_server_initialization():
99
@pytest.mark.asyncio
1010
async def test_list_tools():
1111
"""Test that list_tools returns expected tools."""
12-
tools = await app.list_tools()
12+
tools = await list_tools()
1313
assert len(tools) == 1
14-
assert tools[0].name == "execute_sql"
14+
assert tools[0].name == "execute_sql"
15+
assert "query" in tools[0].inputSchema["properties"]
16+
17+
@pytest.mark.asyncio
18+
async def test_call_tool_invalid_name():
19+
"""Test calling a tool with an invalid name."""
20+
with pytest.raises(ValueError, match="Unknown tool"):
21+
await call_tool("invalid_tool", {})
22+
23+
@pytest.mark.asyncio
24+
async def test_call_tool_missing_query():
25+
"""Test calling execute_sql without a query."""
26+
with pytest.raises(ValueError, match="Query is required"):
27+
await call_tool("execute_sql", {})
28+
29+
# Skip database-dependent tests if no database connection
30+
@pytest.mark.asyncio
31+
@pytest.mark.skipif(
32+
not all([
33+
pytest.importorskip("mysql.connector"),
34+
pytest.importorskip("mysql_mcp_server")
35+
]),
36+
reason="MySQL connection not available"
37+
)
38+
async def test_list_resources():
39+
"""Test listing resources (requires database connection)."""
40+
try:
41+
resources = await list_resources()
42+
assert isinstance(resources, list)
43+
except ValueError as e:
44+
if "Missing required database configuration" in str(e):
45+
pytest.skip("Database configuration not available")
46+
raise

0 commit comments

Comments
 (0)