1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- """Unit tests for mtls_utils ."""
15+ """Unit tests for _mtls_utils ."""
1616
1717import os
1818from unittest .mock import MagicMock
1919from unittest .mock import patch
2020
21- from google .adk .utils import mtls_utils
21+ from google .adk .utils import _mtls_utils
2222import pytest
2323
2424_DEFAULT_TEMPLATE = "service.{location}.rep.googleapis.com"
2727
2828
2929class TestMtlsUtils :
30- """Tests for mtls_utils functions."""
30+ """Tests for _mtls_utils functions."""
3131
3232 @patch ("google.auth.transport.mtls.should_use_client_cert" )
3333 def test_use_client_cert_effective_with_mtls_cert_true (
3434 self , mock_should_use_client_cert
3535 ):
3636 mock_should_use_client_cert .return_value = True
37- assert mtls_utils .use_client_cert_effective () is True
37+ assert _mtls_utils .use_client_cert_effective () is True
3838 mock_should_use_client_cert .assert_called_once ()
3939
4040 @patch ("google.auth.transport.mtls.should_use_client_cert" )
4141 def test_use_client_cert_effective_with_mtls_cert_false (
4242 self , mock_should_use_client_cert
4343 ):
4444 mock_should_use_client_cert .return_value = False
45- assert mtls_utils .use_client_cert_effective () is False
45+ assert _mtls_utils .use_client_cert_effective () is False
4646 mock_should_use_client_cert .assert_called_once ()
4747
4848 @patch ("google.auth.transport.mtls.should_use_client_cert" )
@@ -51,69 +51,69 @@ def test_use_client_cert_effective_fallback_true(
5151 self , mock_should_use_client_cert
5252 ):
5353 mock_should_use_client_cert .side_effect = AttributeError
54- assert mtls_utils .use_client_cert_effective () is True
54+ assert _mtls_utils .use_client_cert_effective () is True
5555
5656 @patch ("google.auth.transport.mtls.should_use_client_cert" )
5757 @patch .dict ("os.environ" , {"GOOGLE_API_USE_CLIENT_CERTIFICATE" : "false" })
5858 def test_use_client_cert_effective_fallback_false (
5959 self , mock_should_use_client_cert
6060 ):
6161 mock_should_use_client_cert .side_effect = AttributeError
62- assert mtls_utils .use_client_cert_effective () is False
62+ assert _mtls_utils .use_client_cert_effective () is False
6363
6464 @patch ("google.auth.transport.mtls.should_use_client_cert" )
6565 @patch .dict ("os.environ" , {}, clear = True )
6666 def test_use_client_cert_effective_fallback_default_false (
6767 self , mock_should_use_client_cert
6868 ):
6969 mock_should_use_client_cert .side_effect = AttributeError
70- assert mtls_utils .use_client_cert_effective () is False
70+ assert _mtls_utils .use_client_cert_effective () is False
7171
72- @patch ("google.adk.utils.mtls_utils .use_client_cert_effective" )
72+ @patch ("google.adk.utils._mtls_utils .use_client_cert_effective" )
7373 @patch .dict ("os.environ" , {"GOOGLE_API_USE_MTLS_ENDPOINT" : "always" })
7474 def test_get_api_endpoint_always (self , mock_use_client_cert ):
75- endpoint = mtls_utils .get_api_endpoint (
75+ endpoint = _mtls_utils .get_api_endpoint (
7676 _LOCATION , _DEFAULT_TEMPLATE , _MTLS_TEMPLATE
7777 )
7878 assert endpoint == _MTLS_TEMPLATE .format (location = _LOCATION )
7979 mock_use_client_cert .assert_not_called ()
8080
81- @patch ("google.adk.utils.mtls_utils .use_client_cert_effective" )
81+ @patch ("google.adk.utils._mtls_utils .use_client_cert_effective" )
8282 @patch .dict ("os.environ" , {"GOOGLE_API_USE_MTLS_ENDPOINT" : "never" })
8383 def test_get_api_endpoint_never (self , mock_use_client_cert ):
84- endpoint = mtls_utils .get_api_endpoint (
84+ endpoint = _mtls_utils .get_api_endpoint (
8585 _LOCATION , _DEFAULT_TEMPLATE , _MTLS_TEMPLATE
8686 )
8787 assert endpoint == _DEFAULT_TEMPLATE .format (location = _LOCATION )
8888 mock_use_client_cert .assert_not_called ()
8989
90- @patch ("google.adk.utils.mtls_utils .use_client_cert_effective" )
90+ @patch ("google.adk.utils._mtls_utils .use_client_cert_effective" )
9191 @patch .dict ("os.environ" , {"GOOGLE_API_USE_MTLS_ENDPOINT" : "auto" })
9292 def test_get_api_endpoint_auto_with_cert (self , mock_use_client_cert ):
9393 mock_use_client_cert .return_value = True
94- endpoint = mtls_utils .get_api_endpoint (
94+ endpoint = _mtls_utils .get_api_endpoint (
9595 _LOCATION , _DEFAULT_TEMPLATE , _MTLS_TEMPLATE
9696 )
9797 assert endpoint == _MTLS_TEMPLATE .format (location = _LOCATION )
9898 mock_use_client_cert .assert_called_once ()
9999
100- @patch ("google.adk.utils.mtls_utils .use_client_cert_effective" )
100+ @patch ("google.adk.utils._mtls_utils .use_client_cert_effective" )
101101 @patch .dict ("os.environ" , {"GOOGLE_API_USE_MTLS_ENDPOINT" : "auto" })
102102 def test_get_api_endpoint_auto_without_cert (self , mock_use_client_cert ):
103103 mock_use_client_cert .return_value = False
104- endpoint = mtls_utils .get_api_endpoint (
104+ endpoint = _mtls_utils .get_api_endpoint (
105105 _LOCATION , _DEFAULT_TEMPLATE , _MTLS_TEMPLATE
106106 )
107107 assert endpoint == _DEFAULT_TEMPLATE .format (location = _LOCATION )
108108 mock_use_client_cert .assert_called_once ()
109109
110- @patch ("google.adk.utils.mtls_utils .use_client_cert_effective" )
110+ @patch ("google.adk.utils._mtls_utils .use_client_cert_effective" )
111111 @patch .dict ("os.environ" , {"GOOGLE_API_USE_MTLS_ENDPOINT" : "invalid_value" })
112112 def test_get_api_endpoint_invalid_fallback_to_auto (
113113 self , mock_use_client_cert
114114 ):
115115 mock_use_client_cert .return_value = True
116- endpoint = mtls_utils .get_api_endpoint (
116+ endpoint = _mtls_utils .get_api_endpoint (
117117 _LOCATION , _DEFAULT_TEMPLATE , _MTLS_TEMPLATE
118118 )
119119 assert endpoint == _MTLS_TEMPLATE .format (location = _LOCATION )
0 commit comments