Skip to content

Commit cea44ff

Browse files
committed
clean up
1 parent 1c94581 commit cea44ff

3 files changed

Lines changed: 6 additions & 49 deletions

File tree

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/_compat.py.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ try:
3939
# is different than that of the fallback implementation below. This will be removed once
4040
# we bump the minimum supported version of google-auth.
4141
from google.auth.transport.mtls import should_use_client_cert # type: ignore
42-
except ImportError: # pragma: no cover
43-
def should_use_client_cert() -> bool: # type: ignore
42+
except ImportError: # pragma: NO COVER
43+
def should_use_client_cert():
4444
"""Returns whether client certificate should be used for mTLS."""
4545
use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower()
4646
if use_client_cert not in ("true", "false"):
4747
raise ValueError(
4848
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
4949
" either `true` or `false`"
5050
)
51-
return use_client_cert == "true"
51+
return use_client_cert == "true"
5252

5353
DEFAULT_UNIVERSE = "googleapis.com"
5454

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -168,50 +168,6 @@ def set_event_loop():
168168
asyncio.set_event_loop(None)
169169

170170

171-
def test__read_environment_variables():
172-
assert {{ service.client_name }}._read_environment_variables() == (False, "auto", None)
173-
174-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
175-
assert {{ service.client_name }}._read_environment_variables() == (True, "auto", None)
176-
177-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}):
178-
assert {{ service.client_name }}._read_environment_variables() == (False, "auto", None)
179-
180-
with mock.patch.dict(
181-
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
182-
):
183-
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
184-
with pytest.raises(ValueError) as excinfo:
185-
{{ service.client_name }}._read_environment_variables()
186-
assert (
187-
str(excinfo.value)
188-
== "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
189-
)
190-
else:
191-
assert {{ service.client_name }}._read_environment_variables() == (
192-
False,
193-
"auto",
194-
None,
195-
)
196-
197-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
198-
assert {{ service.client_name }}._read_environment_variables() == (False, "never", None)
199-
200-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}):
201-
assert {{ service.client_name }}._read_environment_variables() == (False, "always", None)
202-
203-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}):
204-
assert {{ service.client_name }}._read_environment_variables() == (False, "auto", None)
205-
206-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}):
207-
with pytest.raises(MutualTLSChannelError) as excinfo:
208-
{{ service.client_name }}._read_environment_variables()
209-
assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
210-
211-
with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}):
212-
assert {{ service.client_name }}._read_environment_variables() == (False, "auto", "foo.com")
213-
214-
215171
def test__get_client_cert_source():
216172
mock_provided_cert_source = mock.Mock()
217173
mock_default_cert_source = mock.Mock()

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_compat.py.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ def test_should_use_client_cert_fallback_env():
246246
assert universe.should_use_client_cert() is False
247247

248248
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "invalid"}, clear=True):
249-
with pytest.raises(ValueError, match="Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"):
250-
universe.should_use_client_cert()
249+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
250+
with pytest.raises(ValueError, match="Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"):
251+
universe.should_use_client_cert()
251252

252253
{% if has_auto_populated_fields %}
253254

0 commit comments

Comments
 (0)