Skip to content

Commit 4f3671c

Browse files
committed
fix incorrect tests
1 parent daec685 commit 4f3671c

File tree

4 files changed

+178
-94
lines changed

4 files changed

+178
-94
lines changed

google/api_core/operations_v1/abstract_operations_async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(
9898
"""
9999
super().__init__(
100100
credentials=credentials, # type: ignore
101-
transport=transport,
101+
transport=transport or "rest_asyncio",
102102
client_options=client_options,
103103
client_info=client_info,
104104
)

google/api_core/operations_v1/abstract_operations_base_client.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Dict, Optional, Type, Union
2020

2121
from google.api_core import client_options as client_options_lib # type: ignore
22+
from google.api_core import exceptions as core_exceptions # type: ignore
2223
from google.api_core import gapic_v1 # type: ignore
2324
from google.api_core.operations_v1.transports.base import (
2425
DEFAULT_CLIENT_INFO,
@@ -39,7 +40,6 @@
3940
from google.auth import credentials as ga_credentials # type: ignore
4041
from google.auth.exceptions import MutualTLSChannelError # type: ignore
4142
from google.auth.transport import mtls # type: ignore
42-
from google.oauth2 import service_account # type: ignore
4343

4444

4545
class AbstractOperationsBaseClientMeta(type):
@@ -143,9 +143,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs):
143143
Returns:
144144
AbstractOperationsClient: The constructed client.
145145
"""
146-
credentials = service_account.Credentials.from_service_account_info(info)
147-
kwargs["credentials"] = credentials
148-
return cls(*args, **kwargs)
146+
raise NotImplementedError("`from_service_account_info` is not implemented.")
149147

150148
@classmethod
151149
def from_service_account_file(cls, filename: str, *args, **kwargs):
@@ -161,9 +159,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
161159
Returns:
162160
AbstractOperationsClient: The constructed client.
163161
"""
164-
credentials = service_account.Credentials.from_service_account_file(filename)
165-
kwargs["credentials"] = credentials
166-
return cls(*args, **kwargs)
162+
raise NotImplementedError("`from_service_account_file` is not implemented.")
167163

168164
from_service_account_json = from_service_account_file
169165

@@ -362,15 +358,38 @@ def __init__(
362358
)
363359
self._transport = transport
364360
else:
365-
# TODO (WIP): This code block will fail becuase async rest layer does not support all params.
366361
Transport = type(self).get_transport_class(transport)
367-
self._transport = Transport(
368-
credentials=credentials,
369-
credentials_file=client_options.credentials_file,
370-
host=api_endpoint,
371-
scopes=client_options.scopes,
372-
client_cert_source_for_mtls=client_cert_source_func,
373-
quota_project_id=client_options.quota_project_id,
374-
client_info=client_info,
375-
always_use_jwt_access=True,
376-
)
362+
if "async" in str(Transport).lower():
363+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2136): Support the following parameters in async rest.
364+
unsupported_params = {
365+
"google.api_core.client_options.ClientOptions.credentials_file": client_options.credentials_file,
366+
"google.api_core.client_options.ClientOptions.scopes": client_options.scopes,
367+
"google.api_core.client_options.ClientOptions.quota_project_id": client_options.quota_project_id,
368+
"google.api_core.client_options.ClientOptions.client_cert_source": client_options.client_cert_source,
369+
"google.api_core.client_options.ClientOptions.api_audience": client_options.api_audience,
370+
}
371+
provided_unsupported_params = [
372+
name
373+
for name, value in unsupported_params.items()
374+
if value is not None
375+
]
376+
if provided_unsupported_params:
377+
raise core_exceptions.AsyncRestUnsupportedParameterError(
378+
f"The following provided parameters are not supported for `transport=rest_asyncio`: {', '.join(provided_unsupported_params)}"
379+
)
380+
self._transport = Transport(
381+
credentials=credentials,
382+
host=api_endpoint,
383+
client_info=client_info,
384+
)
385+
else:
386+
self._transport = Transport(
387+
credentials=credentials,
388+
credentials_file=client_options.credentials_file,
389+
host=api_endpoint,
390+
scopes=client_options.scopes,
391+
client_cert_source_for_mtls=client_cert_source_func,
392+
quota_project_id=client_options.quota_project_id,
393+
client_info=client_info,
394+
always_use_jwt_access=True,
395+
)

google/api_core/operations_v1/abstract_operations_client.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929
from google.auth import credentials as ga_credentials # type: ignore
3030
from google.longrunning import operations_pb2
31+
from google.oauth2 import service_account # type: ignore
3132
import grpc
3233

3334
OptionalRetry = Union[retries.Retry, object]
@@ -98,6 +99,43 @@ def __init__(
9899
client_info=client_info,
99100
)
100101

102+
@classmethod
103+
def from_service_account_info(cls, info: dict, *args, **kwargs):
104+
"""Creates an instance of this client using the provided credentials
105+
info.
106+
107+
Args:
108+
info (dict): The service account private key info.
109+
args: Additional arguments to pass to the constructor.
110+
kwargs: Additional arguments to pass to the constructor.
111+
112+
Returns:
113+
AbstractOperationsClient: The constructed client.
114+
"""
115+
credentials = service_account.Credentials.from_service_account_info(info)
116+
kwargs["credentials"] = credentials
117+
return cls(*args, **kwargs)
118+
119+
@classmethod
120+
def from_service_account_file(cls, filename: str, *args, **kwargs):
121+
"""Creates an instance of this client using the provided credentials
122+
file.
123+
124+
Args:
125+
filename (str): The path to the service account private key json
126+
file.
127+
args: Additional arguments to pass to the constructor.
128+
kwargs: Additional arguments to pass to the constructor.
129+
130+
Returns:
131+
AbstractOperationsClient: The constructed client.
132+
"""
133+
credentials = service_account.Credentials.from_service_account_file(filename)
134+
kwargs["credentials"] = credentials
135+
return cls(*args, **kwargs)
136+
137+
from_service_account_json = from_service_account_file
138+
101139
def list_operations(
102140
self,
103141
name: str,

0 commit comments

Comments
 (0)