From d5b3a89fe76c4658cfce683737ba8a4a13375269 Mon Sep 17 00:00:00 2001 From: luaifei Date: Tue, 6 May 2025 21:44:50 -0700 Subject: [PATCH] fix: fix a few unit tests Copybara import of the project: -- 93cc9c0b71a92991a888c93675ddc8aee11f21dc by luaifei : fix: Update skipped tests in test_auth_handlers -- 06ddf559c76c113231719bff549d41801a93daf4 by luaifei : fix: Update skipped & failed tests in test_connections_client and test_streaming -- b8f2d357c1101c59ee9b65fa89a75f216e014a7c by luaifei : fix: Remove ignored test file from Python unit tests workflow COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/553 from luaifei:fix-tests d51e42841e71d388c16cc719a4798b029182084f PiperOrigin-RevId: 755669644 --- .github/workflows/python-unit-tests.yml | 1 - tests/unittests/auth/test_auth_handler.py | 6 ++---- tests/unittests/streaming/test_streaming.py | 1 - .../clients/test_connections_client.py | 8 +++++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/python-unit-tests.yml b/.github/workflows/python-unit-tests.yml index a378a75..74dc72e 100644 --- a/.github/workflows/python-unit-tests.yml +++ b/.github/workflows/python-unit-tests.yml @@ -36,6 +36,5 @@ jobs: source .venv/bin/activate pytest tests/unittests \ --ignore=tests/unittests/artifacts/test_artifact_service.py \ - --ignore=tests/unittests/tools/application_integration_tool/clients/test_connections_client.py \ --ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py diff --git a/tests/unittests/auth/test_auth_handler.py b/tests/unittests/auth/test_auth_handler.py index 6a86e8d..6bad2a3 100644 --- a/tests/unittests/auth/test_auth_handler.py +++ b/tests/unittests/auth/test_auth_handler.py @@ -15,12 +15,12 @@ import copy from unittest.mock import patch +import pytest from fastapi.openapi.models import APIKey from fastapi.openapi.models import APIKeyIn from fastapi.openapi.models import OAuth2 from fastapi.openapi.models import OAuthFlowAuthorizationCode from fastapi.openapi.models import OAuthFlows -import pytest from google.adk.auth.auth_credential import AuthCredential from google.adk.auth.auth_credential import AuthCredentialTypes @@ -58,7 +58,7 @@ class MockOAuth2Session: self.redirect_uri = redirect_uri self.state = state - def create_authorization_url(self, url): + def create_authorization_url(self, url, **kwargs): return f"{url}?client_id={self.client_id}&scope={self.scope}", "mock_state" def fetch_token( @@ -238,7 +238,6 @@ class TestGetCredentialKey: class TestGenerateAuthUri: """Tests for the generate_auth_uri method.""" - @pytest.mark.skip(reason="broken tests") @patch("google.adk.auth.auth_handler.OAuth2Session", MockOAuth2Session) def test_generate_auth_uri_oauth2(self, auth_config): """Test generating an auth URI for OAuth2.""" @@ -251,7 +250,6 @@ class TestGenerateAuthUri: assert "client_id=mock_client_id" in result.oauth2.auth_uri assert result.oauth2.state == "mock_state" - @pytest.mark.skip(reason="broken tests") @patch("google.adk.auth.auth_handler.OAuth2Session", MockOAuth2Session) def test_generate_auth_uri_openid( self, openid_auth_scheme, oauth2_credentials diff --git a/tests/unittests/streaming/test_streaming.py b/tests/unittests/streaming/test_streaming.py index 00d387b..a20da0f 100644 --- a/tests/unittests/streaming/test_streaming.py +++ b/tests/unittests/streaming/test_streaming.py @@ -21,7 +21,6 @@ import pytest from .. import utils -@pytest.mark.skip(reason='Streaming is hanging.') def test_streaming(): response1 = LlmResponse( turn_complete=True, diff --git a/tests/unittests/tools/application_integration_tool/clients/test_connections_client.py b/tests/unittests/tools/application_integration_tool/clients/test_connections_client.py index 228c0aa..d60938d 100644 --- a/tests/unittests/tools/application_integration_tool/clients/test_connections_client.py +++ b/tests/unittests/tools/application_integration_tool/clients/test_connections_client.py @@ -195,6 +195,7 @@ class TestConnectionsClient: "serviceName": "tls_test_service", "host": "test.host", "authOverrideEnabled": True, + "name": "", } def test_get_connection_details_success_without_host( @@ -217,6 +218,7 @@ class TestConnectionsClient: "serviceName": "test_service", "host": "", "authOverrideEnabled": False, + "name": "", } def test_get_connection_details_error( @@ -431,21 +433,21 @@ class TestConnectionsClient: def test_create_operation(self): operation = ConnectionsClient.create_operation("Entity1", "test_tool") assert "post" in operation - assert operation["post"]["summary"] == "Create Entity1" + assert operation["post"]["summary"] == "Creates a new Entity1" assert "operationId" in operation["post"] assert operation["post"]["operationId"] == "test_tool_create_Entity1" def test_update_operation(self): operation = ConnectionsClient.update_operation("Entity1", "test_tool") assert "post" in operation - assert operation["post"]["summary"] == "Update Entity1" + assert operation["post"]["summary"] == "Updates the Entity1" assert "operationId" in operation["post"] assert operation["post"]["operationId"] == "test_tool_update_Entity1" def test_delete_operation(self): operation = ConnectionsClient.delete_operation("Entity1", "test_tool") assert "post" in operation - assert operation["post"]["summary"] == "Delete Entity1" + assert operation["post"]["summary"] == "Delete the Entity1" assert operation["post"]["operationId"] == "test_tool_delete_Entity1" def test_create_operation_request(self):