Skip to content

Commit 20e86f3

Browse files
committed
test: add tests for tools
1 parent cf16dcd commit 20e86f3

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

tests/test_tools.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import uuid
2+
import pytest
3+
from protocols_io_mcp.server import mcp
4+
from fastmcp import Client
5+
6+
test_protocol_id = None
7+
test_protocol_title = None
8+
test_protocol_description = None
9+
10+
@pytest.mark.asyncio
11+
async def test_search_public_protocols():
12+
async with Client(mcp) as client:
13+
response = await client.call_tool("search_public_protocols", {"keyword": "dna", "page": 3})
14+
assert "error_message" not in response.data
15+
assert response.data["current_page"] == 3
16+
17+
@pytest.mark.asyncio
18+
async def test_get_my_protocols():
19+
async with Client(mcp) as client:
20+
response = await client.call_tool("get_my_protocols", {})
21+
assert "error_message" not in response.data
22+
if len(response.data) == 2:
23+
global test_protocol_id, test_protocol_title, test_protocol_description
24+
for protocol in response.data:
25+
if protocol["doi"] is None:
26+
test_protocol_id = protocol["id"]
27+
test_protocol_title = protocol["title"]
28+
test_protocol_description = protocol["description"]
29+
break
30+
assert test_protocol_id is not None
31+
32+
@pytest.mark.asyncio
33+
async def test_create_protocol():
34+
global test_protocol_id, test_protocol_title, test_protocol_description
35+
if test_protocol_id is not None:
36+
pytest.skip("Skipping because the maximum number of protocols has been reached")
37+
async with Client(mcp) as client:
38+
response = await client.call_tool("create_protocol", {"title": "Test Protocol", "description": "This is a test protocol."})
39+
assert "error_message" not in response.data
40+
assert response.data["title"] == "Test Protocol"
41+
assert response.data["description"] == "This is a test protocol."
42+
test_protocol_id = response.data["id"]
43+
test_protocol_title = response.data["title"]
44+
test_protocol_description = response.data["description"]
45+
46+
@pytest.mark.asyncio
47+
async def test_get_protocol():
48+
global test_protocol_id
49+
async with Client(mcp) as client:
50+
response = await client.call_tool("get_protocol", {"protocol_id": test_protocol_id})
51+
assert "error_message" not in response.data
52+
assert response.data["id"] == test_protocol_id
53+
assert response.data["title"] == test_protocol_title
54+
assert response.data["description"] == test_protocol_description
55+
56+
@pytest.mark.asyncio
57+
async def test_update_protocol_title():
58+
global test_protocol_id, test_protocol_title
59+
async with Client(mcp) as client:
60+
title_updated = f"Updated Test Protocol {uuid.uuid4().hex}"
61+
response = await client.call_tool("update_protocol_title", {"protocol_id": test_protocol_id, "title": title_updated})
62+
assert "error_message" not in response.data
63+
assert response.data["title"] == title_updated
64+
response = await client.call_tool("update_protocol_title", {"protocol_id": test_protocol_id, "title": test_protocol_title})
65+
assert "error_message" not in response.data
66+
assert response.data["title"] == test_protocol_title
67+
68+
@pytest.mark.asyncio
69+
async def test_update_protocol_description():
70+
global test_protocol_id, test_protocol_description
71+
async with Client(mcp) as client:
72+
description_updated = f"Updated description {uuid.uuid4().hex}"
73+
response = await client.call_tool("update_protocol_description", {"protocol_id": test_protocol_id, "description": description_updated})
74+
assert "error_message" not in response.data
75+
assert response.data["description"] == description_updated
76+
response = await client.call_tool("update_protocol_description", {"protocol_id": test_protocol_id, "description": test_protocol_description})
77+
assert "error_message" not in response.data
78+
assert response.data["description"] == test_protocol_description
79+
80+
@pytest.mark.asyncio
81+
async def test_get_protocol_steps():
82+
global test_protocol_id
83+
async with Client(mcp) as client:
84+
response = await client.call_tool("get_protocol_steps", {"protocol_id": test_protocol_id})
85+
assert "error_message" not in response.data

0 commit comments

Comments
 (0)