async def test_get_credentials_from_cache_when_none_in_manager(
      self, manager, mock_tool_context
  ):
    """Test retrieving credentials from tool_context cache when manager has none.

    This tests the new caching functionality where credentials can be
    retrieved from the tool context state when the manager instance
    doesn't have them loaded.
    """
    # Manager starts with no credentials
    manager.credentials_config.credentials = None

    # Create mock cached credentials JSON that would be stored in cache
    mock_cached_creds_json = json.dumps({
        "token": "cached_token",
        "refresh_token": "cached_refresh_token",
        "client_id": "test_client_id",
        "client_secret": "test_client_secret",
    })

    # Set up the tool context state to contain cached credentials
    mock_tool_context.state[BIGQUERY_TOKEN_CACHE_KEY] = mock_cached_creds_json

    # Mock the Credentials.from_authorized_user_info method
    with patch(
        "google.oauth2.credentials.Credentials.from_authorized_user_info"
    ) as mock_from_json:
      mock_creds = Mock(spec=Credentials)
      mock_creds.valid = True
      mock_from_json.return_value = mock_creds

      result = await manager.get_valid_credentials(mock_tool_context)

      # Verify credentials were created from cached JSON
      mock_from_json.assert_called_once_with(
          json.loads(mock_cached_creds_json), manager.credentials_config.scopes
      )
      # Verify loaded credentials were not cached into manager
      assert manager.credentials_config.credentials is None
      # Verify valid cached credentials were returned
      assert result == mock_creds
Test retrieving credentials from tool_context cache when manager has none.

    This tests the new caching functionality where credentials can be
    retrieved from the tool context state when the manager instance
    doesn't have them loaded.
    
tests/unittests/tools/bigquery/test_bigquery_credentials_manager.py