Skip to content

Commit a88192c

Browse files
rakdutta1madhav165
authored andcommitted
pytest
Signed-off-by: RAKHI DUTTA <rakdutta@in.ibm.com>
1 parent f3493d7 commit a88192c

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

tests/unit/mcpgateway/services/test_tool_service.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def mock_tool():
7474
tool = MagicMock(spec=DbTool)
7575
tool.id = "1"
7676
tool.original_name = "test_tool"
77-
tool.original_name_slug = "test-tool"
7877
tool.url = "http://example.com/tools/test"
7978
tool.description = "A test tool"
8079
tool.integration_type = "MCP"
@@ -96,6 +95,8 @@ def mock_tool():
9695
tool.annotations = {}
9796
tool.gateway_slug = "test-gateway"
9897
tool.name = "test-gateway-test-tool"
98+
tool.custom_name="test_tool"
99+
tool.custom_name_slug = "test-tool"
99100

100101
# Set up metrics
101102
tool.metrics = []
@@ -202,7 +203,7 @@ async def test_register_tool(self, tool_service, mock_tool, test_db):
202203
id="1",
203204
original_name="test_tool",
204205
gateway_slug="test-gateway",
205-
originalNameSlug="test-tool",
206+
customNameSlug="test-tool",
206207
name="test-gateway-test-tool",
207208
url="http://example.com/tools/test",
208209
description="A test tool",
@@ -229,6 +230,7 @@ async def test_register_tool(self, tool_service, mock_tool, test_db):
229230
"avg_response_time": None,
230231
"last_execution_time": None,
231232
},
233+
customName="test_tool",
232234
)
233235
)
234236

@@ -281,10 +283,8 @@ async def test_register_tool_with_gateway_id(self, tool_service, mock_tool, test
281283
# Should raise ToolError due to missing slug on NoneType
282284
with pytest.raises(ToolError) as exc_info:
283285
await tool_service.register_tool(test_db, tool_create)
284-
285-
# The service wraps exceptions, so check the message
286-
assert "Failed to register tool" in str(exc_info.value)
287-
assert "slug" in str(exc_info.value)
286+
# The service wraps exceptions, so check the message
287+
assert "Failed to register tool" in str(exc_info.value)
288288

289289
@pytest.mark.asyncio
290290
async def test_register_tool_with_none_auth(self, tool_service, test_db):
@@ -402,7 +402,8 @@ async def test_list_tools(self, tool_service, mock_tool, test_db):
402402
tool_read = ToolRead(
403403
id="1",
404404
original_name="test_tool",
405-
original_name_slug="test-tool",
405+
custom_name="test_tool",
406+
custom_name_slug="test-tool",
406407
gateway_slug="test-gateway",
407408
name="test-gateway-test-tool",
408409
url="http://example.com/tools/test",
@@ -430,6 +431,7 @@ async def test_list_tools(self, tool_service, mock_tool, test_db):
430431
"avg_response_time": None,
431432
"last_execution_time": None,
432433
},
434+
433435
)
434436
tool_service._convert_tool_to_read = Mock(return_value=tool_read)
435437

@@ -460,7 +462,6 @@ async def test_list_inactive_tools(self, tool_service, mock_tool, test_db):
460462
tool_read = ToolRead(
461463
id="1",
462464
original_name="test_tool",
463-
original_name_slug="test-tool",
464465
gateway_slug="test-gateway",
465466
name="test-gateway-test-tool",
466467
url="http://example.com/tools/test",
@@ -488,6 +489,8 @@ async def test_list_inactive_tools(self, tool_service, mock_tool, test_db):
488489
"avg_response_time": None,
489490
"last_execution_time": None,
490491
},
492+
customName="test_tool",
493+
customNameSlug="test-tool"
491494
)
492495
tool_service._convert_tool_to_read = Mock(return_value=tool_read)
493496

@@ -547,7 +550,6 @@ async def test_get_tool(self, tool_service, mock_tool, test_db):
547550
tool_read = ToolRead(
548551
id="1",
549552
original_name="test_tool",
550-
original_name_slug="test-tool",
551553
gateway_slug="test-gateway",
552554
name="test-gateway-test-tool",
553555
url="http://example.com/tools/test",
@@ -575,6 +577,8 @@ async def test_get_tool(self, tool_service, mock_tool, test_db):
575577
"avg_response_time": None,
576578
"last_execution_time": None,
577579
},
580+
customName="test_tool",
581+
customNameSlug="test-tool"
578582
)
579583
tool_service._convert_tool_to_read = Mock(return_value=tool_read)
580584

