From a1f6c29abe5e7292129fae9d3469f2785ec007ea 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:18:11 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#156) - [ ] 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/cloud_scheduler/async_client.py | 52 ++++++----- .../services/cloud_scheduler/client.py | 18 ++-- .../cloud_scheduler/transports/base.py | 35 +------ .../transports/grpc_asyncio.py | 1 - .../google/cloud/scheduler_v1/types/job.py | 10 ++ .../google/cloud/scheduler_v1/types/target.py | 9 ++ .../services/cloud_scheduler/async_client.py | 52 ++++++----- .../services/cloud_scheduler/client.py | 18 ++-- .../cloud_scheduler/transports/base.py | 35 +------ .../transports/grpc_asyncio.py | 1 - .../cloud/scheduler_v1beta1/types/job.py | 10 ++ .../cloud/scheduler_v1beta1/types/target.py | 9 ++ packages/google-cloud-scheduler/setup.py | 3 +- .../testing/constraints-3.6.txt | 6 +- .../scheduler_v1/test_cloud_scheduler.py | 91 ++----------------- .../scheduler_v1beta1/test_cloud_scheduler.py | 91 ++----------------- 16 files changed, 134 insertions(+), 307 deletions(-) diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/async_client.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/async_client.py index b1303afe3e51..743e36161d58 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/async_client.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/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.scheduler_v1.services.cloud_scheduler import pagers from google.cloud.scheduler_v1.types import cloudscheduler from google.cloud.scheduler_v1.types import job @@ -174,17 +176,17 @@ def __init__( async def list_jobs( self, - request: cloudscheduler.ListJobsRequest = None, + request: Union[cloudscheduler.ListJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListJobsAsyncPager: r"""Lists jobs. Args: - request (:class:`google.cloud.scheduler_v1.types.ListJobsRequest`): + request (Union[google.cloud.scheduler_v1.types.ListJobsRequest, dict]): The request object. Request message for listing jobs using [ListJobs][google.cloud.scheduler.v1.CloudScheduler.ListJobs]. @@ -265,17 +267,17 @@ async def list_jobs( async def get_job( self, - request: cloudscheduler.GetJobRequest = None, + request: Union[cloudscheduler.GetJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: r"""Gets a job. Args: - request (:class:`google.cloud.scheduler_v1.types.GetJobRequest`): + request (Union[google.cloud.scheduler_v1.types.GetJobRequest, dict]): The request object. Request message for [GetJob][google.cloud.scheduler.v1.CloudScheduler.GetJob]. name (:class:`str`): @@ -347,18 +349,18 @@ async def get_job( async def create_job( self, - request: cloudscheduler.CreateJobRequest = None, + request: Union[cloudscheduler.CreateJobRequest, dict] = None, *, parent: str = None, job: gcs_job.Job = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_job.Job: r"""Creates a job. Args: - request (:class:`google.cloud.scheduler_v1.types.CreateJobRequest`): + request (Union[google.cloud.scheduler_v1.types.CreateJobRequest, dict]): The request object. Request message for [CreateJob][google.cloud.scheduler.v1.CloudScheduler.CreateJob]. parent (:class:`str`): @@ -435,11 +437,11 @@ async def create_job( async def update_job( self, - request: cloudscheduler.UpdateJobRequest = None, + request: Union[cloudscheduler.UpdateJobRequest, dict] = None, *, job: gcs_job.Job = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_job.Job: @@ -457,7 +459,7 @@ async def update_job( received. Args: - request (:class:`google.cloud.scheduler_v1.types.UpdateJobRequest`): + request (Union[google.cloud.scheduler_v1.types.UpdateJobRequest, dict]): The request object. Request message for [UpdateJob][google.cloud.scheduler.v1.CloudScheduler.UpdateJob]. job (:class:`google.cloud.scheduler_v1.types.Job`): @@ -533,17 +535,17 @@ async def update_job( async def delete_job( self, - request: cloudscheduler.DeleteJobRequest = None, + request: Union[cloudscheduler.DeleteJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a job. Args: - request (:class:`google.cloud.scheduler_v1.types.DeleteJobRequest`): + request (Union[google.cloud.scheduler_v1.types.DeleteJobRequest, dict]): The request object. Request message for deleting a job using [DeleteJob][google.cloud.scheduler.v1.CloudScheduler.DeleteJob]. @@ -608,10 +610,10 @@ async def delete_job( async def pause_job( self, - request: cloudscheduler.PauseJobRequest = None, + request: Union[cloudscheduler.PauseJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -629,7 +631,7 @@ async def pause_job( to be paused. Args: - request (:class:`google.cloud.scheduler_v1.types.PauseJobRequest`): + request (Union[google.cloud.scheduler_v1.types.PauseJobRequest, dict]): The request object. Request message for [PauseJob][google.cloud.scheduler.v1.CloudScheduler.PauseJob]. name (:class:`str`): @@ -691,10 +693,10 @@ async def pause_job( async def resume_job( self, - request: cloudscheduler.ResumeJobRequest = None, + request: Union[cloudscheduler.ResumeJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -711,7 +713,7 @@ async def resume_job( to be resumed. Args: - request (:class:`google.cloud.scheduler_v1.types.ResumeJobRequest`): + request (Union[google.cloud.scheduler_v1.types.ResumeJobRequest, dict]): The request object. Request message for [ResumeJob][google.cloud.scheduler.v1.CloudScheduler.ResumeJob]. name (:class:`str`): @@ -773,10 +775,10 @@ async def resume_job( async def run_job( self, - request: cloudscheduler.RunJobRequest = None, + request: Union[cloudscheduler.RunJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -785,7 +787,7 @@ async def run_job( dispatch the job, even if the job is already running. Args: - request (:class:`google.cloud.scheduler_v1.types.RunJobRequest`): + request (Union[google.cloud.scheduler_v1.types.RunJobRequest, dict]): The request object. Request message for forcing a job to run now using [RunJob][google.cloud.scheduler.v1.CloudScheduler.RunJob]. diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/client.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/client.py index 7d3dc25ce09e..588cd9c699dd 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/client.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/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.scheduler_v1.services.cloud_scheduler import pagers from google.cloud.scheduler_v1.types import cloudscheduler from google.cloud.scheduler_v1.types import job @@ -372,7 +374,7 @@ def list_jobs( request: Union[cloudscheduler.ListJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListJobsPager: @@ -453,7 +455,7 @@ def get_job( request: Union[cloudscheduler.GetJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -526,7 +528,7 @@ def create_job( *, parent: str = None, job: gcs_job.Job = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_job.Job: @@ -614,7 +616,7 @@ def update_job( *, job: gcs_job.Job = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_job.Job: @@ -711,7 +713,7 @@ def delete_job( request: Union[cloudscheduler.DeleteJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -776,7 +778,7 @@ def pause_job( request: Union[cloudscheduler.PauseJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -859,7 +861,7 @@ def resume_job( request: Union[cloudscheduler.ResumeJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -941,7 +943,7 @@ def run_job( request: Union[cloudscheduler.RunJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/base.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/base.py index 050a17c3a553..9a116cef69ef 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/base.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/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 @@ -38,15 +37,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 CloudSchedulerTransport(abc.ABC): """Abstract transport class for CloudScheduler.""" @@ -96,7 +86,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 @@ -129,29 +119,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/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/grpc_asyncio.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/grpc_asyncio.py index 18a41881e465..bff4a8afbf5f 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/grpc_asyncio.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/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/packages/google-cloud-scheduler/google/cloud/scheduler_v1/types/job.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/types/job.py index 2f8c7c71ac13..8e919e5fc9e4 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/types/job.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/types/job.py @@ -30,6 +30,13 @@ class Job(proto.Message): r"""Configuration for a job. The maximum allowed size for a job is 100KB. + 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): Optionally caller-specified in @@ -62,10 +69,13 @@ class Job(proto.Message): not contain more than 500 characters. pubsub_target (google.cloud.scheduler_v1.types.PubsubTarget): Pub/Sub target. + This field is a member of `oneof`_ ``target``. app_engine_http_target (google.cloud.scheduler_v1.types.AppEngineHttpTarget): App Engine HTTP target. + This field is a member of `oneof`_ ``target``. http_target (google.cloud.scheduler_v1.types.HttpTarget): HTTP target. + This field is a member of `oneof`_ ``target``. schedule (str): Required, except when used with [UpdateJob][google.cloud.scheduler.v1.CloudScheduler.UpdateJob]. diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/types/target.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/types/target.py index 8040a2ec23d2..e2670972ca07 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/types/target.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/types/target.py @@ -51,6 +51,13 @@ class HttpTarget(proto.Message): response constitutes a failed execution. For a redirected request, the response returned by the redirected request is considered. + 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: uri (str): Required. The full URI path that the request will be sent @@ -98,6 +105,7 @@ class HttpTarget(proto.Message): This type of authorization should generally only be used when calling Google APIs hosted on \*.googleapis.com. + This field is a member of `oneof`_ ``authorization_header``. oidc_token (google.cloud.scheduler_v1.types.OidcToken): If specified, an `OIDC `__ @@ -107,6 +115,7 @@ class HttpTarget(proto.Message): This type of authorization can be used for many scenarios, including calling Cloud Run, or endpoints where you intend to validate the token yourself. + This field is a member of `oneof`_ ``authorization_header``. """ uri = proto.Field(proto.STRING, number=1,) diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/async_client.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/async_client.py index db1741e79371..0b6f09d6a6f4 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/async_client.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/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.scheduler_v1beta1.services.cloud_scheduler import pagers from google.cloud.scheduler_v1beta1.types import cloudscheduler from google.cloud.scheduler_v1beta1.types import job @@ -174,17 +176,17 @@ def __init__( async def list_jobs( self, - request: cloudscheduler.ListJobsRequest = None, + request: Union[cloudscheduler.ListJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListJobsAsyncPager: r"""Lists jobs. Args: - request (:class:`google.cloud.scheduler_v1beta1.types.ListJobsRequest`): + request (Union[google.cloud.scheduler_v1beta1.types.ListJobsRequest, dict]): The request object. Request message for listing jobs using [ListJobs][google.cloud.scheduler.v1beta1.CloudScheduler.ListJobs]. @@ -265,17 +267,17 @@ async def list_jobs( async def get_job( self, - request: cloudscheduler.GetJobRequest = None, + request: Union[cloudscheduler.GetJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: r"""Gets a job. Args: - request (:class:`google.cloud.scheduler_v1beta1.types.GetJobRequest`): + request (Union[google.cloud.scheduler_v1beta1.types.GetJobRequest, dict]): The request object. Request message for [GetJob][google.cloud.scheduler.v1beta1.CloudScheduler.GetJob]. name (:class:`str`): @@ -347,18 +349,18 @@ async def get_job( async def create_job( self, - request: cloudscheduler.CreateJobRequest = None, + request: Union[cloudscheduler.CreateJobRequest, dict] = None, *, parent: str = None, job: gcs_job.Job = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_job.Job: r"""Creates a job. Args: - request (:class:`google.cloud.scheduler_v1beta1.types.CreateJobRequest`): + request (Union[google.cloud.scheduler_v1beta1.types.CreateJobRequest, dict]): The request object. Request message for [CreateJob][google.cloud.scheduler.v1beta1.CloudScheduler.CreateJob]. parent (:class:`str`): @@ -436,11 +438,11 @@ async def create_job( async def update_job( self, - request: cloudscheduler.UpdateJobRequest = None, + request: Union[cloudscheduler.UpdateJobRequest, dict] = None, *, job: gcs_job.Job = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_job.Job: @@ -458,7 +460,7 @@ async def update_job( received. Args: - request (:class:`google.cloud.scheduler_v1beta1.types.UpdateJobRequest`): + request (Union[google.cloud.scheduler_v1beta1.types.UpdateJobRequest, dict]): The request object. Request message for [UpdateJob][google.cloud.scheduler.v1beta1.CloudScheduler.UpdateJob]. job (:class:`google.cloud.scheduler_v1beta1.types.Job`): @@ -534,17 +536,17 @@ async def update_job( async def delete_job( self, - request: cloudscheduler.DeleteJobRequest = None, + request: Union[cloudscheduler.DeleteJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a job. Args: - request (:class:`google.cloud.scheduler_v1beta1.types.DeleteJobRequest`): + request (Union[google.cloud.scheduler_v1beta1.types.DeleteJobRequest, dict]): The request object. Request message for deleting a job using [DeleteJob][google.cloud.scheduler.v1beta1.CloudScheduler.DeleteJob]. @@ -609,10 +611,10 @@ async def delete_job( async def pause_job( self, - request: cloudscheduler.PauseJobRequest = None, + request: Union[cloudscheduler.PauseJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -630,7 +632,7 @@ async def pause_job( to be paused. Args: - request (:class:`google.cloud.scheduler_v1beta1.types.PauseJobRequest`): + request (Union[google.cloud.scheduler_v1beta1.types.PauseJobRequest, dict]): The request object. Request message for [PauseJob][google.cloud.scheduler.v1beta1.CloudScheduler.PauseJob]. name (:class:`str`): @@ -702,10 +704,10 @@ async def pause_job( async def resume_job( self, - request: cloudscheduler.ResumeJobRequest = None, + request: Union[cloudscheduler.ResumeJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -722,7 +724,7 @@ async def resume_job( to be resumed. Args: - request (:class:`google.cloud.scheduler_v1beta1.types.ResumeJobRequest`): + request (Union[google.cloud.scheduler_v1beta1.types.ResumeJobRequest, dict]): The request object. Request message for [ResumeJob][google.cloud.scheduler.v1beta1.CloudScheduler.ResumeJob]. name (:class:`str`): @@ -794,10 +796,10 @@ async def resume_job( async def run_job( self, - request: cloudscheduler.RunJobRequest = None, + request: Union[cloudscheduler.RunJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -806,7 +808,7 @@ async def run_job( dispatch the job, even if the job is already running. Args: - request (:class:`google.cloud.scheduler_v1beta1.types.RunJobRequest`): + request (Union[google.cloud.scheduler_v1beta1.types.RunJobRequest, dict]): The request object. Request message for forcing a job to run now using [RunJob][google.cloud.scheduler.v1beta1.CloudScheduler.RunJob]. diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/client.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/client.py index 98725fa66d55..f1a9b24af63f 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/client.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/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.scheduler_v1beta1.services.cloud_scheduler import pagers from google.cloud.scheduler_v1beta1.types import cloudscheduler from google.cloud.scheduler_v1beta1.types import job @@ -372,7 +374,7 @@ def list_jobs( request: Union[cloudscheduler.ListJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListJobsPager: @@ -453,7 +455,7 @@ def get_job( request: Union[cloudscheduler.GetJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -526,7 +528,7 @@ def create_job( *, parent: str = None, job: gcs_job.Job = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_job.Job: @@ -615,7 +617,7 @@ def update_job( *, job: gcs_job.Job = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_job.Job: @@ -712,7 +714,7 @@ def delete_job( request: Union[cloudscheduler.DeleteJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -777,7 +779,7 @@ def pause_job( request: Union[cloudscheduler.PauseJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -860,7 +862,7 @@ def resume_job( request: Union[cloudscheduler.ResumeJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: @@ -942,7 +944,7 @@ def run_job( request: Union[cloudscheduler.RunJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> job.Job: diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/base.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/base.py index a335ee6b88d5..e2586f347916 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/base.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/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 @@ -38,15 +37,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 CloudSchedulerTransport(abc.ABC): """Abstract transport class for CloudScheduler.""" @@ -96,7 +86,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 @@ -129,29 +119,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/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/grpc_asyncio.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/grpc_asyncio.py index 42c53392b397..acda63e7621f 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/grpc_asyncio.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/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/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/types/job.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/types/job.py index bcaf73bdccba..e99d33fedcd1 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/types/job.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/types/job.py @@ -30,6 +30,13 @@ class Job(proto.Message): r"""Configuration for a job. The maximum allowed size for a job is 100KB. + 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): Optionally caller-specified in @@ -62,10 +69,13 @@ class Job(proto.Message): not contain more than 500 characters. pubsub_target (google.cloud.scheduler_v1beta1.types.PubsubTarget): Pub/Sub target. + This field is a member of `oneof`_ ``target``. app_engine_http_target (google.cloud.scheduler_v1beta1.types.AppEngineHttpTarget): App Engine HTTP target. + This field is a member of `oneof`_ ``target``. http_target (google.cloud.scheduler_v1beta1.types.HttpTarget): HTTP target. + This field is a member of `oneof`_ ``target``. schedule (str): Required, except when used with [UpdateJob][google.cloud.scheduler.v1beta1.CloudScheduler.UpdateJob]. diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/types/target.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/types/target.py index de99f45fcd0a..51bf95d7deaf 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/types/target.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/types/target.py @@ -52,6 +52,13 @@ class HttpTarget(proto.Message): request, the response returned by the redirected request is considered. + 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: uri (str): Required. The full URI path that the request will be sent @@ -99,6 +106,7 @@ class HttpTarget(proto.Message): This type of authorization should generally only be used when calling Google APIs hosted on \*.googleapis.com. + This field is a member of `oneof`_ ``authorization_header``. oidc_token (google.cloud.scheduler_v1beta1.types.OidcToken): If specified, an `OIDC `__ @@ -108,6 +116,7 @@ class HttpTarget(proto.Message): This type of authorization can be used for many scenarios, including calling Cloud Run, or endpoints where you intend to validate the token yourself. + This field is a member of `oneof`_ ``authorization_header``. """ uri = proto.Field(proto.STRING, number=1,) diff --git a/packages/google-cloud-scheduler/setup.py b/packages/google-cloud-scheduler/setup.py index 2d4fa2211c4b..1f0e73f7d677 100644 --- a/packages/google-cloud-scheduler/setup.py +++ b/packages/google-cloud-scheduler/setup.py @@ -31,9 +31,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.4.0", - "packaging >= 14.3", ] extras = {"libcst": "libcst >= 0.2.5"} diff --git a/packages/google-cloud-scheduler/testing/constraints-3.6.txt b/packages/google-cloud-scheduler/testing/constraints-3.6.txt index 475800063567..098d66041d44 100644 --- a/packages/google-cloud-scheduler/testing/constraints-3.6.txt +++ b/packages/google-cloud-scheduler/testing/constraints-3.6.txt @@ -5,10 +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 proto-plus==1.4.0 libcst==0.2.5 -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/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1/test_cloud_scheduler.py b/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1/test_cloud_scheduler.py index c67b2b21253b..1d23d860aecb 100644 --- a/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1/test_cloud_scheduler.py +++ b/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1/test_cloud_scheduler.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -36,9 +35,6 @@ from google.cloud.scheduler_v1.services.cloud_scheduler import CloudSchedulerClient from google.cloud.scheduler_v1.services.cloud_scheduler import pagers from google.cloud.scheduler_v1.services.cloud_scheduler import transports -from google.cloud.scheduler_v1.services.cloud_scheduler.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.scheduler_v1.types import cloudscheduler from google.cloud.scheduler_v1.types import job from google.cloud.scheduler_v1.types import job as gcs_job @@ -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_cloud_scheduler_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_cloud_scheduler_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_cloud_scheduler_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_cloud_scheduler_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, @@ -344,7 +326,7 @@ def test_cloud_scheduler_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 @@ -386,7 +368,7 @@ def test_cloud_scheduler_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, @@ -408,7 +390,7 @@ def test_cloud_scheduler_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, @@ -439,7 +421,7 @@ def test_cloud_scheduler_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, @@ -470,7 +452,7 @@ def test_cloud_scheduler_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", @@ -2449,7 +2431,6 @@ def test_cloud_scheduler_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_cloud_scheduler_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2470,26 +2451,6 @@ def test_cloud_scheduler_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_cloud_scheduler_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.scheduler_v1.services.cloud_scheduler.transports.CloudSchedulerTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.CloudSchedulerTransport( - 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_cloud_scheduler_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( @@ -2501,7 +2462,6 @@ def test_cloud_scheduler_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_cloud_scheduler_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2514,18 +2474,6 @@ def test_cloud_scheduler_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_cloud_scheduler_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) - CloudSchedulerClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2533,7 +2481,6 @@ def test_cloud_scheduler_auth_adc_old_google_auth(): transports.CloudSchedulerGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_cloud_scheduler_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2547,26 +2494,6 @@ def test_cloud_scheduler_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.CloudSchedulerGrpcTransport, - transports.CloudSchedulerGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_cloud_scheduler_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/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1beta1/test_cloud_scheduler.py b/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1beta1/test_cloud_scheduler.py index b9aba11006f8..396e48379587 100644 --- a/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1beta1/test_cloud_scheduler.py +++ b/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1beta1/test_cloud_scheduler.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -38,9 +37,6 @@ from google.cloud.scheduler_v1beta1.services.cloud_scheduler import CloudSchedulerClient from google.cloud.scheduler_v1beta1.services.cloud_scheduler import pagers from google.cloud.scheduler_v1beta1.services.cloud_scheduler import transports -from google.cloud.scheduler_v1beta1.services.cloud_scheduler.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.scheduler_v1beta1.types import cloudscheduler from google.cloud.scheduler_v1beta1.types import job from google.cloud.scheduler_v1beta1.types import job as gcs_job @@ -54,20 +50,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" @@ -224,7 +206,7 @@ def test_cloud_scheduler_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, @@ -241,7 +223,7 @@ def test_cloud_scheduler_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, @@ -258,7 +240,7 @@ def test_cloud_scheduler_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, @@ -287,7 +269,7 @@ def test_cloud_scheduler_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, @@ -346,7 +328,7 @@ def test_cloud_scheduler_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 @@ -388,7 +370,7 @@ def test_cloud_scheduler_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, @@ -410,7 +392,7 @@ def test_cloud_scheduler_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, @@ -441,7 +423,7 @@ def test_cloud_scheduler_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, @@ -472,7 +454,7 @@ def test_cloud_scheduler_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", @@ -2451,7 +2433,6 @@ def test_cloud_scheduler_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_cloud_scheduler_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2472,26 +2453,6 @@ def test_cloud_scheduler_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_cloud_scheduler_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.scheduler_v1beta1.services.cloud_scheduler.transports.CloudSchedulerTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.CloudSchedulerTransport( - 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_cloud_scheduler_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( @@ -2503,7 +2464,6 @@ def test_cloud_scheduler_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_cloud_scheduler_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2516,18 +2476,6 @@ def test_cloud_scheduler_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_cloud_scheduler_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) - CloudSchedulerClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2535,7 +2483,6 @@ def test_cloud_scheduler_auth_adc_old_google_auth(): transports.CloudSchedulerGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_cloud_scheduler_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2549,26 +2496,6 @@ def test_cloud_scheduler_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.CloudSchedulerGrpcTransport, - transports.CloudSchedulerGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_cloud_scheduler_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", [