From 0c7a85ac69671d2acecd50c10cd2fc975539ebb6 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 11:02:12 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#141) - [ ] Regenerate this pull request now. docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency committer: busunkim96@ PiperOrigin-RevId: 406468269 Source-Link: https://github.com/googleapis/googleapis/commit/83d81b0c8fc22291a13398d6d77f02dc97a5b6f4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9 --- .../services/web_risk_service/async_client.py | 28 +++--- .../services/web_risk_service/client.py | 10 +- .../web_risk_service/transports/base.py | 35 +------ .../transports/grpc_asyncio.py | 1 - .../web_risk_service_v1_beta1/async_client.py | 22 +++-- .../web_risk_service_v1_beta1/client.py | 8 +- .../transports/base.py | 35 +------ .../transports/grpc_asyncio.py | 1 - setup.py | 3 +- testing/constraints-3.6.txt | 6 +- .../gapic/webrisk_v1/test_web_risk_service.py | 91 ++----------------- .../test_web_risk_service_v1_beta1.py | 91 ++----------------- 12 files changed, 60 insertions(+), 271 deletions(-) diff --git a/google/cloud/webrisk_v1/services/web_risk_service/async_client.py b/google/cloud/webrisk_v1/services/web_risk_service/async_client.py index e31e34e..ded42ff 100644 --- a/google/cloud/webrisk_v1/services/web_risk_service/async_client.py +++ b/google/cloud/webrisk_v1/services/web_risk_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # 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 import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.webrisk_v1.types import webrisk from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebRiskServiceTransport, DEFAULT_CLIENT_INFO @@ -163,12 +165,12 @@ def __init__( async def compute_threat_list_diff( self, - request: webrisk.ComputeThreatListDiffRequest = None, + request: Union[webrisk.ComputeThreatListDiffRequest, dict] = None, *, threat_type: webrisk.ThreatType = None, version_token: bytes = None, constraints: webrisk.ComputeThreatListDiffRequest.Constraints = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.ComputeThreatListDiffResponse: @@ -182,7 +184,7 @@ async def compute_threat_list_diff( once for each list. Args: - request (:class:`google.cloud.webrisk_v1.types.ComputeThreatListDiffRequest`): + request (Union[google.cloud.webrisk_v1.types.ComputeThreatListDiffRequest, dict]): The request object. Describes an API diff request. threat_type (:class:`google.cloud.webrisk_v1.types.ThreatType`): Required. The threat list to update. @@ -270,11 +272,11 @@ async def compute_threat_list_diff( async def search_uris( self, - request: webrisk.SearchUrisRequest = None, + request: Union[webrisk.SearchUrisRequest, dict] = None, *, uri: str = None, threat_types: Sequence[webrisk.ThreatType] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchUrisResponse: @@ -286,7 +288,7 @@ async def search_uris( response will be returned. Args: - request (:class:`google.cloud.webrisk_v1.types.SearchUrisRequest`): + request (Union[google.cloud.webrisk_v1.types.SearchUrisRequest, dict]): The request object. Request to check URI entries against threatLists. uri (:class:`str`): @@ -359,11 +361,11 @@ async def search_uris( async def search_hashes( self, - request: webrisk.SearchHashesRequest = None, + request: Union[webrisk.SearchHashesRequest, dict] = None, *, hash_prefix: bytes = None, threat_types: Sequence[webrisk.ThreatType] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchHashesResponse: @@ -375,7 +377,7 @@ async def search_hashes( match of a threat. Args: - request (:class:`google.cloud.webrisk_v1.types.SearchHashesRequest`): + request (Union[google.cloud.webrisk_v1.types.SearchHashesRequest, dict]): The request object. Request to return full hashes matched by the provided hash prefixes. hash_prefix (:class:`bytes`): @@ -450,11 +452,11 @@ async def search_hashes( async def create_submission( self, - request: webrisk.CreateSubmissionRequest = None, + request: Union[webrisk.CreateSubmissionRequest, dict] = None, *, parent: str = None, submission: webrisk.Submission = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.Submission: @@ -468,7 +470,7 @@ async def create_submission( visibility can use this method. Args: - request (:class:`google.cloud.webrisk_v1.types.CreateSubmissionRequest`): + request (Union[google.cloud.webrisk_v1.types.CreateSubmissionRequest, dict]): The request object. Request to send a potentially phishy URI to WebRisk. parent (:class:`str`): diff --git a/google/cloud/webrisk_v1/services/web_risk_service/client.py b/google/cloud/webrisk_v1/services/web_risk_service/client.py index 7dfa4e8..f93474a 100644 --- a/google/cloud/webrisk_v1/services/web_risk_service/client.py +++ b/google/cloud/webrisk_v1/services/web_risk_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.webrisk_v1.types import webrisk from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebRiskServiceTransport, DEFAULT_CLIENT_INFO @@ -340,7 +342,7 @@ def compute_threat_list_diff( threat_type: webrisk.ThreatType = None, version_token: bytes = None, constraints: webrisk.ComputeThreatListDiffRequest.Constraints = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.ComputeThreatListDiffResponse: @@ -436,7 +438,7 @@ def search_uris( *, uri: str = None, threat_types: Sequence[webrisk.ThreatType] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchUrisResponse: @@ -515,7 +517,7 @@ def search_hashes( *, hash_prefix: bytes = None, threat_types: Sequence[webrisk.ThreatType] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchHashesResponse: @@ -596,7 +598,7 @@ def create_submission( *, parent: str = None, submission: webrisk.Submission = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.Submission: diff --git a/google/cloud/webrisk_v1/services/web_risk_service/transports/base.py b/google/cloud/webrisk_v1/services/web_risk_service/transports/base.py index 670c026..f10584f 100644 --- a/google/cloud/webrisk_v1/services/web_risk_service/transports/base.py +++ b/google/cloud/webrisk_v1/services/web_risk_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -35,15 +34,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class WebRiskServiceTransport(abc.ABC): """Abstract transport class for WebRiskService.""" @@ -93,7 +83,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -126,29 +116,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc_asyncio.py b/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc_asyncio.py index 927b2d7..aea7da4 100644 --- a/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc_asyncio.py +++ b/google/cloud/webrisk_v1/services/web_risk_service/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/async_client.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/async_client.py index 5843475..80f0bd3 100644 --- a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/async_client.py +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # 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 import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.webrisk_v1beta1.types import webrisk from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebRiskServiceV1Beta1Transport, DEFAULT_CLIENT_INFO @@ -166,19 +168,19 @@ def __init__( async def compute_threat_list_diff( self, - request: webrisk.ComputeThreatListDiffRequest = None, + request: Union[webrisk.ComputeThreatListDiffRequest, dict] = None, *, threat_type: webrisk.ThreatType = None, version_token: bytes = None, constraints: webrisk.ComputeThreatListDiffRequest.Constraints = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.ComputeThreatListDiffResponse: r"""Gets the most recent threat list diffs. Args: - request (:class:`google.cloud.webrisk_v1beta1.types.ComputeThreatListDiffRequest`): + request (Union[google.cloud.webrisk_v1beta1.types.ComputeThreatListDiffRequest, dict]): The request object. Describes an API diff request. threat_type (:class:`google.cloud.webrisk_v1beta1.types.ThreatType`): The ThreatList to update. @@ -258,11 +260,11 @@ async def compute_threat_list_diff( async def search_uris( self, - request: webrisk.SearchUrisRequest = None, + request: Union[webrisk.SearchUrisRequest, dict] = None, *, uri: str = None, threat_types: Sequence[webrisk.ThreatType] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchUrisResponse: @@ -270,7 +272,7 @@ async def search_uris( given threatList. Args: - request (:class:`google.cloud.webrisk_v1beta1.types.SearchUrisRequest`): + request (Union[google.cloud.webrisk_v1beta1.types.SearchUrisRequest, dict]): The request object. Request to check URI entries against threatLists. uri (:class:`str`): @@ -342,11 +344,11 @@ async def search_uris( async def search_hashes( self, - request: webrisk.SearchHashesRequest = None, + request: Union[webrisk.SearchHashesRequest, dict] = None, *, hash_prefix: bytes = None, threat_types: Sequence[webrisk.ThreatType] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchHashesResponse: @@ -358,7 +360,7 @@ async def search_hashes( match of a threat. Args: - request (:class:`google.cloud.webrisk_v1beta1.types.SearchHashesRequest`): + request (Union[google.cloud.webrisk_v1beta1.types.SearchHashesRequest, dict]): The request object. Request to return full hashes matched by the provided hash prefixes. hash_prefix (:class:`bytes`): diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/client.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/client.py index 848b44b..6c2b0e7 100644 --- a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/client.py +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.webrisk_v1beta1.types import webrisk from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import WebRiskServiceV1Beta1Transport, DEFAULT_CLIENT_INFO @@ -342,7 +344,7 @@ def compute_threat_list_diff( threat_type: webrisk.ThreatType = None, version_token: bytes = None, constraints: webrisk.ComputeThreatListDiffRequest.Constraints = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.ComputeThreatListDiffResponse: @@ -423,7 +425,7 @@ def search_uris( *, uri: str = None, threat_types: Sequence[webrisk.ThreatType] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchUrisResponse: @@ -497,7 +499,7 @@ def search_hashes( *, hash_prefix: bytes = None, threat_types: Sequence[webrisk.ThreatType] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> webrisk.SearchHashesResponse: diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/base.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/base.py index 3312229..5db2edb 100644 --- a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/base.py +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -35,15 +34,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class WebRiskServiceV1Beta1Transport(abc.ABC): """Abstract transport class for WebRiskServiceV1Beta1.""" @@ -93,7 +83,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -126,29 +116,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc_asyncio.py b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc_asyncio.py index 3f3d446..eb6dea7 100644 --- a/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc_asyncio.py +++ b/google/cloud/webrisk_v1beta1/services/web_risk_service_v1_beta1/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/setup.py b/setup.py index 3350f1e..9b88a5e 100644 --- a/setup.py +++ b/setup.py @@ -32,9 +32,8 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "proto-plus >= 1.10.0", - "packaging >= 14.3", ] extras = {} diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 3ac91c6..da8c573 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,9 +5,5 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.10.0 -packaging==14.3 -# TODO: remove once google-auth>=1.25.0 is required transitively -# through google-api-core>=1.28.0 -google-auth==1.24.0 diff --git a/tests/unit/gapic/webrisk_v1/test_web_risk_service.py b/tests/unit/gapic/webrisk_v1/test_web_risk_service.py index 9ce2589..ee4a483 100644 --- a/tests/unit/gapic/webrisk_v1/test_web_risk_service.py +++ b/tests/unit/gapic/webrisk_v1/test_web_risk_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -35,29 +34,12 @@ from google.cloud.webrisk_v1.services.web_risk_service import WebRiskServiceAsyncClient from google.cloud.webrisk_v1.services.web_risk_service import WebRiskServiceClient from google.cloud.webrisk_v1.services.web_risk_service import transports -from google.cloud.webrisk_v1.services.web_risk_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.webrisk_v1.types import webrisk from google.oauth2 import service_account from google.protobuf import timestamp_pb2 # type: ignore import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -214,7 +196,7 @@ def test_web_risk_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -231,7 +213,7 @@ def test_web_risk_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -248,7 +230,7 @@ def test_web_risk_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -277,7 +259,7 @@ def test_web_risk_service_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -336,7 +318,7 @@ def test_web_risk_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -378,7 +360,7 @@ def test_web_risk_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -400,7 +382,7 @@ def test_web_risk_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -431,7 +413,7 @@ def test_web_risk_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -462,7 +444,7 @@ def test_web_risk_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -1342,7 +1324,6 @@ def test_web_risk_service_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_web_risk_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1363,26 +1344,6 @@ def test_web_risk_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_web_risk_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.webrisk_v1.services.web_risk_service.transports.WebRiskServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.WebRiskServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_web_risk_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1394,7 +1355,6 @@ def test_web_risk_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_web_risk_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1407,18 +1367,6 @@ def test_web_risk_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_web_risk_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - WebRiskServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1426,7 +1374,6 @@ def test_web_risk_service_auth_adc_old_google_auth(): transports.WebRiskServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_web_risk_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1440,26 +1387,6 @@ def test_web_risk_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.WebRiskServiceGrpcTransport, - transports.WebRiskServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_web_risk_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/webrisk_v1beta1/test_web_risk_service_v1_beta1.py b/tests/unit/gapic/webrisk_v1beta1/test_web_risk_service_v1_beta1.py index ea7838d..c593e05 100644 --- a/tests/unit/gapic/webrisk_v1beta1/test_web_risk_service_v1_beta1.py +++ b/tests/unit/gapic/webrisk_v1beta1/test_web_risk_service_v1_beta1.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,29 +38,12 @@ WebRiskServiceV1Beta1Client, ) from google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1 import transports -from google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.webrisk_v1beta1.types import webrisk from google.oauth2 import service_account from google.protobuf import timestamp_pb2 # type: ignore import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -223,7 +205,7 @@ def test_web_risk_service_v1_beta1_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -240,7 +222,7 @@ def test_web_risk_service_v1_beta1_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -257,7 +239,7 @@ def test_web_risk_service_v1_beta1_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -286,7 +268,7 @@ def test_web_risk_service_v1_beta1_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -355,7 +337,7 @@ def test_web_risk_service_v1_beta1_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -397,7 +379,7 @@ def test_web_risk_service_v1_beta1_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -419,7 +401,7 @@ def test_web_risk_service_v1_beta1_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -454,7 +436,7 @@ def test_web_risk_service_v1_beta1_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -489,7 +471,7 @@ def test_web_risk_service_v1_beta1_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -1160,7 +1142,6 @@ def test_web_risk_service_v1_beta1_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_web_risk_service_v1_beta1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1181,26 +1162,6 @@ def test_web_risk_service_v1_beta1_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_web_risk_service_v1_beta1_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.webrisk_v1beta1.services.web_risk_service_v1_beta1.transports.WebRiskServiceV1Beta1Transport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.WebRiskServiceV1Beta1Transport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_web_risk_service_v1_beta1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1212,7 +1173,6 @@ def test_web_risk_service_v1_beta1_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_web_risk_service_v1_beta1_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1225,18 +1185,6 @@ def test_web_risk_service_v1_beta1_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_web_risk_service_v1_beta1_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - WebRiskServiceV1Beta1Client() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1244,7 +1192,6 @@ def test_web_risk_service_v1_beta1_auth_adc_old_google_auth(): transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_web_risk_service_v1_beta1_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1258,26 +1205,6 @@ def test_web_risk_service_v1_beta1_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.WebRiskServiceV1Beta1GrpcTransport, - transports.WebRiskServiceV1Beta1GrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_web_risk_service_v1_beta1_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [