Skip to content

Commit 78ca19a

Browse files
committed
Fix tests
Signed-off-by: Madhav Kandukuri <[email protected]>
1 parent d33c663 commit 78ca19a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

tests/unit/mcpgateway/services/test_tool_service.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,20 +1649,31 @@ async def test_invoke_tool_mcp_tool_basic_auth(self, tool_service, mock_tool, mo
16491649
mock_gateway.enabled = True
16501650
mock_gateway.reachable = True
16511651
mock_gateway.id = mock_tool.gateway_id
1652+
mock_gateway.slug="test-gateway"
1653+
mock_gateway.capabilities = {"tools": {"listChanged": True}}
1654+
mock_gateway.transport = "SSE"
1655+
mock_gateway.passthrough_headers = []
16521656

1653-
# Use a robust side_effect function like other working tests
1654-
returns = [mock_tool, mock_tool, mock_gateway]
1657+
# Ensure the service reads headers from the gateway attached to the tool
1658+
# The invoke path uses `gateway = tool.gateway` for auth header calculation
1659+
mock_tool.gateway = mock_gateway
1660+
1661+
# Two DB selects occur in this path: first for tool, then for gateway
1662+
# Return the tool on first call and the gateway on second call
1663+
returns = [mock_tool, mock_gateway]
16551664

16561665
def execute_side_effect(*_args, **_kwargs):
16571666
if returns:
16581667
value = returns.pop(0)
16591668
else:
1660-
# After initial queries, keep returning gateway for any additional queries
16611669
value = mock_gateway
16621670

1663-
m = Mock()
1664-
m.scalar_one_or_none.return_value = value
1665-
return m
1671+
# Return an object whose scalar_one_or_none() returns the real value
1672+
class Result:
1673+
def scalar_one_or_none(self_inner):
1674+
return value
1675+
1676+
return Result()
16661677

16671678
test_db.execute = Mock(side_effect=execute_side_effect)
16681679

@@ -1701,6 +1712,7 @@ def execute_side_effect(*_args, **_kwargs):
17011712
sse_client_mock.assert_called_once_with(
17021713
url=mock_gateway.url,
17031714
headers={"Authorization": "Basic dGVzdF91c2VyOnRlc3RfcGFzc3dvcmQ="},
1715+
httpx_client_factory=ANY,
17041716
)
17051717

17061718
@pytest.mark.asyncio

0 commit comments

Comments
 (0)