Fix GCP async connection test mock setup

The test_gcp_async_connection_creation test was incorrectly mocking
the Connector class for async context manager usage, but the actual
implementation creates the connector directly and calls connect_async.

Changed mock setup to:
- Use MagicMock for the connector (not AsyncMock)
- Set Connector.return_value directly (not through __aenter__)
- Use AsyncMock for connect_async method

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
openhands 2025-12-25 04:24:20 +00:00
parent 864f775697
commit 8102b51750

View File

@ -456,13 +456,10 @@ class TestDbSessionInjectorGCPIntegration:
# Mock the google.cloud.sql.connector module
with patch.dict('sys.modules', {'google.cloud.sql.connector': MagicMock()}):
mock_connector_module = sys.modules['google.cloud.sql.connector']
mock_connector = AsyncMock()
mock_connector_module.Connector.return_value.__aenter__.return_value = (
mock_connector
)
mock_connector_module.Connector.return_value.__aexit__.return_value = None
mock_connector = MagicMock()
mock_connector_module.Connector.return_value = mock_connector
mock_connection = AsyncMock()
mock_connector.connect_async.return_value = mock_connection
mock_connector.connect_async = AsyncMock(return_value=mock_connection)
connection = await gcp_db_session_injector._create_async_gcp_db_connection()