@@ -650,7 +654,8 @@ async def test_toggle_tool_status(self, tool_service, mock_tool, test_db):
650654
tool_read = ToolRead(
651655
id="1",
652656
original_name="test_tool",
653-
original_name_slug="test-tool",
657+
custom_name="test_tool",
658+
custom_name_slug="test-tool",
654659
gateway_slug="test-gateway",
655660
name="test-gateway-test-tool",
656661
url="http://example.com/tools/test",
@@ -678,6 +683,7 @@ async def test_toggle_tool_status(self, tool_service, mock_tool, test_db):
678683
"avg_response_time": None,
679684
"last_execution_time": None,
680685
},
686+
681687
)
682688
tool_service._convert_tool_to_read = Mock(return_value=tool_read)
683689

@@ -832,7 +838,8 @@ async def test_toggle_tool_status_no_change(self, tool_service, mock_tool, test_
832838
tool_read = ToolRead(
833839
id="1",
834840
original_name="test_tool",
835-
original_name_slug="test-tool",
841+
custom_name="test_tool",
842+
custom_name_slug="test-tool",
836843
gateway_slug="test-gateway",
837844
name="test-gateway-test-tool",
838845
url="http://example.com/tools/test",
@@ -902,7 +909,8 @@ async def test_update_tool(self, tool_service, mock_tool, test_db):
902909
tool_read = ToolRead(
903910
id="1",
904911
original_name="test_tool",
905-
original_name_slug="test-tool",
912+
custom_name="test_tool",
913+
custom_name_slug="test-tool",
906914
gateway_slug="test-gateway",
907915
name="test-gateway-test-tool",
908916
url="http://example.com/tools/updated", # Updated URL
@@ -935,7 +943,7 @@ async def test_update_tool(self, tool_service, mock_tool, test_db):
935943

936944
# Create update request
937945
tool_update = ToolUpdate(
938-
name="updated_tool",
946+
custom_name="updated_tool",
939947
url="http://example.com/tools/updated",
940948
description="An updated test tool",
941949
)
@@ -949,7 +957,7 @@ async def test_update_tool(self, tool_service, mock_tool, test_db):
949957
test_db.refresh.assert_called_once()
950958

951959
# Verify properties were updated
952-
assert mock_tool.name == "updated_tool"
960+
assert mock_tool.custom_name == "updated_tool"
953961
assert mock_tool.url == "http://example.com/tools/updated"
954962
assert mock_tool.description == "An updated test tool"
955963

tests/unit/mcpgateway/test_admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ async def test_admin_edit_tool_all_error_paths(self, mock_update_tool, mock_requ
437437
from starlette.datastructures import FormData
438438

439439
mock_request.form = AsyncMock(
440-
return_value=FormData([("name", "Tool_Name_1"), ("url", "http://example.com"), ("requestType", "GET"), ("integrationType", "REST"), ("headers", "{}"), ("input_schema", "{}")])
440+
return_value=FormData([("name", "Tool_Name_1"),("customName", "Tool_Name_1"), ("url", "http://example.com"), ("requestType", "GET"), ("integrationType", "REST"), ("headers", "{}"), ("input_schema", "{}")])
441441
)
442442
mock_update_tool.side_effect = IntegrityError("Integrity constraint", {}, Exception("Duplicate key"))
443443
result = await admin_edit_tool(tool_id, mock_request, mock_db, "test-user")
@@ -466,6 +466,7 @@ async def test_admin_edit_tool_with_empty_optional_fields(self, mock_update_tool
466466
form_data = FakeForm(
467467
{
468468
"name": "Updated_Tool", # Valid tool name format
469+
"customName": "Updated_Tool", # Add required field for validation
469470
"url": "http://updated.com",
470471
"description": "",
471472
"headers": "",

tests/unit/mcpgateway/test_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"id": "1",
6666
"name": "test_tool",
6767
"originalName": "test_tool",
68+
"customName": "test_tool",
6869
"url": "http://example.com/tools/test",
6970
"description": "A test tool",
7071
"requestType": "POST",
@@ -82,7 +83,7 @@
8283
"executionCount": 5,
8384
"metrics": MOCK_METRICS,
8485
"gatewaySlug": "gateway-1",
85-
"originalNameSlug": "test-tool",
86+
"customNameSlug": "test-tool",
8687
}
8788

8889
# camelCase → snake_case key map for the fields that differ

0 commit comments

Comments
 (0)