Skip to content

Commit 2af0753

Browse files
committed
Bug fix
1 parent b8e64e2 commit 2af0753

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

.coverage

-52 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ __pycache__/
1515
/data/
1616
/node_modules/
1717
coverage.xml
18+
.coverage
1819

1920
# docs
2021
/docs/generated/
@@ -23,3 +24,4 @@ coverage.xml
2324
# env files
2425
.env
2526
*.local
27+
.vscode

src/protocol_mcp/services/protocols_io.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ async def search_protocols(
124124
filter_params = {}
125125
if peer_reviewed_only:
126126
filter_params["filter"] = "peer_reviewed"
127+
else:
128+
# Default to searching public protocols
129+
filter_params["filter"] = "public"
130+
131+
# Use date ordering instead of relevance (which has a DB error)
132+
filter_params["order_field"] = "date"
133+
filter_params["order_dir"] = "desc"
127134

128135
response = await client.search_protocols(
129136
query=query,

tests/fixtures/protocols_io_responses.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,91 @@
11
"""Mock responses for protocols.io API tests."""
22

33
SEARCH_RESPONSE = {
4+
"status_code": 0,
45
"items": [
56
{
67
"id": 12345,
78
"title": "RNA Extraction from Tissue Samples",
9+
"title_html": "RNA Extraction from Tissue Samples",
810
"uri": "rna-extraction-from-tissue-samples-abc123",
9-
"doi": "10.17504/protocols.io.abc123",
11+
"doi": "dx.doi.org/10.17504/protocols.io.abc123",
12+
"url": "https://www.protocols.io/view/rna-extraction-from-tissue-samples-abc123",
1013
"stats": {
1114
"number_of_steps": 15,
15+
"number_of_views": 1234,
16+
"number_of_bookmarks": 5,
17+
"number_of_comments": 2,
1218
},
1319
"creator": {
1420
"name": "Jane Doe",
1521
"username": "janedoe",
22+
"affiliation": "Test University",
23+
"link": None,
24+
"image": {
25+
"source": "https://www.protocols.io/img/avatars/001.png",
26+
"placeholder": "https://www.protocols.io/img/avatars/001.png",
27+
},
1628
},
1729
"version_id": 1,
30+
"public": True,
31+
"published_on": 1609459200,
32+
"created_on": 1609459200,
1833
},
1934
{
2035
"id": 12346,
2136
"title": "High-Quality RNA Isolation Protocol",
37+
"title_html": "High-Quality RNA Isolation Protocol",
2238
"uri": "high-quality-rna-isolation-xyz789",
23-
"doi": "10.17504/protocols.io.xyz789",
39+
"doi": "dx.doi.org/10.17504/protocols.io.xyz789",
40+
"url": "https://www.protocols.io/view/high-quality-rna-isolation-xyz789",
2441
"stats": {
2542
"number_of_steps": 22,
43+
"number_of_views": 567,
44+
"number_of_bookmarks": 3,
45+
"number_of_comments": 1,
2646
},
2747
"creator": {
2848
"name": "John Smith",
2949
"username": "johnsmith",
50+
"affiliation": "Research Institute",
51+
"link": None,
52+
"image": {
53+
"source": "https://www.protocols.io/img/avatars/002.png",
54+
"placeholder": "https://www.protocols.io/img/avatars/002.png",
55+
},
3056
},
3157
"version_id": 2,
58+
"public": True,
59+
"published_on": 1609545600,
60+
"created_on": 1609545600,
3261
},
3362
],
3463
"pagination": {
3564
"current_page": 1,
3665
"total_pages": 5,
3766
"total_results": 47,
3867
"page_size": 10,
68+
"next_page": "https://www.protocols.io/api/v3/protocols?filter=public&key=RNA&page_id=2&page_size=10",
69+
"prev_page": None,
70+
"first": 0,
71+
"last": 47,
72+
"changed_on": None,
3973
},
4074
}
4175

4276
EMPTY_SEARCH_RESPONSE = {
77+
"status_code": 0,
4378
"items": [],
4479
"pagination": {
4580
"current_page": 1,
4681
"total_pages": 0,
4782
"total_results": 0,
4883
"page_size": 10,
84+
"next_page": None,
85+
"prev_page": None,
86+
"first": 0,
87+
"last": 0,
88+
"changed_on": None,
4989
},
5090
}
5191

tests/test_protocols_io.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
async def test_search_protocols_returns_formatted_results(httpx_mock: HTTPXMock):
2020
"""Test that search returns properly formatted results."""
2121
httpx_mock.add_response(
22-
url="https://www.protocols.io/api/v3/protocols?key=RNA&page_size=10&page_id=1&order_field=relevance",
22+
url="https://www.protocols.io/api/v3/protocols?key=RNA&page_size=10&page_id=1&filter=public&order_field=date&order_dir=desc",
2323
json=SEARCH_RESPONSE,
2424
)
2525

@@ -39,7 +39,7 @@ async def test_search_protocols_returns_formatted_results(httpx_mock: HTTPXMock)
3939
async def test_search_protocols_handles_empty_results(httpx_mock: HTTPXMock):
4040
"""Test that search handles no results gracefully."""
4141
httpx_mock.add_response(
42-
url="https://www.protocols.io/api/v3/protocols?key=nonexistent_xyz_query&page_size=10&page_id=1&order_field=relevance",
42+
url="https://www.protocols.io/api/v3/protocols?key=nonexistent_xyz_query&page_size=10&page_id=1&filter=public&order_field=date&order_dir=desc",
4343
json=EMPTY_SEARCH_RESPONSE,
4444
)
4545

@@ -53,7 +53,7 @@ async def test_search_protocols_handles_empty_results(httpx_mock: HTTPXMock):
5353
async def test_search_protocols_with_peer_reviewed_filter(httpx_mock: HTTPXMock):
5454
"""Test that peer_reviewed_only filter is applied."""
5555
httpx_mock.add_response(
56-
url="https://www.protocols.io/api/v3/protocols?key=RNA&page_size=10&page_id=1&order_field=relevance&filter=peer_reviewed",
56+
url="https://www.protocols.io/api/v3/protocols?key=RNA&page_size=10&page_id=1&filter=peer_reviewed&order_field=date&order_dir=desc",
5757
json=SEARCH_RESPONSE,
5858
)
5959

@@ -190,7 +190,7 @@ async def test_search_respects_max_results_bounds(httpx_mock: HTTPXMock):
190190
"""Test that max_results is bounded between 1 and 50."""
191191
# Test with value > 50 (should be clamped to 50)
192192
httpx_mock.add_response(
193-
url="https://www.protocols.io/api/v3/protocols?key=RNA&page_size=50&page_id=1&order_field=relevance",
193+
url="https://www.protocols.io/api/v3/protocols?key=RNA&page_size=50&page_id=1&filter=public&order_field=date&order_dir=desc",
194194
json=SEARCH_RESPONSE,
195195
)
196196

0 commit comments

Comments
 (0)