@@ -96,6 +96,8 @@ def mock_oauth_auth_code_gateway():
96
96
gw .enabled = True
97
97
gw .reachable = True
98
98
gw .tools = []
99
+ gw .resources = []
100
+ gw .prompts = []
99
101
gw .transport = "sse"
100
102
gw .auth_type = "oauth"
101
103
gw .auth_value = {}
@@ -518,21 +520,35 @@ async def test_forward_request_to_all_oauth_error_collection(self, gateway_servi
518
520
@pytest .mark .asyncio
519
521
async def test_fetch_tools_after_oauth_success (self , gateway_service , mock_oauth_auth_code_gateway , test_db ):
520
522
"""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
+ ]
525
536
526
537
# Mock TokenStorageService
527
538
with patch ("mcpgateway.services.token_storage_service.TokenStorageService" ) as mock_token_service_class :
528
539
mock_token_service = MagicMock ()
529
540
mock_token_service_class .return_value = mock_token_service
530
541
mock_token_service .get_user_token = AsyncMock (return_value = "oauth_callback_token" )
531
542
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
+
533
549
gateway_service .connect_to_sse_server = AsyncMock (return_value = (
534
550
{"protocolVersion" : "0.1.0" }, # capabilities
535
- [MagicMock ( spec = ToolCreate , name = "oauth_tool" , description = "OAuth Tool" ) ], # tools
551
+ [mock_tool ], # tools
536
552
[], # resources
537
553
[] # prompts
538
554
))
0 commit comments