Skip to content

Commit 0f0dc70

Browse files
committed
fix(apigee): mock google.auth.default in unit tests to fix CI failures
Add autouse fixture to mock google.auth.default across all apigee_llm tests, preventing DefaultCredentialsError in CI environments without Application Default Credentials.
1 parent 873d22b commit 0f0dc70

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

tests/unittests/models/test_apigee_llm.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
PROXY_URL = 'https://test.apigee.net'
3535

3636

37+
@pytest.fixture(autouse=True)
38+
def mock_google_auth_default():
39+
"""Mocks google.auth.default to avoid requiring real credentials in tests."""
40+
with mock.patch(
41+
'google.adk.models.apigee_llm.google.auth.default'
42+
) as mock_auth:
43+
mock_auth.return_value = (mock.Mock(), 'test-project')
44+
yield mock_auth
45+
46+
3747
@pytest.fixture
3848
def llm_request():
3949
"""Provides a sample LlmRequest for testing."""
@@ -654,13 +664,12 @@ def test_parse_response_usage_metadata():
654664

655665
@pytest.mark.asyncio
656666
@mock.patch('google.genai.Client')
657-
@mock.patch('google.adk.models.apigee_llm.google.auth.default')
658667
async def test_api_client_requests_userinfo_email_scope(
659-
mock_auth_default, mock_client_constructor, llm_request
668+
mock_client_constructor, llm_request, mock_google_auth_default
660669
):
661670
"""Tests that api_client requests userinfo.email scope for Apigee Gateway tokeninfo."""
662671
mock_credentials = mock.Mock()
663-
mock_auth_default.return_value = (mock_credentials, 'test-project')
672+
mock_google_auth_default.return_value = (mock_credentials, 'test-project')
664673

665674
mock_client_instance = mock.Mock()
666675
mock_client_instance.aio.models.generate_content = AsyncMock(
@@ -683,7 +692,7 @@ async def test_api_client_requests_userinfo_email_scope(
683692
)
684693
_ = [resp async for resp in apigee_llm.generate_content_async(llm_request)]
685694

686-
mock_auth_default.assert_called_once_with(scopes=_APIGEE_SCOPES)
695+
mock_google_auth_default.assert_called_once_with(scopes=_APIGEE_SCOPES)
687696

688697
_, kwargs = mock_client_constructor.call_args
689698
assert kwargs['credentials'] is mock_credentials

0 commit comments

Comments
 (0)