1616from unittest import mock
1717
1818import pytest
19- from google .auth .exceptions import MutualTLSChannelError
2019
2120try :
2221 import grpc # noqa: F401
2524
2625from google .api_core import exceptions
2726from google .api_core .gapic_v1 import config
27+ from google .auth .exceptions import MutualTLSChannelError
2828
2929INTERFACE_CONFIG = {
3030 "retry_codes" : {
@@ -121,14 +121,18 @@ def test_use_client_cert_effective_fallback_env_true():
121121def test_use_client_cert_effective_fallback_env_false ():
122122 mock_mtls = mock .Mock (spec = [])
123123 with mock .patch ("google.api_core.gapic_v1.config.mtls" , mock_mtls ):
124- with mock .patch .dict (os .environ , {"GOOGLE_API_USE_CLIENT_CERTIFICATE" : "false" }):
124+ with mock .patch .dict (
125+ os .environ , {"GOOGLE_API_USE_CLIENT_CERTIFICATE" : "false" }
126+ ):
125127 assert config .use_client_cert_effective () is False
126128
127129
128130def test_use_client_cert_effective_fallback_env_invalid ():
129131 mock_mtls = mock .Mock (spec = [])
130132 with mock .patch ("google.api_core.gapic_v1.config.mtls" , mock_mtls ):
131- with mock .patch .dict (os .environ , {"GOOGLE_API_USE_CLIENT_CERTIFICATE" : "invalid" }):
133+ with mock .patch .dict (
134+ os .environ , {"GOOGLE_API_USE_CLIENT_CERTIFICATE" : "invalid" }
135+ ):
132136 with pytest .raises (
133137 ValueError ,
134138 match = "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" ,
@@ -142,7 +146,9 @@ def test_get_client_cert_source_provided():
142146
143147
144148def test_get_client_cert_source_default ():
145- mock_mtls = mock .Mock (spec = ["has_default_client_cert_source" , "default_client_cert_source" ])
149+ mock_mtls = mock .Mock (
150+ spec = ["has_default_client_cert_source" , "default_client_cert_source" ]
151+ )
146152 mock_mtls .has_default_client_cert_source .return_value = True
147153 mock_source = mock .Mock ()
148154 mock_mtls .default_client_cert_source .return_value = mock_source
@@ -151,7 +157,9 @@ def test_get_client_cert_source_default():
151157
152158
153159def test_get_client_cert_source_none ():
154- mock_mtls = mock .Mock (spec = ["has_default_client_cert_source" , "default_client_cert_source" ])
160+ mock_mtls = mock .Mock (
161+ spec = ["has_default_client_cert_source" , "default_client_cert_source" ]
162+ )
155163 mock_mtls .has_default_client_cert_source .return_value = False
156164 with mock .patch ("google.api_core.gapic_v1.config.mtls" , mock_mtls ):
157165 with pytest .raises (
@@ -168,10 +176,15 @@ def test_get_client_cert_source_use_cert_flag_false():
168176
169177
170178def test_read_environment_variables ():
171- with mock .patch ("google.api_core.gapic_v1.config.use_client_cert_effective" , return_value = True ):
179+ with mock .patch (
180+ "google.api_core.gapic_v1.config.use_client_cert_effective" , return_value = True
181+ ):
172182 with mock .patch .dict (
173183 os .environ ,
174- {"GOOGLE_API_USE_MTLS_ENDPOINT" : "always" , "GOOGLE_CLOUD_UNIVERSE_DOMAIN" : "my-universe.com" }
184+ {
185+ "GOOGLE_API_USE_MTLS_ENDPOINT" : "always" ,
186+ "GOOGLE_CLOUD_UNIVERSE_DOMAIN" : "my-universe.com" ,
187+ },
175188 ):
176189 use_cert , use_mtls , universe = config .read_environment_variables ()
177190 assert use_cert is True
@@ -180,7 +193,9 @@ def test_read_environment_variables():
180193
181194
182195def test_read_environment_variables_invalid_mtls ():
183- with mock .patch ("google.api_core.gapic_v1.config.use_client_cert_effective" , return_value = True ):
196+ with mock .patch (
197+ "google.api_core.gapic_v1.config.use_client_cert_effective" , return_value = True
198+ ):
184199 with mock .patch .dict (os .environ , {"GOOGLE_API_USE_MTLS_ENDPOINT" : "invalid" }):
185200 with pytest .raises (MutualTLSChannelError ):
186201 config .read_environment_variables ()
0 commit comments