Skip to content

Commit 9e8ded7

Browse files
fix: Refactor mTLS configuration test for AgentRegistry
fix: Refactor test_make_request_configures_mtls to mock session instantiation and response.
1 parent 6387971 commit 9e8ded7

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

tests/unittests/integrations/agent_registry/test_agent_registry.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -761,19 +761,33 @@ def test_make_request_uses_authorized_session_no_mtls(
761761
)
762762
@patch("google.auth.transport.mtls.default_client_cert_source")
763763
@patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"})
764-
def test_make_request_configures_mtls(
765-
self, mock_cert_source, mock_has_cert, registry
766-
):
764+
def test_make_request_configures_mtls(self, mock_cert_source, registry):
767765
"""Verifies that mTLS is configured when supported and enabled."""
768-
mock_session = registry._session
769766
mock_cert_source.return_value = lambda: (b"cert", b"key")
770767

771-
registry._make_request("test-path")
768+
with patch(
769+
"google.auth.default", return_value=(MagicMock(), "test-project")
770+
), patch(
771+
"google.adk.integrations.agent_registry.agent_registry._use_client_cert_effective",
772+
return_value=True,
773+
), patch(
774+
"google.auth.transport.requests.AuthorizedSession"
775+
) as mock_session_class:
776+
# Instantiate inside the test after enabling mTLS patches
777+
registry = AgentRegistry(project_id="test-project", location="global")
778+
mock_session = registry._session
779+
780+
# Mock successful response
781+
mock_response = MagicMock()
782+
mock_response.json.return_value = {"key": "value"}
783+
mock_session.get.return_value = mock_response
784+
785+
registry._make_request("test-path")
772786

773-
# Verify mTLS configuration and endpoint
774-
mock_session.configure_mtls_channel.assert_called_once()
775-
args, kwargs = mock_session.get.call_args
776-
assert "agentregistry.mtls.googleapis.com" in args[0]
787+
# Verify mTLS configuration and endpoint
788+
mock_session.configure_mtls_channel.assert_called_once()
789+
args, kwargs = mock_session.get.call_args
790+
assert "agentregistry.mtls.googleapis.com" in args[0]
777791

778792
@pytest.mark.parametrize(
779793
"env_val, has_cert, expected",

0 commit comments

Comments
 (0)