diff --git a/google/cloud/servicecontrol_v1/services/quota_controller/async_client.py b/google/cloud/servicecontrol_v1/services/quota_controller/async_client.py index 49a268d..d91c49b 100644 --- a/google/cloud/servicecontrol_v1/services/quota_controller/async_client.py +++ b/google/cloud/servicecontrol_v1/services/quota_controller/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.servicecontrol_v1.types import metric_value from google.cloud.servicecontrol_v1.types import quota_controller from .transports.base import QuotaControllerTransport, DEFAULT_CLIENT_INFO @@ -165,9 +167,9 @@ def __init__( async def allocate_quota( self, - request: quota_controller.AllocateQuotaRequest = None, + request: Union[quota_controller.AllocateQuotaRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> quota_controller.AllocateQuotaResponse: @@ -185,7 +187,7 @@ async def allocate_quota( functionality. Args: - request (:class:`google.cloud.servicecontrol_v1.types.AllocateQuotaRequest`): + request (Union[google.cloud.servicecontrol_v1.types.AllocateQuotaRequest, dict]): The request object. Request message for the AllocateQuota method. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/servicecontrol_v1/services/quota_controller/client.py b/google/cloud/servicecontrol_v1/services/quota_controller/client.py index b2a4e64..cb4e64b 100644 --- a/google/cloud/servicecontrol_v1/services/quota_controller/client.py +++ b/google/cloud/servicecontrol_v1/services/quota_controller/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.servicecontrol_v1.types import metric_value from google.cloud.servicecontrol_v1.types import quota_controller from .transports.base import QuotaControllerTransport, DEFAULT_CLIENT_INFO @@ -339,7 +341,7 @@ def allocate_quota( self, request: Union[quota_controller.AllocateQuotaRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> quota_controller.AllocateQuotaResponse: diff --git a/google/cloud/servicecontrol_v1/services/quota_controller/transports/base.py b/google/cloud/servicecontrol_v1/services/quota_controller/transports/base.py index 3257a28..a3e7ff7 100644 --- a/google/cloud/servicecontrol_v1/services/quota_controller/transports/base.py +++ b/google/cloud/servicecontrol_v1/services/quota_controller/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 @@ -37,15 +36,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 QuotaControllerTransport(abc.ABC): """Abstract transport class for QuotaController.""" @@ -98,7 +88,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 @@ -131,29 +121,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/servicecontrol_v1/services/quota_controller/transports/grpc_asyncio.py b/google/cloud/servicecontrol_v1/services/quota_controller/transports/grpc_asyncio.py index a513a09..e25b311 100644 --- a/google/cloud/servicecontrol_v1/services/quota_controller/transports/grpc_asyncio.py +++ b/google/cloud/servicecontrol_v1/services/quota_controller/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/servicecontrol_v1/services/service_controller/async_client.py b/google/cloud/servicecontrol_v1/services/service_controller/async_client.py index fbcc3ee..1f13c8a 100644 --- a/google/cloud/servicecontrol_v1/services/service_controller/async_client.py +++ b/google/cloud/servicecontrol_v1/services/service_controller/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.servicecontrol_v1.types import check_error from google.cloud.servicecontrol_v1.types import service_controller from .transports.base import ServiceControllerTransport, DEFAULT_CLIENT_INFO @@ -165,9 +167,9 @@ def __init__( async def check( self, - request: service_controller.CheckRequest = None, + request: Union[service_controller.CheckRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> service_controller.CheckResponse: @@ -192,7 +194,7 @@ async def check( `Cloud IAM `__. Args: - request (:class:`google.cloud.servicecontrol_v1.types.CheckRequest`): + request (Union[google.cloud.servicecontrol_v1.types.CheckRequest, dict]): The request object. Request message for the Check method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -235,9 +237,9 @@ async def check( async def report( self, - request: service_controller.ReportRequest = None, + request: Union[service_controller.ReportRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> service_controller.ReportResponse: @@ -261,7 +263,7 @@ async def report( `Google Cloud IAM `__. Args: - request (:class:`google.cloud.servicecontrol_v1.types.ReportRequest`): + request (Union[google.cloud.servicecontrol_v1.types.ReportRequest, dict]): The request object. Request message for the Report method. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/servicecontrol_v1/services/service_controller/client.py b/google/cloud/servicecontrol_v1/services/service_controller/client.py index 0ab18a6..3b5f129 100644 --- a/google/cloud/servicecontrol_v1/services/service_controller/client.py +++ b/google/cloud/servicecontrol_v1/services/service_controller/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.servicecontrol_v1.types import check_error from google.cloud.servicecontrol_v1.types import service_controller from .transports.base import ServiceControllerTransport, DEFAULT_CLIENT_INFO @@ -341,7 +343,7 @@ def check( self, request: Union[service_controller.CheckRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> service_controller.CheckResponse: @@ -403,7 +405,7 @@ def report( self, request: Union[service_controller.ReportRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> service_controller.ReportResponse: diff --git a/google/cloud/servicecontrol_v1/services/service_controller/transports/base.py b/google/cloud/servicecontrol_v1/services/service_controller/transports/base.py index c6559eb..07eb753 100644 --- a/google/cloud/servicecontrol_v1/services/service_controller/transports/base.py +++ b/google/cloud/servicecontrol_v1/services/service_controller/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 @@ -37,15 +36,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 ServiceControllerTransport(abc.ABC): """Abstract transport class for ServiceController.""" @@ -98,7 +88,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 @@ -131,29 +121,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/servicecontrol_v1/services/service_controller/transports/grpc_asyncio.py b/google/cloud/servicecontrol_v1/services/service_controller/transports/grpc_asyncio.py index 5dbd054..46f953d 100644 --- a/google/cloud/servicecontrol_v1/services/service_controller/transports/grpc_asyncio.py +++ b/google/cloud/servicecontrol_v1/services/service_controller/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/servicecontrol_v1/types/distribution.py b/google/cloud/servicecontrol_v1/types/distribution.py index b8ea164..22c57bd 100644 --- a/google/cloud/servicecontrol_v1/types/distribution.py +++ b/google/cloud/servicecontrol_v1/types/distribution.py @@ -34,6 +34,13 @@ class Distribution(proto.Message): variance - a histogram of the values of the sample points + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: count (int): The total number of samples in the @@ -68,10 +75,13 @@ class Distribution(proto.Message): Any suffix of trailing zeros may be omitted. linear_buckets (google.cloud.servicecontrol_v1.types.Distribution.LinearBuckets): Buckets with constant width. + This field is a member of `oneof`_ ``bucket_option``. exponential_buckets (google.cloud.servicecontrol_v1.types.Distribution.ExponentialBuckets): Buckets with exponentially growing width. + This field is a member of `oneof`_ ``bucket_option``. explicit_buckets (google.cloud.servicecontrol_v1.types.Distribution.ExplicitBuckets): Buckets with arbitrary user-provided width. + This field is a member of `oneof`_ ``bucket_option``. exemplars (Sequence[google.api.distribution_pb2.Exemplar]): Example points. Must be in increasing order of ``value`` field. diff --git a/google/cloud/servicecontrol_v1/types/log_entry.py b/google/cloud/servicecontrol_v1/types/log_entry.py index 0ac9e95..dc8ec7f 100644 --- a/google/cloud/servicecontrol_v1/types/log_entry.py +++ b/google/cloud/servicecontrol_v1/types/log_entry.py @@ -31,6 +31,13 @@ class LogEntry(proto.Message): r"""An individual log entry. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): Required. The log to which this log entry belongs. Examples: @@ -63,12 +70,15 @@ class LogEntry(proto.Message): The log entry payload, represented as a protocol buffer that is expressed as a JSON object. The only accepted type currently is [AuditLog][google.cloud.audit.AuditLog]. + This field is a member of `oneof`_ ``payload``. text_payload (str): The log entry payload, represented as a Unicode string (UTF-8). + This field is a member of `oneof`_ ``payload``. struct_payload (google.protobuf.struct_pb2.Struct): The log entry payload, represented as a structure that is expressed as a JSON object. + This field is a member of `oneof`_ ``payload``. operation (google.cloud.servicecontrol_v1.types.LogEntryOperation): Optional. Information about an operation associated with the log entry, if applicable. diff --git a/google/cloud/servicecontrol_v1/types/metric_value.py b/google/cloud/servicecontrol_v1/types/metric_value.py index 9f1e628..ed11979 100644 --- a/google/cloud/servicecontrol_v1/types/metric_value.py +++ b/google/cloud/servicecontrol_v1/types/metric_value.py @@ -27,6 +27,13 @@ class MetricValue(proto.Message): r"""Represents a single metric value. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: labels (Sequence[google.cloud.servicecontrol_v1.types.MetricValue.LabelsEntry]): The labels describing the metric value. See comments on @@ -48,14 +55,19 @@ class MetricValue(proto.Message): will be used. bool_value (bool): A boolean value. + This field is a member of `oneof`_ ``value``. int64_value (int): A signed 64-bit integer value. + This field is a member of `oneof`_ ``value``. double_value (float): A double precision floating point value. + This field is a member of `oneof`_ ``value``. string_value (str): A text string value. + This field is a member of `oneof`_ ``value``. distribution_value (google.cloud.servicecontrol_v1.types.Distribution): A distribution value. + This field is a member of `oneof`_ ``value``. """ labels = proto.MapField(proto.STRING, proto.STRING, number=1,) diff --git a/setup.py b/setup.py index 074a894..f6d1288 100644 --- a/setup.py +++ b/setup.py @@ -28,10 +28,9 @@ # 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", "libcst >= 0.2.5", "proto-plus >= 1.15.0", - "packaging >= 14.3", ] package_root = os.path.abspath(os.path.dirname(__file__)) diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 316c3c5..d5ee700 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,8 +5,6 @@ # # 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 libcst==0.2.5 proto-plus==1.15.0 -packaging==14.3 -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is transitively required through google-auth diff --git a/tests/unit/gapic/servicecontrol_v1/test_quota_controller.py b/tests/unit/gapic/servicecontrol_v1/test_quota_controller.py index 9f4ae58..3022024 100644 --- a/tests/unit/gapic/servicecontrol_v1/test_quota_controller.py +++ b/tests/unit/gapic/servicecontrol_v1/test_quota_controller.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ QuotaControllerClient, ) from google.cloud.servicecontrol_v1.services.quota_controller import transports -from google.cloud.servicecontrol_v1.services.quota_controller.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.servicecontrol_v1.types import distribution as gas_distribution from google.cloud.servicecontrol_v1.types import metric_value from google.cloud.servicecontrol_v1.types import quota_controller @@ -52,20 +48,6 @@ 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" @@ -222,7 +204,7 @@ def test_quota_controller_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, @@ -239,7 +221,7 @@ def test_quota_controller_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, @@ -256,7 +238,7 @@ def test_quota_controller_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, @@ -285,7 +267,7 @@ def test_quota_controller_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, @@ -354,7 +336,7 @@ def test_quota_controller_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 @@ -396,7 +378,7 @@ def test_quota_controller_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, @@ -418,7 +400,7 @@ def test_quota_controller_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, @@ -449,7 +431,7 @@ def test_quota_controller_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, @@ -480,7 +462,7 @@ def test_quota_controller_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", @@ -707,7 +689,6 @@ def test_quota_controller_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_quota_controller_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -731,29 +712,6 @@ def test_quota_controller_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_quota_controller_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.servicecontrol_v1.services.quota_controller.transports.QuotaControllerTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.QuotaControllerTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/servicecontrol", - ), - quota_project_id="octopus", - ) - - def test_quota_controller_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( @@ -765,7 +723,6 @@ def test_quota_controller_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_quota_controller_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -781,21 +738,6 @@ def test_quota_controller_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_quota_controller_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) - QuotaControllerClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/servicecontrol", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -803,7 +745,6 @@ def test_quota_controller_auth_adc_old_google_auth(): transports.QuotaControllerGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_quota_controller_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -820,29 +761,6 @@ def test_quota_controller_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.QuotaControllerGrpcTransport, - transports.QuotaControllerGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_quota_controller_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", - "https://www.googleapis.com/auth/servicecontrol", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/servicecontrol_v1/test_service_controller.py b/tests/unit/gapic/servicecontrol_v1/test_service_controller.py index 3e2934d..4b068e8 100644 --- a/tests/unit/gapic/servicecontrol_v1/test_service_controller.py +++ b/tests/unit/gapic/servicecontrol_v1/test_service_controller.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ServiceControllerClient, ) from google.cloud.servicecontrol_v1.services.service_controller import transports -from google.cloud.servicecontrol_v1.services.service_controller.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.servicecontrol_v1.types import check_error from google.cloud.servicecontrol_v1.types import distribution as gas_distribution from google.cloud.servicecontrol_v1.types import http_request @@ -59,20 +55,6 @@ 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" @@ -230,7 +212,7 @@ def test_service_controller_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, @@ -247,7 +229,7 @@ def test_service_controller_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, @@ -264,7 +246,7 @@ def test_service_controller_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, @@ -293,7 +275,7 @@ def test_service_controller_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, @@ -362,7 +344,7 @@ def test_service_controller_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 @@ -404,7 +386,7 @@ def test_service_controller_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, @@ -426,7 +408,7 @@ def test_service_controller_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, @@ -457,7 +439,7 @@ def test_service_controller_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, @@ -488,7 +470,7 @@ def test_service_controller_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", @@ -807,7 +789,6 @@ def test_service_controller_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_service_controller_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -831,29 +812,6 @@ def test_service_controller_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_service_controller_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.servicecontrol_v1.services.service_controller.transports.ServiceControllerTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ServiceControllerTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/servicecontrol", - ), - quota_project_id="octopus", - ) - - def test_service_controller_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( @@ -865,7 +823,6 @@ def test_service_controller_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_service_controller_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -881,21 +838,6 @@ def test_service_controller_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_service_controller_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) - ServiceControllerClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/servicecontrol", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -903,7 +845,6 @@ def test_service_controller_auth_adc_old_google_auth(): transports.ServiceControllerGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_service_controller_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -920,29 +861,6 @@ def test_service_controller_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ServiceControllerGrpcTransport, - transports.ServiceControllerGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_service_controller_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", - "https://www.googleapis.com/auth/servicecontrol", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [