Skip to content

Commit

Permalink
fix unit tests and address more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmayr committed Oct 7, 2024
1 parent 1913c76 commit 80e27e4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def __init__(
are specified, the client will attempt to ascertain the
credentials from the environment.
transport (Union[str, OperationsTransport]): The
transport to use. If set to None, a transport is chosen
automatically.
transport to use. If set to None, this defaults to 'rest_asyncio'.
client_options (google.api_core.client_options.ClientOptions): Custom options for the
client. It won't take effect if a ``transport`` instance is provided.
(1) The ``api_endpoint`` property can be used to override the
Expand Down
49 changes: 10 additions & 39 deletions google/api_core/operations_v1/abstract_operations_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from typing import Dict, Optional, Type, Union

from google.api_core import client_options as client_options_lib # type: ignore
from google.api_core import exceptions as core_exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core.operations_v1.transports.base import (
DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -359,41 +358,13 @@ def __init__(
self._transport = transport
else:
Transport = type(self).get_transport_class(transport)
# NOTE: The conditional logic below to initialize the transport can be removed
# once we have feature parity with the sync transport.
if "async" in str(Transport).lower():
unsupported_params = {
# TODO(https://github.com/googleapis/python-api-core/issues/715): Add support for `credentials_file` to async REST transport.
"google.api_core.client_options.ClientOptions.credentials_file": client_options.credentials_file,
# TODO(https://github.com/googleapis/python-api-core/issues/716): Add support for `scopes` to async REST transport.
"google.api_core.client_options.ClientOptions.scopes": client_options.scopes,
# TODO(https://github.com/googleapis/python-api-core/issues/717): Add support for `quota_project_id` to async REST transport.
"google.api_core.client_options.ClientOptions.quota_project_id": client_options.quota_project_id,
# TODO(https://github.com/googleapis/python-api-core/issues/718): Add support for `client_cert_source` to async REST transport.
"google.api_core.client_options.ClientOptions.client_cert_source": client_options.client_cert_source,
}
provided_unsupported_params = [
name
for name, value in unsupported_params.items()
if value is not None
]
if provided_unsupported_params:
raise core_exceptions.AsyncRestUnsupportedParameterError(
f"The following provided parameters are not supported for `transport=rest_asyncio`: {', '.join(provided_unsupported_params)}"
)
self._transport = Transport(
credentials=credentials,
host=api_endpoint,
client_info=client_info,
)
else:
self._transport = Transport(
credentials=credentials,
credentials_file=client_options.credentials_file,
host=api_endpoint,
scopes=client_options.scopes,
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
)
self._transport = Transport(
credentials=credentials,
credentials_file=client_options.credentials_file,
host=api_endpoint,
scopes=client_options.scopes,
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
)
35 changes: 30 additions & 5 deletions google/api_core/operations_v1/transports/rest_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ def __init__(
*,
host: str = "longrunning.googleapis.com",
credentials: Optional[ga_credentials_async.Credentials] = None,
credentials_file: Optional[str] = None,
scopes: Optional[Sequence[str]] = None,
client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
quota_project_id: Optional[str] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
always_use_jwt_access: Optional[bool] = False,
url_scheme: str = "https",
http_options: Optional[Dict] = None,
path_prefix: str = "v1",
# TODO(https://github.com/googleapis/python-api-core/issues/715): Add support for `credentials_file` to async REST transport.
# TODO(https://github.com/googleapis/python-api-core/issues/716): Add support for `scopes` to async REST transport.
# TODO(https://github.com/googleapis/python-api-core/issues/717): Add support for `quota_project_id` to async REST transport.
# TODO(https://github.com/googleapis/python-api-core/issues/718): Add support for `client_cert_source` to async REST transport.
# TODO(https://github.com/googleapis/python-api-core/issues/715): Add docstring for `credentials_file` to async REST transport.
# TODO(https://github.com/googleapis/python-api-core/issues/716): Add docstring for `scopes` to async REST transport.
# TODO(https://github.com/googleapis/python-api-core/issues/717): Add docstring for `quota_project_id` to async REST transport.
# TODO(https://github.com/googleapis/python-api-core/issues/718): Add docstring for `client_cert_source` to async REST transport.
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -109,12 +113,33 @@ def __init__(
"v1" by default.
"""
unsupported_params = {
# TODO(https://github.com/googleapis/python-api-core/issues/715): Add support for `credentials_file` to async REST transport.
"google.api_core.client_options.ClientOptions.credentials_file": credentials_file,
# TODO(https://github.com/googleapis/python-api-core/issues/716): Add support for `scopes` to async REST transport.
"google.api_core.client_options.ClientOptions.scopes": scopes,
# TODO(https://github.com/googleapis/python-api-core/issues/717): Add support for `quota_project_id` to async REST transport.
"google.api_core.client_options.ClientOptions.quota_project_id": quota_project_id,
# TODO(https://github.com/googleapis/python-api-core/issues/718): Add support for `client_cert_source` to async REST transport.
"google.api_core.client_options.ClientOptions.client_cert_source": client_cert_source_for_mtls,
# TODO(https://github.com/googleapis/python-api-core/issues/718): Add support for `client_cert_source` to async REST transport.
"google.api_core.client_options.ClientOptions.client_cert_source": client_cert_source_for_mtls,
}
provided_unsupported_params = [
name for name, value in unsupported_params.items() if value is not None
]
if provided_unsupported_params:
raise core_exceptions.AsyncRestUnsupportedParameterError(
f"The following provided parameters are not supported for `transport=rest_asyncio`: {', '.join(provided_unsupported_params)}"
)

super().__init__(
host=host,
# TODO(https://github.com/googleapis/python-api-core/issues/709): Remove `type: ignore` when the linked issue is resolved.
credentials=credentials, # type: ignore
client_info=client_info,
always_use_jwt_access=always_use_jwt_access,
# TODO(https://github.com/googleapis/python-api-core/issues/725): Set always_use_jwt_access token when supported.
always_use_jwt_access=False,
)
# TODO(https://github.com/googleapis/python-api-core/issues/708): add support for
# `default_host` in AsyncAuthorizedSession for feature parity with the synchronous
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/operations_v1/test_operations_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import mock
import pytest
from typing import Any
from typing import Any, List

try:
import grpc # noqa: F401
Expand Down Expand Up @@ -68,7 +68,7 @@
],
}

CLIENTS: list[Any] = [
CLIENTS: List[Any] = [
AbstractOperationsClient,
]
CLIENTS_WITH_TRANSPORT = [
Expand Down

0 comments on commit 80e27e4

Please sign in to comment.