@@ -96,6 +96,8 @@ def mock_oauth_auth_code_gateway():
9696 gw .enabled = True
9797 gw .reachable = True
9898 gw .tools = []
99+ gw .resources = []
100+ gw .prompts = []
99101 gw .transport = "sse"
100102 gw .auth_type = "oauth"
101103 gw .auth_value = {}
@@ -518,21 +520,35 @@ async def test_forward_request_to_all_oauth_error_collection(self, gateway_servi
518520 @pytest .mark .asyncio
519521 async def test_fetch_tools_after_oauth_success (self , gateway_service , mock_oauth_auth_code_gateway , test_db ):
520522 """Test successful tool fetching after OAuth authorization."""
521- # Mock database execute to return the gateway
522- mock_result = MagicMock ()
523- mock_result .scalar_one_or_none .return_value = mock_oauth_auth_code_gateway
524- test_db .execute .return_value = mock_result
523+ # Mock database execute to return the gateway for initial query
524+ mock_gateway_result = MagicMock ()
525+ mock_gateway_result .scalar_one_or_none .return_value = mock_oauth_auth_code_gateway
526+
527+ # Mock database execute for helper method queries (finding existing tools)
528+ mock_tool_result = MagicMock ()
529+ mock_tool_result .scalar_one_or_none .return_value = None # No existing tool found
530+
531+ # Set up side effect for multiple database calls
532+ test_db .execute .side_effect = [
533+ mock_gateway_result , # First call to get gateway
534+ mock_tool_result , # Call from _update_or_create_tools helper method
535+ ]
525536
526537 # Mock TokenStorageService
527538 with patch ("mcpgateway.services.token_storage_service.TokenStorageService" ) as mock_token_service_class :
528539 mock_token_service = MagicMock ()
529540 mock_token_service_class .return_value = mock_token_service
530541 mock_token_service .get_user_token = AsyncMock (return_value = "oauth_callback_token" )
531542
532- # Mock the connection methods
543+ # Mock the connection methods - create properly configured tool mocks
544+ mock_tool = MagicMock (spec = ToolCreate )
545+ mock_tool .name = "oauth_tool"
546+ mock_tool .description = "OAuth Tool"
547+ mock_tool .inputSchema = {}
548+
533549 gateway_service .connect_to_sse_server = AsyncMock (return_value = (
534550 {"protocolVersion" : "0.1.0" }, # capabilities
535- [MagicMock ( spec = ToolCreate , name = "oauth_tool" , description = "OAuth Tool" ) ], # tools
551+ [mock_tool ], # tools
536552 [], # resources
537553 [] # prompts
538554 ))
0 commit comments