From fd06e9fe8626ac3d86175518c52ff14efebc0f7b 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 14:48:13 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#429) - [ ] Regenerate this pull request now. docs: list oneofs in docstring docs(v2beta1): clarified meaning of the legacy editions docs(v2beta1): clarified semantic of the streaming APIs 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/agents/async_client.py | 58 +++++----- .../dialogflow_v2/services/agents/client.py | 20 ++-- .../services/agents/transports/base.py | 37 +------ .../services/agents/transports/grpc.py | 2 +- .../agents/transports/grpc_asyncio.py | 3 +- .../services/answer_records/async_client.py | 16 +-- .../services/answer_records/client.py | 6 +- .../answer_records/transports/base.py | 35 +----- .../answer_records/transports/grpc_asyncio.py | 1 - .../services/contexts/async_client.py | 40 +++---- .../dialogflow_v2/services/contexts/client.py | 14 +-- .../services/contexts/transports/base.py | 35 +----- .../contexts/transports/grpc_asyncio.py | 1 - .../conversation_profiles/async_client.py | 42 +++++--- .../services/conversation_profiles/client.py | 12 ++- .../conversation_profiles/transports/base.py | 35 +----- .../transports/grpc_asyncio.py | 1 - .../services/conversations/async_client.py | 34 +++--- .../services/conversations/client.py | 12 ++- .../services/conversations/transports/base.py | 35 +----- .../conversations/transports/grpc_asyncio.py | 1 - .../services/documents/async_client.py | 40 +++---- .../services/documents/client.py | 14 +-- .../services/documents/transports/base.py | 37 +------ .../services/documents/transports/grpc.py | 2 +- .../documents/transports/grpc_asyncio.py | 3 +- .../services/entity_types/async_client.py | 64 +++++------ .../services/entity_types/client.py | 22 ++-- .../services/entity_types/transports/base.py | 37 +------ .../services/entity_types/transports/grpc.py | 2 +- .../entity_types/transports/grpc_asyncio.py | 3 +- .../services/environments/async_client.py | 40 +++---- .../services/environments/client.py | 14 +-- .../services/environments/transports/base.py | 35 +----- .../environments/transports/grpc_asyncio.py | 1 - .../services/fulfillments/async_client.py | 16 +-- .../services/fulfillments/client.py | 6 +- .../services/fulfillments/transports/base.py | 35 +----- .../fulfillments/transports/grpc_asyncio.py | 1 - .../services/intents/async_client.py | 46 ++++---- .../dialogflow_v2/services/intents/client.py | 16 +-- .../services/intents/transports/base.py | 37 +------ .../services/intents/transports/grpc.py | 2 +- .../intents/transports/grpc_asyncio.py | 3 +- .../services/knowledge_bases/async_client.py | 34 +++--- .../services/knowledge_bases/client.py | 12 ++- .../knowledge_bases/transports/base.py | 35 +----- .../transports/grpc_asyncio.py | 1 - .../services/participants/async_client.py | 46 ++++---- .../services/participants/client.py | 16 +-- .../services/participants/transports/base.py | 35 +----- .../participants/transports/grpc_asyncio.py | 1 - .../session_entity_types/async_client.py | 38 ++++--- .../services/session_entity_types/client.py | 12 ++- .../session_entity_types/transports/base.py | 35 +----- .../transports/grpc_asyncio.py | 1 - .../services/sessions/async_client.py | 12 ++- .../dialogflow_v2/services/sessions/client.py | 6 +- .../services/sessions/transports/base.py | 35 +----- .../sessions/transports/grpc_asyncio.py | 1 - .../services/versions/async_client.py | 34 +++--- .../dialogflow_v2/services/versions/client.py | 12 ++- .../services/versions/transports/base.py | 35 +----- .../versions/transports/grpc_asyncio.py | 1 - google/cloud/dialogflow_v2/types/agent.py | 27 +++++ .../dialogflow_v2/types/answer_record.py | 17 +++ .../dialogflow_v2/types/conversation_event.py | 4 + .../types/conversation_profile.py | 19 ++++ google/cloud/dialogflow_v2/types/document.py | 13 +++ .../cloud/dialogflow_v2/types/entity_type.py | 9 ++ .../cloud/dialogflow_v2/types/fulfillment.py | 4 + google/cloud/dialogflow_v2/types/intent.py | 39 +++++++ .../cloud/dialogflow_v2/types/participant.py | 19 ++++ google/cloud/dialogflow_v2/types/session.py | 10 ++ .../services/agents/async_client.py | 58 +++++----- .../services/agents/client.py | 20 ++-- .../services/agents/transports/base.py | 37 +------ .../services/agents/transports/grpc.py | 2 +- .../agents/transports/grpc_asyncio.py | 3 +- .../services/answer_records/async_client.py | 22 ++-- .../services/answer_records/client.py | 8 +- .../answer_records/transports/base.py | 35 +----- .../answer_records/transports/grpc_asyncio.py | 1 - .../services/contexts/async_client.py | 40 +++---- .../services/contexts/client.py | 14 +-- .../services/contexts/transports/base.py | 35 +----- .../contexts/transports/grpc_asyncio.py | 1 - .../conversation_profiles/async_client.py | 42 +++++--- .../services/conversation_profiles/client.py | 12 ++- .../conversation_profiles/transports/base.py | 35 +----- .../transports/grpc_asyncio.py | 1 - .../services/conversations/async_client.py | 40 +++---- .../services/conversations/client.py | 14 +-- .../services/conversations/transports/base.py | 35 +----- .../conversations/transports/grpc_asyncio.py | 1 - .../services/documents/async_client.py | 46 ++++---- .../services/documents/client.py | 16 +-- .../services/documents/transports/base.py | 37 +------ .../services/documents/transports/grpc.py | 2 +- .../documents/transports/grpc_asyncio.py | 3 +- .../services/entity_types/async_client.py | 64 +++++------ .../services/entity_types/client.py | 22 ++-- .../services/entity_types/transports/base.py | 37 +------ .../services/entity_types/transports/grpc.py | 2 +- .../entity_types/transports/grpc_asyncio.py | 3 +- .../services/environments/async_client.py | 40 +++---- .../services/environments/client.py | 14 +-- .../services/environments/transports/base.py | 35 +----- .../environments/transports/grpc_asyncio.py | 1 - .../services/fulfillments/async_client.py | 16 +-- .../services/fulfillments/client.py | 6 +- .../services/fulfillments/transports/base.py | 35 +----- .../fulfillments/transports/grpc_asyncio.py | 1 - .../services/intents/async_client.py | 46 ++++---- .../services/intents/client.py | 16 +-- .../services/intents/transports/base.py | 37 +------ .../services/intents/transports/grpc.py | 2 +- .../intents/transports/grpc_asyncio.py | 3 +- .../services/knowledge_bases/async_client.py | 34 +++--- .../services/knowledge_bases/client.py | 12 ++- .../knowledge_bases/transports/base.py | 35 +----- .../transports/grpc_asyncio.py | 1 - .../services/participants/async_client.py | 64 +++++------ .../services/participants/client.py | 22 ++-- .../services/participants/transports/base.py | 35 +----- .../participants/transports/grpc_asyncio.py | 1 - .../session_entity_types/async_client.py | 38 ++++--- .../services/session_entity_types/client.py | 12 ++- .../session_entity_types/transports/base.py | 35 +----- .../transports/grpc_asyncio.py | 1 - .../services/sessions/async_client.py | 23 ++-- .../services/sessions/client.py | 17 +-- .../services/sessions/transports/base.py | 35 +----- .../sessions/transports/grpc_asyncio.py | 1 - .../services/versions/async_client.py | 34 +++--- .../services/versions/client.py | 12 ++- .../services/versions/transports/base.py | 35 +----- .../versions/transports/grpc_asyncio.py | 1 - .../cloud/dialogflow_v2beta1/types/agent.py | 27 +++++ .../dialogflow_v2beta1/types/answer_record.py | 17 +++ .../types/conversation_event.py | 4 + .../types/conversation_profile.py | 19 ++++ .../dialogflow_v2beta1/types/document.py | 18 ++++ .../dialogflow_v2beta1/types/entity_type.py | 9 ++ .../dialogflow_v2beta1/types/fulfillment.py | 4 + .../cloud/dialogflow_v2beta1/types/intent.py | 73 +++++++++++++ .../dialogflow_v2beta1/types/participant.py | 51 +++++++++ .../cloud/dialogflow_v2beta1/types/session.py | 84 +++++++++------ setup.py | 3 +- testing/constraints-3.6.txt | 4 +- tests/unit/gapic/dialogflow_v2/test_agents.py | 97 ++--------------- .../dialogflow_v2/test_answer_records.py | 100 ++---------------- .../unit/gapic/dialogflow_v2/test_contexts.py | 97 ++--------------- .../test_conversation_profiles.py | 100 ++---------------- .../gapic/dialogflow_v2/test_conversations.py | 100 ++---------------- .../gapic/dialogflow_v2/test_documents.py | 97 ++--------------- .../gapic/dialogflow_v2/test_entity_types.py | 97 ++--------------- .../gapic/dialogflow_v2/test_environments.py | 100 ++---------------- .../gapic/dialogflow_v2/test_fulfillments.py | 100 ++---------------- .../unit/gapic/dialogflow_v2/test_intents.py | 97 ++--------------- .../dialogflow_v2/test_knowledge_bases.py | 100 ++---------------- .../gapic/dialogflow_v2/test_participants.py | 100 ++---------------- .../test_session_entity_types.py | 100 ++---------------- .../unit/gapic/dialogflow_v2/test_sessions.py | 97 ++--------------- .../unit/gapic/dialogflow_v2/test_versions.py | 97 ++--------------- .../gapic/dialogflow_v2beta1/test_agents.py | 97 ++--------------- .../dialogflow_v2beta1/test_answer_records.py | 100 ++---------------- .../gapic/dialogflow_v2beta1/test_contexts.py | 97 ++--------------- .../test_conversation_profiles.py | 100 ++---------------- .../dialogflow_v2beta1/test_conversations.py | 100 ++---------------- .../dialogflow_v2beta1/test_documents.py | 97 ++--------------- .../dialogflow_v2beta1/test_entity_types.py | 97 ++--------------- .../dialogflow_v2beta1/test_environments.py | 100 ++---------------- .../dialogflow_v2beta1/test_fulfillments.py | 100 ++---------------- .../gapic/dialogflow_v2beta1/test_intents.py | 97 ++--------------- .../test_knowledge_bases.py | 100 ++---------------- .../dialogflow_v2beta1/test_participants.py | 100 ++---------------- .../test_session_entity_types.py | 100 ++---------------- .../gapic/dialogflow_v2beta1/test_sessions.py | 97 ++--------------- .../gapic/dialogflow_v2beta1/test_versions.py | 97 ++--------------- 180 files changed, 1623 insertions(+), 4515 deletions(-) diff --git a/google/cloud/dialogflow_v2/services/agents/async_client.py b/google/cloud/dialogflow_v2/services/agents/async_client.py index 5f6815aa4..5be41e5c8 100644 --- a/google/cloud/dialogflow_v2/services/agents/async_client.py +++ b/google/cloud/dialogflow_v2/services/agents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2.services.agents import pagers @@ -159,17 +161,17 @@ def __init__( async def get_agent( self, - request: agent.GetAgentRequest = None, + request: Union[agent.GetAgentRequest, 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]] = (), ) -> agent.Agent: r"""Retrieves the specified agent. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetAgentRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetAgentRequest, dict]): The request object. The request message for [Agents.GetAgent][google.cloud.dialogflow.v2.Agents.GetAgent]. parent (:class:`str`): @@ -239,10 +241,10 @@ async def get_agent( async def set_agent( self, - request: gcd_agent.SetAgentRequest = None, + request: Union[gcd_agent.SetAgentRequest, dict] = None, *, agent: gcd_agent.Agent = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_agent.Agent: @@ -253,7 +255,7 @@ async def set_agent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.SetAgentRequest`): + request (Union[google.cloud.dialogflow_v2.types.SetAgentRequest, dict]): The request object. The request message for [Agents.SetAgent][google.cloud.dialogflow.v2.Agents.SetAgent]. agent (:class:`google.cloud.dialogflow_v2.types.Agent`): @@ -323,17 +325,17 @@ async def set_agent( async def delete_agent( self, - request: agent.DeleteAgentRequest = None, + request: Union[agent.DeleteAgentRequest, 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]] = (), ) -> None: r"""Deletes the specified agent. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteAgentRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteAgentRequest, dict]): The request object. The request message for [Agents.DeleteAgent][google.cloud.dialogflow.v2.Agents.DeleteAgent]. parent (:class:`str`): @@ -387,10 +389,10 @@ async def delete_agent( async def search_agents( self, - request: agent.SearchAgentsRequest = None, + request: Union[agent.SearchAgentsRequest, 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.SearchAgentsAsyncPager: @@ -403,7 +405,7 @@ async def search_agents( Sub-Collections `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.SearchAgentsRequest`): + request (Union[google.cloud.dialogflow_v2.types.SearchAgentsRequest, dict]): The request object. The request message for [Agents.SearchAgents][google.cloud.dialogflow.v2.Agents.SearchAgents]. parent (:class:`str`): @@ -473,10 +475,10 @@ async def search_agents( async def train_agent( self, - request: agent.TrainAgentRequest = None, + request: Union[agent.TrainAgentRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -497,7 +499,7 @@ async def train_agent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.TrainAgentRequest`): + request (Union[google.cloud.dialogflow_v2.types.TrainAgentRequest, dict]): The request object. The request message for [Agents.TrainAgent][google.cloud.dialogflow.v2.Agents.TrainAgent]. parent (:class:`str`): @@ -579,10 +581,10 @@ async def train_agent( async def export_agent( self, - request: agent.ExportAgentRequest = None, + request: Union[agent.ExportAgentRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -599,7 +601,7 @@ async def export_agent( [ExportAgentResponse][google.cloud.dialogflow.v2.ExportAgentResponse] Args: - request (:class:`google.cloud.dialogflow_v2.types.ExportAgentRequest`): + request (Union[google.cloud.dialogflow_v2.types.ExportAgentRequest, dict]): The request object. The request message for [Agents.ExportAgent][google.cloud.dialogflow.v2.Agents.ExportAgent]. parent (:class:`str`): @@ -672,9 +674,9 @@ async def export_agent( async def import_agent( self, - request: agent.ImportAgentRequest = None, + request: Union[agent.ImportAgentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -709,7 +711,7 @@ async def import_agent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.ImportAgentRequest`): + request (Union[google.cloud.dialogflow_v2.types.ImportAgentRequest, dict]): The request object. The request message for [Agents.ImportAgent][google.cloud.dialogflow.v2.Agents.ImportAgent]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -770,9 +772,9 @@ async def import_agent( async def restore_agent( self, - request: agent.RestoreAgentRequest = None, + request: Union[agent.RestoreAgentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -805,7 +807,7 @@ async def restore_agent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.RestoreAgentRequest`): + request (Union[google.cloud.dialogflow_v2.types.RestoreAgentRequest, dict]): The request object. The request message for [Agents.RestoreAgent][google.cloud.dialogflow.v2.Agents.RestoreAgent]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -866,9 +868,9 @@ async def restore_agent( async def get_validation_result( self, - request: agent.GetValidationResultRequest = None, + request: Union[agent.GetValidationResultRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> validation_result.ValidationResult: @@ -877,7 +879,7 @@ async def get_validation_result( automatically when training is completed. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetValidationResultRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetValidationResultRequest, dict]): The request object. The request message for [Agents.GetValidationResult][google.cloud.dialogflow.v2.Agents.GetValidationResult]. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/dialogflow_v2/services/agents/client.py b/google/cloud/dialogflow_v2/services/agents/client.py index 4a74e1694..ecbb333e9 100644 --- a/google/cloud/dialogflow_v2/services/agents/client.py +++ b/google/cloud/dialogflow_v2/services/agents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2.services.agents import pagers @@ -351,7 +353,7 @@ def get_agent( request: Union[agent.GetAgentRequest, 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]] = (), ) -> agent.Agent: @@ -431,7 +433,7 @@ def set_agent( request: Union[gcd_agent.SetAgentRequest, dict] = None, *, agent: gcd_agent.Agent = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_agent.Agent: @@ -515,7 +517,7 @@ def delete_agent( request: Union[agent.DeleteAgentRequest, 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]] = (), ) -> None: @@ -579,7 +581,7 @@ def search_agents( request: Union[agent.SearchAgentsRequest, 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.SearchAgentsPager: @@ -665,7 +667,7 @@ def train_agent( request: Union[agent.TrainAgentRequest, 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]] = (), ) -> operation.Operation: @@ -771,7 +773,7 @@ def export_agent( request: Union[agent.ExportAgentRequest, 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]] = (), ) -> operation.Operation: @@ -863,7 +865,7 @@ def import_agent( self, request: Union[agent.ImportAgentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -962,7 +964,7 @@ def restore_agent( self, request: Union[agent.RestoreAgentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1059,7 +1061,7 @@ def get_validation_result( self, request: Union[agent.GetValidationResultRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> validation_result.ValidationResult: diff --git a/google/cloud/dialogflow_v2/services/agents/transports/base.py b/google/cloud/dialogflow_v2/services/agents/transports/base.py index f7a10e47f..f11253a57 100644 --- a/google/cloud/dialogflow_v2/services/agents/transports/base.py +++ b/google/cloud/dialogflow_v2/services/agents/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 @@ -42,15 +41,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 AgentsTransport(abc.ABC): """Abstract transport class for Agents.""" @@ -103,7 +93,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 @@ -136,29 +126,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 = { @@ -203,7 +170,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/dialogflow_v2/services/agents/transports/grpc.py b/google/cloud/dialogflow_v2/services/agents/transports/grpc.py index 6e52a4e0e..94feb1abb 100644 --- a/google/cloud/dialogflow_v2/services/agents/transports/grpc.py +++ b/google/cloud/dialogflow_v2/services/agents/transports/grpc.py @@ -115,7 +115,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py index bc71955a0..2d4b3a589 100644 --- a/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -162,7 +161,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2/services/answer_records/async_client.py b/google/cloud/dialogflow_v2/services/answer_records/async_client.py index 8bdbb5ac2..232a38206 100644 --- a/google/cloud/dialogflow_v2/services/answer_records/async_client.py +++ b/google/cloud/dialogflow_v2/services/answer_records/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.dialogflow_v2.services.answer_records import pagers from google.cloud.dialogflow_v2.types import answer_record from google.cloud.dialogflow_v2.types import answer_record as gcd_answer_record @@ -169,10 +171,10 @@ def __init__( async def list_answer_records( self, - request: answer_record.ListAnswerRecordsRequest = None, + request: Union[answer_record.ListAnswerRecordsRequest, 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.ListAnswerRecordsAsyncPager: @@ -180,7 +182,7 @@ async def list_answer_records( specified project in reverse chronological order. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListAnswerRecordsRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListAnswerRecordsRequest, dict]): The request object. Request message for [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2.AnswerRecords.ListAnswerRecords]. parent (:class:`str`): @@ -251,18 +253,18 @@ async def list_answer_records( async def update_answer_record( self, - request: gcd_answer_record.UpdateAnswerRecordRequest = None, + request: Union[gcd_answer_record.UpdateAnswerRecordRequest, dict] = None, *, answer_record: gcd_answer_record.AnswerRecord = 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]] = (), ) -> gcd_answer_record.AnswerRecord: r"""Updates the specified answer record. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateAnswerRecordRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateAnswerRecordRequest, dict]): The request object. Request message for [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2.AnswerRecords.UpdateAnswerRecord]. answer_record (:class:`google.cloud.dialogflow_v2.types.AnswerRecord`): diff --git a/google/cloud/dialogflow_v2/services/answer_records/client.py b/google/cloud/dialogflow_v2/services/answer_records/client.py index a0246bec1..c0a06db6c 100644 --- a/google/cloud/dialogflow_v2/services/answer_records/client.py +++ b/google/cloud/dialogflow_v2/services/answer_records/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.dialogflow_v2.services.answer_records import pagers from google.cloud.dialogflow_v2.types import answer_record from google.cloud.dialogflow_v2.types import answer_record as gcd_answer_record @@ -353,7 +355,7 @@ def list_answer_records( request: Union[answer_record.ListAnswerRecordsRequest, 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.ListAnswerRecordsPager: @@ -436,7 +438,7 @@ def update_answer_record( *, answer_record: gcd_answer_record.AnswerRecord = 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]] = (), ) -> gcd_answer_record.AnswerRecord: diff --git a/google/cloud/dialogflow_v2/services/answer_records/transports/base.py b/google/cloud/dialogflow_v2/services/answer_records/transports/base.py index ee70ced70..22407870d 100644 --- a/google/cloud/dialogflow_v2/services/answer_records/transports/base.py +++ b/google/cloud/dialogflow_v2/services/answer_records/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 AnswerRecordsTransport(abc.ABC): """Abstract transport class for AnswerRecords.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py index 7f70b48fb..2378d3912 100644 --- a/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/answer_records/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/dialogflow_v2/services/contexts/async_client.py b/google/cloud/dialogflow_v2/services/contexts/async_client.py index 1e5135a9e..c34dbf111 100644 --- a/google/cloud/dialogflow_v2/services/contexts/async_client.py +++ b/google/cloud/dialogflow_v2/services/contexts/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.dialogflow_v2.services.contexts import pagers from google.cloud.dialogflow_v2.types import context from google.cloud.dialogflow_v2.types import context as gcd_context @@ -158,10 +160,10 @@ def __init__( async def list_contexts( self, - request: context.ListContextsRequest = None, + request: Union[context.ListContextsRequest, 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.ListContextsAsyncPager: @@ -169,7 +171,7 @@ async def list_contexts( session. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListContextsRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListContextsRequest, dict]): The request object. The request message for [Contexts.ListContexts][google.cloud.dialogflow.v2.Contexts.ListContexts]. parent (:class:`str`): @@ -243,17 +245,17 @@ async def list_contexts( async def get_context( self, - request: context.GetContextRequest = None, + request: Union[context.GetContextRequest, 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]] = (), ) -> context.Context: r"""Retrieves the specified context. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetContextRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetContextRequest, dict]): The request object. The request message for [Contexts.GetContext][google.cloud.dialogflow.v2.Contexts.GetContext]. name (:class:`str`): @@ -336,11 +338,11 @@ async def get_context( async def create_context( self, - request: gcd_context.CreateContextRequest = None, + request: Union[gcd_context.CreateContextRequest, dict] = None, *, parent: str = None, context: gcd_context.Context = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_context.Context: @@ -349,7 +351,7 @@ async def create_context( context. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateContextRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateContextRequest, dict]): The request object. The request message for [Contexts.CreateContext][google.cloud.dialogflow.v2.Contexts.CreateContext]. parent (:class:`str`): @@ -438,18 +440,18 @@ async def create_context( async def update_context( self, - request: gcd_context.UpdateContextRequest = None, + request: Union[gcd_context.UpdateContextRequest, dict] = None, *, context: gcd_context.Context = 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]] = (), ) -> gcd_context.Context: r"""Updates the specified context. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateContextRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateContextRequest, dict]): The request object. The request message for [Contexts.UpdateContext][google.cloud.dialogflow.v2.Contexts.UpdateContext]. context (:class:`google.cloud.dialogflow_v2.types.Context`): @@ -536,17 +538,17 @@ async def update_context( async def delete_context( self, - request: context.DeleteContextRequest = None, + request: Union[context.DeleteContextRequest, 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 the specified context. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteContextRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteContextRequest, dict]): The request object. The request message for [Contexts.DeleteContext][google.cloud.dialogflow.v2.Contexts.DeleteContext]. name (:class:`str`): @@ -605,17 +607,17 @@ async def delete_context( async def delete_all_contexts( self, - request: context.DeleteAllContextsRequest = None, + request: Union[context.DeleteAllContextsRequest, 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]] = (), ) -> None: r"""Deletes all active contexts in the specified session. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteAllContextsRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteAllContextsRequest, dict]): The request object. The request message for [Contexts.DeleteAllContexts][google.cloud.dialogflow.v2.Contexts.DeleteAllContexts]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2/services/contexts/client.py b/google/cloud/dialogflow_v2/services/contexts/client.py index 06e29095f..f8ecc1294 100644 --- a/google/cloud/dialogflow_v2/services/contexts/client.py +++ b/google/cloud/dialogflow_v2/services/contexts/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.dialogflow_v2.services.contexts import pagers from google.cloud.dialogflow_v2.types import context from google.cloud.dialogflow_v2.types import context as gcd_context @@ -353,7 +355,7 @@ def list_contexts( request: Union[context.ListContextsRequest, 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.ListContextsPager: @@ -438,7 +440,7 @@ def get_context( request: Union[context.GetContextRequest, 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]] = (), ) -> context.Context: @@ -532,7 +534,7 @@ def create_context( *, parent: str = None, context: gcd_context.Context = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_context.Context: @@ -634,7 +636,7 @@ def update_context( *, context: gcd_context.Context = 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]] = (), ) -> gcd_context.Context: @@ -731,7 +733,7 @@ def delete_context( request: Union[context.DeleteContextRequest, 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: @@ -800,7 +802,7 @@ def delete_all_contexts( request: Union[context.DeleteAllContextsRequest, 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]] = (), ) -> None: diff --git a/google/cloud/dialogflow_v2/services/contexts/transports/base.py b/google/cloud/dialogflow_v2/services/contexts/transports/base.py index dda6e53e2..7029d897c 100644 --- a/google/cloud/dialogflow_v2/services/contexts/transports/base.py +++ b/google/cloud/dialogflow_v2/services/contexts/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 @@ -39,15 +38,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 ContextsTransport(abc.ABC): """Abstract transport class for Contexts.""" @@ -100,7 +90,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 @@ -133,29 +123,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/dialogflow_v2/services/contexts/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py index 1cb2fca64..fb51dc09e 100644 --- a/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/contexts/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/dialogflow_v2/services/conversation_profiles/async_client.py b/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py index ca633fb2f..b25601df2 100644 --- a/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py +++ b/google/cloud/dialogflow_v2/services/conversation_profiles/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.dialogflow_v2.services.conversation_profiles import pagers from google.cloud.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import conversation_profile @@ -190,10 +192,12 @@ def __init__( async def list_conversation_profiles( self, - request: conversation_profile.ListConversationProfilesRequest = None, + request: Union[ + conversation_profile.ListConversationProfilesRequest, 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.ListConversationProfilesAsyncPager: @@ -201,7 +205,7 @@ async def list_conversation_profiles( specified project. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListConversationProfilesRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListConversationProfilesRequest, dict]): The request object. The request message for [ConversationProfiles.ListConversationProfiles][google.cloud.dialogflow.v2.ConversationProfiles.ListConversationProfiles]. parent (:class:`str`): @@ -272,17 +276,17 @@ async def list_conversation_profiles( async def get_conversation_profile( self, - request: conversation_profile.GetConversationProfileRequest = None, + request: Union[conversation_profile.GetConversationProfileRequest, 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]] = (), ) -> conversation_profile.ConversationProfile: r"""Retrieves the specified conversation profile. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetConversationProfileRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetConversationProfileRequest, dict]): The request object. The request message for [ConversationProfiles.GetConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.GetConversationProfile]. name (:class:`str`): @@ -344,11 +348,13 @@ async def get_conversation_profile( async def create_conversation_profile( self, - request: gcd_conversation_profile.CreateConversationProfileRequest = None, + request: Union[ + gcd_conversation_profile.CreateConversationProfileRequest, dict + ] = None, *, parent: str = None, conversation_profile: gcd_conversation_profile.ConversationProfile = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_conversation_profile.ConversationProfile: @@ -361,7 +367,7 @@ async def create_conversation_profile( API. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateConversationProfileRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateConversationProfileRequest, dict]): The request object. The request message for [ConversationProfiles.CreateConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.CreateConversationProfile]. parent (:class:`str`): @@ -432,11 +438,13 @@ async def create_conversation_profile( async def update_conversation_profile( self, - request: gcd_conversation_profile.UpdateConversationProfileRequest = None, + request: Union[ + gcd_conversation_profile.UpdateConversationProfileRequest, dict + ] = None, *, conversation_profile: gcd_conversation_profile.ConversationProfile = 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]] = (), ) -> gcd_conversation_profile.ConversationProfile: @@ -449,7 +457,7 @@ async def update_conversation_profile( API. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateConversationProfileRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateConversationProfileRequest, dict]): The request object. The request message for [ConversationProfiles.UpdateConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.UpdateConversationProfile]. conversation_profile (:class:`google.cloud.dialogflow_v2.types.ConversationProfile`): @@ -521,17 +529,19 @@ async def update_conversation_profile( async def delete_conversation_profile( self, - request: conversation_profile.DeleteConversationProfileRequest = None, + request: Union[ + conversation_profile.DeleteConversationProfileRequest, 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 the specified conversation profile. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteConversationProfileRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteConversationProfileRequest, dict]): The request object. The request message for [ConversationProfiles.DeleteConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.DeleteConversationProfile]. This operation fails if the conversation profile is diff --git a/google/cloud/dialogflow_v2/services/conversation_profiles/client.py b/google/cloud/dialogflow_v2/services/conversation_profiles/client.py index 0b2807157..3af5b23f5 100644 --- a/google/cloud/dialogflow_v2/services/conversation_profiles/client.py +++ b/google/cloud/dialogflow_v2/services/conversation_profiles/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.dialogflow_v2.services.conversation_profiles import pagers from google.cloud.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import conversation_profile @@ -424,7 +426,7 @@ def list_conversation_profiles( ] = 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.ListConversationProfilesPager: @@ -510,7 +512,7 @@ def get_conversation_profile( request: Union[conversation_profile.GetConversationProfileRequest, 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]] = (), ) -> conversation_profile.ConversationProfile: @@ -585,7 +587,7 @@ def create_conversation_profile( *, parent: str = None, conversation_profile: gcd_conversation_profile.ConversationProfile = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_conversation_profile.ConversationProfile: @@ -679,7 +681,7 @@ def update_conversation_profile( *, conversation_profile: gcd_conversation_profile.ConversationProfile = 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]] = (), ) -> gcd_conversation_profile.ConversationProfile: @@ -773,7 +775,7 @@ def delete_conversation_profile( ] = 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: diff --git a/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py b/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py index 87fe87c1e..8d4294d3c 100644 --- a/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py +++ b/google/cloud/dialogflow_v2/services/conversation_profiles/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 @@ -41,15 +40,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 ConversationProfilesTransport(abc.ABC): """Abstract transport class for ConversationProfiles.""" @@ -102,7 +92,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 @@ -135,29 +125,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/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py index b3d0d2d00..e3b2b81bd 100644 --- a/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/conversation_profiles/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/dialogflow_v2/services/conversations/async_client.py b/google/cloud/dialogflow_v2/services/conversations/async_client.py index ee94e904a..550906050 100644 --- a/google/cloud/dialogflow_v2/services/conversations/async_client.py +++ b/google/cloud/dialogflow_v2/services/conversations/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.dialogflow_v2.services.conversations import pagers from google.cloud.dialogflow_v2.types import conversation from google.cloud.dialogflow_v2.types import conversation as gcd_conversation @@ -176,11 +178,11 @@ def __init__( async def create_conversation( self, - request: gcd_conversation.CreateConversationRequest = None, + request: Union[gcd_conversation.CreateConversationRequest, dict] = None, *, parent: str = None, conversation: gcd_conversation.Conversation = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_conversation.Conversation: @@ -207,7 +209,7 @@ async def create_conversation( is triggered, conversation will transfer to Assist Stage. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateConversationRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateConversationRequest, dict]): The request object. The request message for [Conversations.CreateConversation][google.cloud.dialogflow.v2.Conversations.CreateConversation]. parent (:class:`str`): @@ -281,10 +283,10 @@ async def create_conversation( async def list_conversations( self, - request: conversation.ListConversationsRequest = None, + request: Union[conversation.ListConversationsRequest, 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.ListConversationsAsyncPager: @@ -292,7 +294,7 @@ async def list_conversations( specified project. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListConversationsRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListConversationsRequest, dict]): The request object. The request message for [Conversations.ListConversations][google.cloud.dialogflow.v2.Conversations.ListConversations]. parent (:class:`str`): @@ -363,17 +365,17 @@ async def list_conversations( async def get_conversation( self, - request: conversation.GetConversationRequest = None, + request: Union[conversation.GetConversationRequest, 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]] = (), ) -> conversation.Conversation: r"""Retrieves the specific conversation. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetConversationRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetConversationRequest, dict]): The request object. The request message for [Conversations.GetConversation][google.cloud.dialogflow.v2.Conversations.GetConversation]. name (:class:`str`): @@ -439,10 +441,10 @@ async def get_conversation( async def complete_conversation( self, - request: conversation.CompleteConversationRequest = None, + request: Union[conversation.CompleteConversationRequest, 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]] = (), ) -> conversation.Conversation: @@ -451,7 +453,7 @@ async def complete_conversation( days. Args: - request (:class:`google.cloud.dialogflow_v2.types.CompleteConversationRequest`): + request (Union[google.cloud.dialogflow_v2.types.CompleteConversationRequest, dict]): The request object. The request message for [Conversations.CompleteConversation][google.cloud.dialogflow.v2.Conversations.CompleteConversation]. name (:class:`str`): @@ -518,10 +520,10 @@ async def complete_conversation( async def list_messages( self, - request: conversation.ListMessagesRequest = None, + request: Union[conversation.ListMessagesRequest, 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.ListMessagesAsyncPager: @@ -532,7 +534,7 @@ async def list_messages( and empty page_token. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListMessagesRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListMessagesRequest, dict]): The request object. The request message for [Conversations.ListMessages][google.cloud.dialogflow.v2.Conversations.ListMessages]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2/services/conversations/client.py b/google/cloud/dialogflow_v2/services/conversations/client.py index ae05f5ff4..8e6340432 100644 --- a/google/cloud/dialogflow_v2/services/conversations/client.py +++ b/google/cloud/dialogflow_v2/services/conversations/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.dialogflow_v2.services.conversations import pagers from google.cloud.dialogflow_v2.types import conversation from google.cloud.dialogflow_v2.types import conversation as gcd_conversation @@ -387,7 +389,7 @@ def create_conversation( *, parent: str = None, conversation: gcd_conversation.Conversation = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_conversation.Conversation: @@ -491,7 +493,7 @@ def list_conversations( request: Union[conversation.ListConversationsRequest, 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.ListConversationsPager: @@ -573,7 +575,7 @@ def get_conversation( request: Union[conversation.GetConversationRequest, 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]] = (), ) -> conversation.Conversation: @@ -649,7 +651,7 @@ def complete_conversation( request: Union[conversation.CompleteConversationRequest, 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]] = (), ) -> conversation.Conversation: @@ -728,7 +730,7 @@ def list_messages( request: Union[conversation.ListMessagesRequest, 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.ListMessagesPager: diff --git a/google/cloud/dialogflow_v2/services/conversations/transports/base.py b/google/cloud/dialogflow_v2/services/conversations/transports/base.py index 1834009d5..036a97fbe 100644 --- a/google/cloud/dialogflow_v2/services/conversations/transports/base.py +++ b/google/cloud/dialogflow_v2/services/conversations/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 ConversationsTransport(abc.ABC): """Abstract transport class for Conversations.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2/services/conversations/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py index 9a6d9cfda..1ad275372 100644 --- a/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/conversations/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/dialogflow_v2/services/documents/async_client.py b/google/cloud/dialogflow_v2/services/documents/async_client.py index c0e708525..8b8af77e3 100644 --- a/google/cloud/dialogflow_v2/services/documents/async_client.py +++ b/google/cloud/dialogflow_v2/services/documents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2.services.documents import pagers @@ -164,10 +166,10 @@ def __init__( async def list_documents( self, - request: document.ListDocumentsRequest = None, + request: Union[document.ListDocumentsRequest, 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.ListDocumentsAsyncPager: @@ -175,7 +177,7 @@ async def list_documents( base. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListDocumentsRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListDocumentsRequest, dict]): The request object. Request message for [Documents.ListDocuments][google.cloud.dialogflow.v2.Documents.ListDocuments]. parent (:class:`str`): @@ -246,17 +248,17 @@ async def list_documents( async def get_document( self, - request: document.GetDocumentRequest = None, + request: Union[document.GetDocumentRequest, 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]] = (), ) -> document.Document: r"""Retrieves the specified document. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetDocumentRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetDocumentRequest, dict]): The request object. Request message for [Documents.GetDocument][google.cloud.dialogflow.v2.Documents.GetDocument]. name (:class:`str`): @@ -324,11 +326,11 @@ async def get_document( async def create_document( self, - request: gcd_document.CreateDocumentRequest = None, + request: Union[gcd_document.CreateDocumentRequest, dict] = None, *, parent: str = None, document: gcd_document.Document = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -344,7 +346,7 @@ async def create_document( - ``response``: [Document][google.cloud.dialogflow.v2.Document] Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateDocumentRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateDocumentRequest, dict]): The request object. Request message for [Documents.CreateDocument][google.cloud.dialogflow.v2.Documents.CreateDocument]. parent (:class:`str`): @@ -432,10 +434,10 @@ async def create_document( async def delete_document( self, - request: document.DeleteDocumentRequest = None, + request: Union[document.DeleteDocumentRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -452,7 +454,7 @@ async def delete_document( message `__ Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteDocumentRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteDocumentRequest, dict]): The request object. Request message for [Documents.DeleteDocument][google.cloud.dialogflow.v2.Documents.DeleteDocument]. name (:class:`str`): @@ -534,11 +536,11 @@ async def delete_document( async def update_document( self, - request: gcd_document.UpdateDocumentRequest = None, + request: Union[gcd_document.UpdateDocumentRequest, dict] = None, *, document: gcd_document.Document = 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]] = (), ) -> operation_async.AsyncOperation: @@ -554,7 +556,7 @@ async def update_document( - ``response``: [Document][google.cloud.dialogflow.v2.Document] Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateDocumentRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateDocumentRequest, dict]): The request object. Request message for [Documents.UpdateDocument][google.cloud.dialogflow.v2.Documents.UpdateDocument]. document (:class:`google.cloud.dialogflow_v2.types.Document`): @@ -644,11 +646,11 @@ async def update_document( async def reload_document( self, - request: document.ReloadDocumentRequest = None, + request: Union[document.ReloadDocumentRequest, dict] = None, *, name: str = None, content_uri: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -671,7 +673,7 @@ async def reload_document( is deprecated; only use ``projects.knowledgeBases.documents``. Args: - request (:class:`google.cloud.dialogflow_v2.types.ReloadDocumentRequest`): + request (Union[google.cloud.dialogflow_v2.types.ReloadDocumentRequest, dict]): The request object. Request message for [Documents.ReloadDocument][google.cloud.dialogflow.v2.Documents.ReloadDocument]. name (:class:`str`): diff --git a/google/cloud/dialogflow_v2/services/documents/client.py b/google/cloud/dialogflow_v2/services/documents/client.py index cfa9dc907..926077655 100644 --- a/google/cloud/dialogflow_v2/services/documents/client.py +++ b/google/cloud/dialogflow_v2/services/documents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2.services.documents import pagers @@ -357,7 +359,7 @@ def list_documents( request: Union[document.ListDocumentsRequest, 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.ListDocumentsPager: @@ -439,7 +441,7 @@ def get_document( request: Union[document.GetDocumentRequest, 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]] = (), ) -> document.Document: @@ -518,7 +520,7 @@ def create_document( *, parent: str = None, document: gcd_document.Document = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -625,7 +627,7 @@ def delete_document( request: Union[document.DeleteDocumentRequest, 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]] = (), ) -> operation.Operation: @@ -728,7 +730,7 @@ def update_document( *, document: gcd_document.Document = 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]] = (), ) -> operation.Operation: @@ -838,7 +840,7 @@ def reload_document( *, name: str = None, content_uri: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/google/cloud/dialogflow_v2/services/documents/transports/base.py b/google/cloud/dialogflow_v2/services/documents/transports/base.py index 875f1df70..fd54c1802 100644 --- a/google/cloud/dialogflow_v2/services/documents/transports/base.py +++ b/google/cloud/dialogflow_v2/services/documents/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 @@ -40,15 +39,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 DocumentsTransport(abc.ABC): """Abstract transport class for Documents.""" @@ -101,7 +91,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 @@ -134,29 +124,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 = { @@ -190,7 +157,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/dialogflow_v2/services/documents/transports/grpc.py b/google/cloud/dialogflow_v2/services/documents/transports/grpc.py index ca40d991a..9f6d1e5a2 100644 --- a/google/cloud/dialogflow_v2/services/documents/transports/grpc.py +++ b/google/cloud/dialogflow_v2/services/documents/transports/grpc.py @@ -114,7 +114,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py index eadfb102c..e82978ae2 100644 --- a/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -161,7 +160,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2/services/entity_types/async_client.py b/google/cloud/dialogflow_v2/services/entity_types/async_client.py index 6dbe7224f..c7c997d27 100644 --- a/google/cloud/dialogflow_v2/services/entity_types/async_client.py +++ b/google/cloud/dialogflow_v2/services/entity_types/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2.services.entity_types import pagers @@ -166,11 +168,11 @@ def __init__( async def list_entity_types( self, - request: entity_type.ListEntityTypesRequest = None, + request: Union[entity_type.ListEntityTypesRequest, dict] = None, *, parent: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEntityTypesAsyncPager: @@ -178,7 +180,7 @@ async def list_entity_types( agent. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListEntityTypesRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListEntityTypesRequest, dict]): The request object. The request message for [EntityTypes.ListEntityTypes][google.cloud.dialogflow.v2.EntityTypes.ListEntityTypes]. parent (:class:`str`): @@ -260,18 +262,18 @@ async def list_entity_types( async def get_entity_type( self, - request: entity_type.GetEntityTypeRequest = None, + request: Union[entity_type.GetEntityTypeRequest, dict] = None, *, name: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> entity_type.EntityType: r"""Retrieves the specified entity type. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetEntityTypeRequest, dict]): The request object. The request message for [EntityTypes.GetEntityType][google.cloud.dialogflow.v2.EntityTypes.GetEntityType]. name (:class:`str`): @@ -357,12 +359,12 @@ async def get_entity_type( async def create_entity_type( self, - request: gcd_entity_type.CreateEntityTypeRequest = None, + request: Union[gcd_entity_type.CreateEntityTypeRequest, dict] = None, *, parent: str = None, entity_type: gcd_entity_type.EntityType = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_entity_type.EntityType: @@ -373,7 +375,7 @@ async def create_entity_type( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateEntityTypeRequest, dict]): The request object. The request message for [EntityTypes.CreateEntityType][google.cloud.dialogflow.v2.EntityTypes.CreateEntityType]. parent (:class:`str`): @@ -466,11 +468,11 @@ async def create_entity_type( async def update_entity_type( self, - request: gcd_entity_type.UpdateEntityTypeRequest = None, + request: Union[gcd_entity_type.UpdateEntityTypeRequest, dict] = None, *, entity_type: gcd_entity_type.EntityType = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_entity_type.EntityType: @@ -481,7 +483,7 @@ async def update_entity_type( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateEntityTypeRequest, dict]): The request object. The request message for [EntityTypes.UpdateEntityType][google.cloud.dialogflow.v2.EntityTypes.UpdateEntityType]. entity_type (:class:`google.cloud.dialogflow_v2.types.EntityType`): @@ -567,10 +569,10 @@ async def update_entity_type( async def delete_entity_type( self, - request: entity_type.DeleteEntityTypeRequest = None, + request: Union[entity_type.DeleteEntityTypeRequest, 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: @@ -581,7 +583,7 @@ async def delete_entity_type( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteEntityTypeRequest, dict]): The request object. The request message for [EntityTypes.DeleteEntityType][google.cloud.dialogflow.v2.EntityTypes.DeleteEntityType]. name (:class:`str`): @@ -635,9 +637,9 @@ async def delete_entity_type( async def batch_update_entity_types( self, - request: entity_type.BatchUpdateEntityTypesRequest = None, + request: Union[entity_type.BatchUpdateEntityTypesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -658,7 +660,7 @@ async def batch_update_entity_types( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.BatchUpdateEntityTypesRequest`): + request (Union[google.cloud.dialogflow_v2.types.BatchUpdateEntityTypesRequest, dict]): The request object. The request message for [EntityTypes.BatchUpdateEntityTypes][google.cloud.dialogflow.v2.EntityTypes.BatchUpdateEntityTypes]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -710,11 +712,11 @@ async def batch_update_entity_types( async def batch_delete_entity_types( self, - request: entity_type.BatchDeleteEntityTypesRequest = None, + request: Union[entity_type.BatchDeleteEntityTypesRequest, dict] = None, *, parent: str = None, entity_type_names: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -735,7 +737,7 @@ async def batch_delete_entity_types( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.BatchDeleteEntityTypesRequest`): + request (Union[google.cloud.dialogflow_v2.types.BatchDeleteEntityTypesRequest, dict]): The request object. The request message for [EntityTypes.BatchDeleteEntityTypes][google.cloud.dialogflow.v2.EntityTypes.BatchDeleteEntityTypes]. parent (:class:`str`): @@ -826,12 +828,12 @@ async def batch_delete_entity_types( async def batch_create_entities( self, - request: entity_type.BatchCreateEntitiesRequest = None, + request: Union[entity_type.BatchCreateEntitiesRequest, dict] = None, *, parent: str = None, entities: Sequence[entity_type.EntityType.Entity] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -852,7 +854,7 @@ async def batch_create_entities( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.BatchCreateEntitiesRequest`): + request (Union[google.cloud.dialogflow_v2.types.BatchCreateEntitiesRequest, dict]): The request object. The request message for [EntityTypes.BatchCreateEntities][google.cloud.dialogflow.v2.EntityTypes.BatchCreateEntities]. parent (:class:`str`): @@ -954,12 +956,12 @@ async def batch_create_entities( async def batch_update_entities( self, - request: entity_type.BatchUpdateEntitiesRequest = None, + request: Union[entity_type.BatchUpdateEntitiesRequest, dict] = None, *, parent: str = None, entities: Sequence[entity_type.EntityType.Entity] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -982,7 +984,7 @@ async def batch_update_entities( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.BatchUpdateEntitiesRequest`): + request (Union[google.cloud.dialogflow_v2.types.BatchUpdateEntitiesRequest, dict]): The request object. The request message for [EntityTypes.BatchUpdateEntities][google.cloud.dialogflow.v2.EntityTypes.BatchUpdateEntities]. parent (:class:`str`): @@ -1086,12 +1088,12 @@ async def batch_update_entities( async def batch_delete_entities( self, - request: entity_type.BatchDeleteEntitiesRequest = None, + request: Union[entity_type.BatchDeleteEntitiesRequest, dict] = None, *, parent: str = None, entity_values: Sequence[str] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1112,7 +1114,7 @@ async def batch_delete_entities( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.BatchDeleteEntitiesRequest`): + request (Union[google.cloud.dialogflow_v2.types.BatchDeleteEntitiesRequest, dict]): The request object. The request message for [EntityTypes.BatchDeleteEntities][google.cloud.dialogflow.v2.EntityTypes.BatchDeleteEntities]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2/services/entity_types/client.py b/google/cloud/dialogflow_v2/services/entity_types/client.py index 99c67e884..d532ccf91 100644 --- a/google/cloud/dialogflow_v2/services/entity_types/client.py +++ b/google/cloud/dialogflow_v2/services/entity_types/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2.services.entity_types import pagers @@ -357,7 +359,7 @@ def list_entity_types( *, parent: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEntityTypesPager: @@ -451,7 +453,7 @@ def get_entity_type( *, name: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> entity_type.EntityType: @@ -549,7 +551,7 @@ def create_entity_type( parent: str = None, entity_type: gcd_entity_type.EntityType = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_entity_type.EntityType: @@ -657,7 +659,7 @@ def update_entity_type( *, entity_type: gcd_entity_type.EntityType = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_entity_type.EntityType: @@ -757,7 +759,7 @@ def delete_entity_type( request: Union[entity_type.DeleteEntityTypeRequest, 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: @@ -824,7 +826,7 @@ def batch_update_entity_types( self, request: Union[entity_type.BatchUpdateEntityTypesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -904,7 +906,7 @@ def batch_delete_entity_types( *, parent: str = None, entity_type_names: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1023,7 +1025,7 @@ def batch_create_entities( parent: str = None, entities: Sequence[entity_type.EntityType.Entity] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1151,7 +1153,7 @@ def batch_update_entities( parent: str = None, entities: Sequence[entity_type.EntityType.Entity] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1283,7 +1285,7 @@ def batch_delete_entities( parent: str = None, entity_values: Sequence[str] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/google/cloud/dialogflow_v2/services/entity_types/transports/base.py b/google/cloud/dialogflow_v2/services/entity_types/transports/base.py index f0be661d2..5df41c1d6 100644 --- a/google/cloud/dialogflow_v2/services/entity_types/transports/base.py +++ b/google/cloud/dialogflow_v2/services/entity_types/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 @@ -41,15 +40,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 EntityTypesTransport(abc.ABC): """Abstract transport class for EntityTypes.""" @@ -102,7 +92,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 @@ -135,29 +125,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 = { @@ -213,7 +180,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py b/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py index 93ac606df..b15a9ab26 100644 --- a/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py +++ b/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py @@ -115,7 +115,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py index 6f3f42d4c..f1c07c47b 100644 --- a/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -162,7 +161,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2/services/environments/async_client.py b/google/cloud/dialogflow_v2/services/environments/async_client.py index 4d83b3aa8..4595caf9c 100644 --- a/google/cloud/dialogflow_v2/services/environments/async_client.py +++ b/google/cloud/dialogflow_v2/services/environments/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.dialogflow_v2.services.environments import pagers from google.cloud.dialogflow_v2.types import environment from google.cloud.dialogflow_v2.types import fulfillment @@ -167,10 +169,10 @@ def __init__( async def list_environments( self, - request: environment.ListEnvironmentsRequest = None, + request: Union[environment.ListEnvironmentsRequest, 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.ListEnvironmentsAsyncPager: @@ -178,7 +180,7 @@ async def list_environments( the specified agent. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListEnvironmentsRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListEnvironmentsRequest, dict]): The request object. The request message for [Environments.ListEnvironments][google.cloud.dialogflow.v2.Environments.ListEnvironments]. parent (:class:`str`): @@ -251,16 +253,16 @@ async def list_environments( async def get_environment( self, - request: environment.GetEnvironmentRequest = None, + request: Union[environment.GetEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: r"""Retrieves the specified agent environment. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetEnvironmentRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetEnvironmentRequest, dict]): The request object. The request message for [Environments.GetEnvironment][google.cloud.dialogflow.v2.Environments.GetEnvironment]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -319,16 +321,16 @@ async def get_environment( async def create_environment( self, - request: environment.CreateEnvironmentRequest = None, + request: Union[environment.CreateEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: r"""Creates an agent environment. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateEnvironmentRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateEnvironmentRequest, dict]): The request object. The request message for [Environments.CreateEnvironment][google.cloud.dialogflow.v2.Environments.CreateEnvironment]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -387,9 +389,9 @@ async def create_environment( async def update_environment( self, - request: environment.UpdateEnvironmentRequest = None, + request: Union[environment.UpdateEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: @@ -409,7 +411,7 @@ async def update_environment( calling this method. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateEnvironmentRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateEnvironmentRequest, dict]): The request object. The request message for [Environments.UpdateEnvironment][google.cloud.dialogflow.v2.Environments.UpdateEnvironment]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -470,16 +472,16 @@ async def update_environment( async def delete_environment( self, - request: environment.DeleteEnvironmentRequest = None, + request: Union[environment.DeleteEnvironmentRequest, dict] = 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 the specified agent environment. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteEnvironmentRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteEnvironmentRequest, dict]): The request object. The request message for [Environments.DeleteEnvironment][google.cloud.dialogflow.v2.Environments.DeleteEnvironment]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -512,16 +514,16 @@ async def delete_environment( async def get_environment_history( self, - request: environment.GetEnvironmentHistoryRequest = None, + request: Union[environment.GetEnvironmentHistoryRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GetEnvironmentHistoryAsyncPager: r"""Gets the history of the specified environment. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetEnvironmentHistoryRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetEnvironmentHistoryRequest, dict]): The request object. The request message for [Environments.GetEnvironmentHistory][google.cloud.dialogflow.v2.Environments.GetEnvironmentHistory]. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/dialogflow_v2/services/environments/client.py b/google/cloud/dialogflow_v2/services/environments/client.py index 157714ec0..ad5f335e2 100644 --- a/google/cloud/dialogflow_v2/services/environments/client.py +++ b/google/cloud/dialogflow_v2/services/environments/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.dialogflow_v2.services.environments import pagers from google.cloud.dialogflow_v2.types import environment from google.cloud.dialogflow_v2.types import fulfillment @@ -379,7 +381,7 @@ def list_environments( request: Union[environment.ListEnvironmentsRequest, 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.ListEnvironmentsPager: @@ -462,7 +464,7 @@ def get_environment( self, request: Union[environment.GetEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: @@ -531,7 +533,7 @@ def create_environment( self, request: Union[environment.CreateEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: @@ -600,7 +602,7 @@ def update_environment( self, request: Union[environment.UpdateEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: @@ -684,7 +686,7 @@ def delete_environment( self, request: Union[environment.DeleteEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -727,7 +729,7 @@ def get_environment_history( self, request: Union[environment.GetEnvironmentHistoryRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GetEnvironmentHistoryPager: diff --git a/google/cloud/dialogflow_v2/services/environments/transports/base.py b/google/cloud/dialogflow_v2/services/environments/transports/base.py index 3e9662f0d..6e833d2b0 100644 --- a/google/cloud/dialogflow_v2/services/environments/transports/base.py +++ b/google/cloud/dialogflow_v2/services/environments/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 EnvironmentsTransport(abc.ABC): """Abstract transport class for Environments.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2/services/environments/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py index 659106463..b0a927add 100644 --- a/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/environments/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/dialogflow_v2/services/fulfillments/async_client.py b/google/cloud/dialogflow_v2/services/fulfillments/async_client.py index 95c4d08ea..bac283472 100644 --- a/google/cloud/dialogflow_v2/services/fulfillments/async_client.py +++ b/google/cloud/dialogflow_v2/services/fulfillments/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.dialogflow_v2.types import fulfillment from google.cloud.dialogflow_v2.types import fulfillment as gcd_fulfillment from google.protobuf import field_mask_pb2 # type: ignore @@ -162,17 +164,17 @@ def __init__( async def get_fulfillment( self, - request: fulfillment.GetFulfillmentRequest = None, + request: Union[fulfillment.GetFulfillmentRequest, 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]] = (), ) -> fulfillment.Fulfillment: r"""Retrieves the fulfillment. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetFulfillmentRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetFulfillmentRequest, dict]): The request object. The request message for [Fulfillments.GetFulfillment][google.cloud.dialogflow.v2.Fulfillments.GetFulfillment]. name (:class:`str`): @@ -243,18 +245,18 @@ async def get_fulfillment( async def update_fulfillment( self, - request: gcd_fulfillment.UpdateFulfillmentRequest = None, + request: Union[gcd_fulfillment.UpdateFulfillmentRequest, dict] = None, *, fulfillment: gcd_fulfillment.Fulfillment = 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]] = (), ) -> gcd_fulfillment.Fulfillment: r"""Updates the fulfillment. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateFulfillmentRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateFulfillmentRequest, dict]): The request object. The request message for [Fulfillments.UpdateFulfillment][google.cloud.dialogflow.v2.Fulfillments.UpdateFulfillment]. fulfillment (:class:`google.cloud.dialogflow_v2.types.Fulfillment`): diff --git a/google/cloud/dialogflow_v2/services/fulfillments/client.py b/google/cloud/dialogflow_v2/services/fulfillments/client.py index 22f4d67a8..12b82f79d 100644 --- a/google/cloud/dialogflow_v2/services/fulfillments/client.py +++ b/google/cloud/dialogflow_v2/services/fulfillments/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.dialogflow_v2.types import fulfillment from google.cloud.dialogflow_v2.types import fulfillment as gcd_fulfillment from google.protobuf import field_mask_pb2 # type: ignore @@ -348,7 +350,7 @@ def get_fulfillment( request: Union[fulfillment.GetFulfillmentRequest, 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]] = (), ) -> fulfillment.Fulfillment: @@ -430,7 +432,7 @@ def update_fulfillment( *, fulfillment: gcd_fulfillment.Fulfillment = 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]] = (), ) -> gcd_fulfillment.Fulfillment: diff --git a/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py b/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py index 372a1e3d7..fa12c38d0 100644 --- a/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py +++ b/google/cloud/dialogflow_v2/services/fulfillments/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 FulfillmentsTransport(abc.ABC): """Abstract transport class for Fulfillments.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py index 7c2aa28b4..7214c3754 100644 --- a/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/fulfillments/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/dialogflow_v2/services/intents/async_client.py b/google/cloud/dialogflow_v2/services/intents/async_client.py index e4a353208..99bf99dc0 100644 --- a/google/cloud/dialogflow_v2/services/intents/async_client.py +++ b/google/cloud/dialogflow_v2/services/intents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2.services.intents import pagers @@ -164,11 +166,11 @@ def __init__( async def list_intents( self, - request: intent.ListIntentsRequest = None, + request: Union[intent.ListIntentsRequest, dict] = None, *, parent: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIntentsAsyncPager: @@ -176,7 +178,7 @@ async def list_intents( agent. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListIntentsRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListIntentsRequest, dict]): The request object. The request message for [Intents.ListIntents][google.cloud.dialogflow.v2.Intents.ListIntents]. parent (:class:`str`): @@ -267,18 +269,18 @@ async def list_intents( async def get_intent( self, - request: intent.GetIntentRequest = None, + request: Union[intent.GetIntentRequest, dict] = None, *, name: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> intent.Intent: r"""Retrieves the specified intent. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetIntentRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetIntentRequest, dict]): The request object. The request message for [Intents.GetIntent][google.cloud.dialogflow.v2.Intents.GetIntent]. name (:class:`str`): @@ -360,12 +362,12 @@ async def get_intent( async def create_intent( self, - request: gcd_intent.CreateIntentRequest = None, + request: Union[gcd_intent.CreateIntentRequest, dict] = None, *, parent: str = None, intent: gcd_intent.Intent = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_intent.Intent: @@ -376,7 +378,7 @@ async def create_intent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateIntentRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateIntentRequest, dict]): The request object. The request message for [Intents.CreateIntent][google.cloud.dialogflow.v2.Intents.CreateIntent]. parent (:class:`str`): @@ -465,12 +467,12 @@ async def create_intent( async def update_intent( self, - request: gcd_intent.UpdateIntentRequest = None, + request: Union[gcd_intent.UpdateIntentRequest, dict] = None, *, intent: gcd_intent.Intent = None, language_code: str = 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]] = (), ) -> gcd_intent.Intent: @@ -481,7 +483,7 @@ async def update_intent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateIntentRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateIntentRequest, dict]): The request object. The request message for [Intents.UpdateIntent][google.cloud.dialogflow.v2.Intents.UpdateIntent]. intent (:class:`google.cloud.dialogflow_v2.types.Intent`): @@ -572,10 +574,10 @@ async def update_intent( async def delete_intent( self, - request: intent.DeleteIntentRequest = None, + request: Union[intent.DeleteIntentRequest, 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: @@ -587,7 +589,7 @@ async def delete_intent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteIntentRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteIntentRequest, dict]): The request object. The request message for [Intents.DeleteIntent][google.cloud.dialogflow.v2.Intents.DeleteIntent]. name (:class:`str`): @@ -643,12 +645,12 @@ async def delete_intent( async def batch_update_intents( self, - request: intent.BatchUpdateIntentsRequest = None, + request: Union[intent.BatchUpdateIntentsRequest, dict] = None, *, parent: str = None, intent_batch_uri: str = None, intent_batch_inline: intent.IntentBatch = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -669,7 +671,7 @@ async def batch_update_intents( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.BatchUpdateIntentsRequest`): + request (Union[google.cloud.dialogflow_v2.types.BatchUpdateIntentsRequest, dict]): The request object. parent (:class:`str`): Required. The name of the agent to update or create @@ -763,11 +765,11 @@ async def batch_update_intents( async def batch_delete_intents( self, - request: intent.BatchDeleteIntentsRequest = None, + request: Union[intent.BatchDeleteIntentsRequest, dict] = None, *, parent: str = None, intents: Sequence[intent.Intent] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -788,7 +790,7 @@ async def batch_delete_intents( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.BatchDeleteIntentsRequest`): + request (Union[google.cloud.dialogflow_v2.types.BatchDeleteIntentsRequest, dict]): The request object. The request message for [Intents.BatchDeleteIntents][google.cloud.dialogflow.v2.Intents.BatchDeleteIntents]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2/services/intents/client.py b/google/cloud/dialogflow_v2/services/intents/client.py index 1363372a8..31edcd412 100644 --- a/google/cloud/dialogflow_v2/services/intents/client.py +++ b/google/cloud/dialogflow_v2/services/intents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2.services.intents import pagers @@ -371,7 +373,7 @@ def list_intents( *, parent: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIntentsPager: @@ -474,7 +476,7 @@ def get_intent( *, name: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> intent.Intent: @@ -568,7 +570,7 @@ def create_intent( parent: str = None, intent: gcd_intent.Intent = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_intent.Intent: @@ -673,7 +675,7 @@ def update_intent( intent: gcd_intent.Intent = None, language_code: str = 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]] = (), ) -> gcd_intent.Intent: @@ -778,7 +780,7 @@ def delete_intent( request: Union[intent.DeleteIntentRequest, 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: @@ -851,7 +853,7 @@ def batch_update_intents( parent: str = None, intent_batch_uri: str = None, intent_batch_inline: intent.IntentBatch = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -970,7 +972,7 @@ def batch_delete_intents( *, parent: str = None, intents: Sequence[intent.Intent] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/google/cloud/dialogflow_v2/services/intents/transports/base.py b/google/cloud/dialogflow_v2/services/intents/transports/base.py index 1c7e61b3a..89b85d21b 100644 --- a/google/cloud/dialogflow_v2/services/intents/transports/base.py +++ b/google/cloud/dialogflow_v2/services/intents/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 @@ -41,15 +40,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 IntentsTransport(abc.ABC): """Abstract transport class for Intents.""" @@ -102,7 +92,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 @@ -135,29 +125,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 = { @@ -198,7 +165,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/dialogflow_v2/services/intents/transports/grpc.py b/google/cloud/dialogflow_v2/services/intents/transports/grpc.py index 748c1bf42..038b30ce1 100644 --- a/google/cloud/dialogflow_v2/services/intents/transports/grpc.py +++ b/google/cloud/dialogflow_v2/services/intents/transports/grpc.py @@ -114,7 +114,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py index f2570e27c..0fa796a24 100644 --- a/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -161,7 +160,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py b/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py index 0416e1590..f44152d8b 100644 --- a/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py +++ b/google/cloud/dialogflow_v2/services/knowledge_bases/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.dialogflow_v2.services.knowledge_bases import pagers from google.cloud.dialogflow_v2.types import knowledge_base from google.cloud.dialogflow_v2.types import knowledge_base as gcd_knowledge_base @@ -169,10 +171,10 @@ def __init__( async def list_knowledge_bases( self, - request: knowledge_base.ListKnowledgeBasesRequest = None, + request: Union[knowledge_base.ListKnowledgeBasesRequest, 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.ListKnowledgeBasesAsyncPager: @@ -180,7 +182,7 @@ async def list_knowledge_bases( specified agent. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListKnowledgeBasesRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListKnowledgeBasesRequest, dict]): The request object. Request message for [KnowledgeBases.ListKnowledgeBases][google.cloud.dialogflow.v2.KnowledgeBases.ListKnowledgeBases]. parent (:class:`str`): @@ -251,17 +253,17 @@ async def list_knowledge_bases( async def get_knowledge_base( self, - request: knowledge_base.GetKnowledgeBaseRequest = None, + request: Union[knowledge_base.GetKnowledgeBaseRequest, 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]] = (), ) -> knowledge_base.KnowledgeBase: r"""Retrieves the specified knowledge base. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetKnowledgeBaseRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetKnowledgeBaseRequest, dict]): The request object. Request message for [KnowledgeBases.GetKnowledgeBase][google.cloud.dialogflow.v2.KnowledgeBases.GetKnowledgeBase]. name (:class:`str`): @@ -333,18 +335,18 @@ async def get_knowledge_base( async def create_knowledge_base( self, - request: gcd_knowledge_base.CreateKnowledgeBaseRequest = None, + request: Union[gcd_knowledge_base.CreateKnowledgeBaseRequest, dict] = None, *, parent: str = None, knowledge_base: gcd_knowledge_base.KnowledgeBase = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_knowledge_base.KnowledgeBase: r"""Creates a knowledge base. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateKnowledgeBaseRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateKnowledgeBaseRequest, dict]): The request object. Request message for [KnowledgeBases.CreateKnowledgeBase][google.cloud.dialogflow.v2.KnowledgeBases.CreateKnowledgeBase]. parent (:class:`str`): @@ -425,17 +427,17 @@ async def create_knowledge_base( async def delete_knowledge_base( self, - request: knowledge_base.DeleteKnowledgeBaseRequest = None, + request: Union[knowledge_base.DeleteKnowledgeBaseRequest, 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 the specified knowledge base. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteKnowledgeBaseRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteKnowledgeBaseRequest, dict]): The request object. Request message for [KnowledgeBases.DeleteKnowledgeBase][google.cloud.dialogflow.v2.KnowledgeBases.DeleteKnowledgeBase]. name (:class:`str`): @@ -490,18 +492,18 @@ async def delete_knowledge_base( async def update_knowledge_base( self, - request: gcd_knowledge_base.UpdateKnowledgeBaseRequest = None, + request: Union[gcd_knowledge_base.UpdateKnowledgeBaseRequest, dict] = None, *, knowledge_base: gcd_knowledge_base.KnowledgeBase = 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]] = (), ) -> gcd_knowledge_base.KnowledgeBase: r"""Updates the specified knowledge base. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateKnowledgeBaseRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateKnowledgeBaseRequest, dict]): The request object. Request message for [KnowledgeBases.UpdateKnowledgeBase][google.cloud.dialogflow.v2.KnowledgeBases.UpdateKnowledgeBase]. knowledge_base (:class:`google.cloud.dialogflow_v2.types.KnowledgeBase`): diff --git a/google/cloud/dialogflow_v2/services/knowledge_bases/client.py b/google/cloud/dialogflow_v2/services/knowledge_bases/client.py index 68fe63e09..ca79bd1df 100644 --- a/google/cloud/dialogflow_v2/services/knowledge_bases/client.py +++ b/google/cloud/dialogflow_v2/services/knowledge_bases/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.dialogflow_v2.services.knowledge_bases import pagers from google.cloud.dialogflow_v2.types import knowledge_base from google.cloud.dialogflow_v2.types import knowledge_base as gcd_knowledge_base @@ -355,7 +357,7 @@ def list_knowledge_bases( request: Union[knowledge_base.ListKnowledgeBasesRequest, 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.ListKnowledgeBasesPager: @@ -437,7 +439,7 @@ def get_knowledge_base( request: Union[knowledge_base.GetKnowledgeBaseRequest, 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]] = (), ) -> knowledge_base.KnowledgeBase: @@ -520,7 +522,7 @@ def create_knowledge_base( *, parent: str = None, knowledge_base: gcd_knowledge_base.KnowledgeBase = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_knowledge_base.KnowledgeBase: @@ -611,7 +613,7 @@ def delete_knowledge_base( request: Union[knowledge_base.DeleteKnowledgeBaseRequest, 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: @@ -677,7 +679,7 @@ def update_knowledge_base( *, knowledge_base: gcd_knowledge_base.KnowledgeBase = 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]] = (), ) -> gcd_knowledge_base.KnowledgeBase: diff --git a/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py b/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py index 268d72127..cde8f9742 100644 --- a/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py +++ b/google/cloud/dialogflow_v2/services/knowledge_bases/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 @@ -39,15 +38,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 KnowledgeBasesTransport(abc.ABC): """Abstract transport class for KnowledgeBases.""" @@ -100,7 +90,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 @@ -133,29 +123,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/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py index dabb41d2a..b4d759708 100644 --- a/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/knowledge_bases/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/dialogflow_v2/services/participants/async_client.py b/google/cloud/dialogflow_v2/services/participants/async_client.py index d7b55107d..b9680bf7f 100644 --- a/google/cloud/dialogflow_v2/services/participants/async_client.py +++ b/google/cloud/dialogflow_v2/services/participants/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.dialogflow_v2.services.participants import pagers from google.cloud.dialogflow_v2.types import participant from google.cloud.dialogflow_v2.types import participant as gcd_participant @@ -174,18 +176,18 @@ def __init__( async def create_participant( self, - request: gcd_participant.CreateParticipantRequest = None, + request: Union[gcd_participant.CreateParticipantRequest, dict] = None, *, parent: str = None, participant: gcd_participant.Participant = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_participant.Participant: r"""Creates a new participant in a conversation. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateParticipantRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateParticipantRequest, dict]): The request object. The request message for [Participants.CreateParticipant][google.cloud.dialogflow.v2.Participants.CreateParticipant]. parent (:class:`str`): @@ -254,17 +256,17 @@ async def create_participant( async def get_participant( self, - request: participant.GetParticipantRequest = None, + request: Union[participant.GetParticipantRequest, 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]] = (), ) -> participant.Participant: r"""Retrieves a conversation participant. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetParticipantRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetParticipantRequest, dict]): The request object. The request message for [Participants.GetParticipant][google.cloud.dialogflow.v2.Participants.GetParticipant]. name (:class:`str`): @@ -325,10 +327,10 @@ async def get_participant( async def list_participants( self, - request: participant.ListParticipantsRequest = None, + request: Union[participant.ListParticipantsRequest, 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.ListParticipantsAsyncPager: @@ -336,7 +338,7 @@ async def list_participants( conversation. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListParticipantsRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListParticipantsRequest, dict]): The request object. The request message for [Participants.ListParticipants][google.cloud.dialogflow.v2.Participants.ListParticipants]. parent (:class:`str`): @@ -407,18 +409,18 @@ async def list_participants( async def update_participant( self, - request: gcd_participant.UpdateParticipantRequest = None, + request: Union[gcd_participant.UpdateParticipantRequest, dict] = None, *, participant: gcd_participant.Participant = 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]] = (), ) -> gcd_participant.Participant: r"""Updates the specified participant. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateParticipantRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateParticipantRequest, dict]): The request object. The request message for [Participants.UpdateParticipant][google.cloud.dialogflow.v2.Participants.UpdateParticipant]. participant (:class:`google.cloud.dialogflow_v2.types.Participant`): @@ -488,12 +490,12 @@ async def update_participant( async def analyze_content( self, - request: gcd_participant.AnalyzeContentRequest = None, + request: Union[gcd_participant.AnalyzeContentRequest, dict] = None, *, participant: str = None, text_input: session.TextInput = None, event_input: session.EventInput = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_participant.AnalyzeContentResponse: @@ -505,7 +507,7 @@ async def analyze_content( environments `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.AnalyzeContentRequest`): + request (Union[google.cloud.dialogflow_v2.types.AnalyzeContentRequest, dict]): The request object. The request message for [Participants.AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent]. participant (:class:`str`): @@ -594,10 +596,10 @@ async def analyze_content( async def suggest_articles( self, - request: participant.SuggestArticlesRequest = None, + request: Union[participant.SuggestArticlesRequest, 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]] = (), ) -> participant.SuggestArticlesResponse: @@ -605,7 +607,7 @@ async def suggest_articles( specific historical messages. Args: - request (:class:`google.cloud.dialogflow_v2.types.SuggestArticlesRequest`): + request (Union[google.cloud.dialogflow_v2.types.SuggestArticlesRequest, dict]): The request object. The request message for [Participants.SuggestArticles][google.cloud.dialogflow.v2.Participants.SuggestArticles]. parent (:class:`str`): @@ -667,10 +669,10 @@ async def suggest_articles( async def suggest_faq_answers( self, - request: participant.SuggestFaqAnswersRequest = None, + request: Union[participant.SuggestFaqAnswersRequest, 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]] = (), ) -> participant.SuggestFaqAnswersResponse: @@ -678,7 +680,7 @@ async def suggest_faq_answers( specific historical messages. Args: - request (:class:`google.cloud.dialogflow_v2.types.SuggestFaqAnswersRequest`): + request (Union[google.cloud.dialogflow_v2.types.SuggestFaqAnswersRequest, dict]): The request object. The request message for [Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2.Participants.SuggestFaqAnswers]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2/services/participants/client.py b/google/cloud/dialogflow_v2/services/participants/client.py index 27bfaba9a..ef7bc6996 100644 --- a/google/cloud/dialogflow_v2/services/participants/client.py +++ b/google/cloud/dialogflow_v2/services/participants/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.dialogflow_v2.services.participants import pagers from google.cloud.dialogflow_v2.types import participant from google.cloud.dialogflow_v2.types import participant as gcd_participant @@ -417,7 +419,7 @@ def create_participant( *, parent: str = None, participant: gcd_participant.Participant = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_participant.Participant: @@ -496,7 +498,7 @@ def get_participant( request: Union[participant.GetParticipantRequest, 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]] = (), ) -> participant.Participant: @@ -567,7 +569,7 @@ def list_participants( request: Union[participant.ListParticipantsRequest, 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.ListParticipantsPager: @@ -650,7 +652,7 @@ def update_participant( *, participant: gcd_participant.Participant = 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]] = (), ) -> gcd_participant.Participant: @@ -732,7 +734,7 @@ def analyze_content( participant: str = None, text_input: session.TextInput = None, event_input: session.EventInput = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_participant.AnalyzeContentResponse: @@ -827,7 +829,7 @@ def suggest_articles( request: Union[participant.SuggestArticlesRequest, 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]] = (), ) -> participant.SuggestArticlesResponse: @@ -900,7 +902,7 @@ def suggest_faq_answers( request: Union[participant.SuggestFaqAnswersRequest, 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]] = (), ) -> participant.SuggestFaqAnswersResponse: diff --git a/google/cloud/dialogflow_v2/services/participants/transports/base.py b/google/cloud/dialogflow_v2/services/participants/transports/base.py index 0f180787e..8cd7efd0a 100644 --- a/google/cloud/dialogflow_v2/services/participants/transports/base.py +++ b/google/cloud/dialogflow_v2/services/participants/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 ParticipantsTransport(abc.ABC): """Abstract transport class for Participants.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2/services/participants/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py index df6a33c4b..f1e025860 100644 --- a/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/participants/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/dialogflow_v2/services/session_entity_types/async_client.py b/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py index 35aeccfa9..e73bd1f07 100644 --- a/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py +++ b/google/cloud/dialogflow_v2/services/session_entity_types/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.dialogflow_v2.services.session_entity_types import pagers from google.cloud.dialogflow_v2.types import entity_type from google.cloud.dialogflow_v2.types import session_entity_type @@ -175,10 +177,10 @@ def __init__( async def list_session_entity_types( self, - request: session_entity_type.ListSessionEntityTypesRequest = None, + request: Union[session_entity_type.ListSessionEntityTypesRequest, 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.ListSessionEntityTypesAsyncPager: @@ -189,7 +191,7 @@ async def list_session_entity_types( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListSessionEntityTypesRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListSessionEntityTypesRequest, dict]): The request object. The request message for [SessionEntityTypes.ListSessionEntityTypes][google.cloud.dialogflow.v2.SessionEntityTypes.ListSessionEntityTypes]. parent (:class:`str`): @@ -264,10 +266,10 @@ async def list_session_entity_types( async def get_session_entity_type( self, - request: session_entity_type.GetSessionEntityTypeRequest = None, + request: Union[session_entity_type.GetSessionEntityTypeRequest, 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]] = (), ) -> session_entity_type.SessionEntityType: @@ -277,7 +279,7 @@ async def get_session_entity_type( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetSessionEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetSessionEntityTypeRequest, dict]): The request object. The request message for [SessionEntityTypes.GetSessionEntityType][google.cloud.dialogflow.v2.SessionEntityTypes.GetSessionEntityType]. name (:class:`str`): @@ -351,11 +353,13 @@ async def get_session_entity_type( async def create_session_entity_type( self, - request: gcd_session_entity_type.CreateSessionEntityTypeRequest = None, + request: Union[ + gcd_session_entity_type.CreateSessionEntityTypeRequest, dict + ] = None, *, parent: str = None, session_entity_type: gcd_session_entity_type.SessionEntityType = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session_entity_type.SessionEntityType: @@ -368,7 +372,7 @@ async def create_session_entity_type( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateSessionEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateSessionEntityTypeRequest, dict]): The request object. The request message for [SessionEntityTypes.CreateSessionEntityType][google.cloud.dialogflow.v2.SessionEntityTypes.CreateSessionEntityType]. parent (:class:`str`): @@ -451,11 +455,13 @@ async def create_session_entity_type( async def update_session_entity_type( self, - request: gcd_session_entity_type.UpdateSessionEntityTypeRequest = None, + request: Union[ + gcd_session_entity_type.UpdateSessionEntityTypeRequest, dict + ] = None, *, session_entity_type: gcd_session_entity_type.SessionEntityType = 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]] = (), ) -> gcd_session_entity_type.SessionEntityType: @@ -465,7 +471,7 @@ async def update_session_entity_type( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateSessionEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateSessionEntityTypeRequest, dict]): The request object. The request message for [SessionEntityTypes.UpdateSessionEntityType][google.cloud.dialogflow.v2.SessionEntityTypes.UpdateSessionEntityType]. session_entity_type (:class:`google.cloud.dialogflow_v2.types.SessionEntityType`): @@ -545,10 +551,10 @@ async def update_session_entity_type( async def delete_session_entity_type( self, - request: session_entity_type.DeleteSessionEntityTypeRequest = None, + request: Union[session_entity_type.DeleteSessionEntityTypeRequest, 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: @@ -558,7 +564,7 @@ async def delete_session_entity_type( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteSessionEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteSessionEntityTypeRequest, dict]): The request object. The request message for [SessionEntityTypes.DeleteSessionEntityType][google.cloud.dialogflow.v2.SessionEntityTypes.DeleteSessionEntityType]. name (:class:`str`): diff --git a/google/cloud/dialogflow_v2/services/session_entity_types/client.py b/google/cloud/dialogflow_v2/services/session_entity_types/client.py index b174431ce..a30a54d5e 100644 --- a/google/cloud/dialogflow_v2/services/session_entity_types/client.py +++ b/google/cloud/dialogflow_v2/services/session_entity_types/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.dialogflow_v2.services.session_entity_types import pagers from google.cloud.dialogflow_v2.types import entity_type from google.cloud.dialogflow_v2.types import session_entity_type @@ -361,7 +363,7 @@ def list_session_entity_types( request: Union[session_entity_type.ListSessionEntityTypesRequest, 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.ListSessionEntityTypesPager: @@ -452,7 +454,7 @@ def get_session_entity_type( request: Union[session_entity_type.GetSessionEntityTypeRequest, 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]] = (), ) -> session_entity_type.SessionEntityType: @@ -542,7 +544,7 @@ def create_session_entity_type( *, parent: str = None, session_entity_type: gcd_session_entity_type.SessionEntityType = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session_entity_type.SessionEntityType: @@ -648,7 +650,7 @@ def update_session_entity_type( *, session_entity_type: gcd_session_entity_type.SessionEntityType = 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]] = (), ) -> gcd_session_entity_type.SessionEntityType: @@ -745,7 +747,7 @@ def delete_session_entity_type( request: Union[session_entity_type.DeleteSessionEntityTypeRequest, 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: diff --git a/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py b/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py index cf7b13128..6cff1880d 100644 --- a/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py +++ b/google/cloud/dialogflow_v2/services/session_entity_types/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 @@ -41,15 +40,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 SessionEntityTypesTransport(abc.ABC): """Abstract transport class for SessionEntityTypes.""" @@ -102,7 +92,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 @@ -135,29 +125,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/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py index a6d8f3b3b..1ceaee091 100644 --- a/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/session_entity_types/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/dialogflow_v2/services/sessions/async_client.py b/google/cloud/dialogflow_v2/services/sessions/async_client.py index 16483e563..b33ed8611 100644 --- a/google/cloud/dialogflow_v2/services/sessions/async_client.py +++ b/google/cloud/dialogflow_v2/services/sessions/async_client.py @@ -28,13 +28,15 @@ ) 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.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import session from google.cloud.dialogflow_v2.types import session as gcd_session @@ -178,11 +180,11 @@ def __init__( async def detect_intent( self, - request: gcd_session.DetectIntentRequest = None, + request: Union[gcd_session.DetectIntentRequest, dict] = None, *, session: str = None, query_input: gcd_session.QueryInput = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session.DetectIntentResponse: @@ -203,7 +205,7 @@ async def detect_intent( environments `__. Args: - request (:class:`google.cloud.dialogflow_v2.types.DetectIntentRequest`): + request (Union[google.cloud.dialogflow_v2.types.DetectIntentRequest, dict]): The request object. The request to detect user's intent. session (:class:`str`): Required. The name of the session this query is sent to. @@ -310,7 +312,7 @@ def streaming_detect_intent( self, requests: AsyncIterator[session.StreamingDetectIntentRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[session.StreamingDetectIntentResponse]]: diff --git a/google/cloud/dialogflow_v2/services/sessions/client.py b/google/cloud/dialogflow_v2/services/sessions/client.py index 92a4e8f85..ad4c9bb3a 100644 --- a/google/cloud/dialogflow_v2/services/sessions/client.py +++ b/google/cloud/dialogflow_v2/services/sessions/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.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import session from google.cloud.dialogflow_v2.types import session as gcd_session @@ -401,7 +403,7 @@ def detect_intent( *, session: str = None, query_input: gcd_session.QueryInput = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session.DetectIntentResponse: @@ -520,7 +522,7 @@ def streaming_detect_intent( self, requests: Iterator[session.StreamingDetectIntentRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[session.StreamingDetectIntentResponse]: diff --git a/google/cloud/dialogflow_v2/services/sessions/transports/base.py b/google/cloud/dialogflow_v2/services/sessions/transports/base.py index e3c1432b6..a0f7252d6 100644 --- a/google/cloud/dialogflow_v2/services/sessions/transports/base.py +++ b/google/cloud/dialogflow_v2/services/sessions/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 SessionsTransport(abc.ABC): """Abstract transport class for Sessions.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2/services/sessions/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py index 1ab0e3419..c14c7585e 100644 --- a/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/sessions/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/dialogflow_v2/services/versions/async_client.py b/google/cloud/dialogflow_v2/services/versions/async_client.py index 70fca103f..d790c2b17 100644 --- a/google/cloud/dialogflow_v2/services/versions/async_client.py +++ b/google/cloud/dialogflow_v2/services/versions/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.dialogflow_v2.services.versions import pagers from google.cloud.dialogflow_v2.types import version from google.cloud.dialogflow_v2.types import version as gcd_version @@ -158,10 +160,10 @@ def __init__( async def list_versions( self, - request: version.ListVersionsRequest = None, + request: Union[version.ListVersionsRequest, 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.ListVersionsAsyncPager: @@ -169,7 +171,7 @@ async def list_versions( agent. Args: - request (:class:`google.cloud.dialogflow_v2.types.ListVersionsRequest`): + request (Union[google.cloud.dialogflow_v2.types.ListVersionsRequest, dict]): The request object. The request message for [Versions.ListVersions][google.cloud.dialogflow.v2.Versions.ListVersions]. parent (:class:`str`): @@ -242,17 +244,17 @@ async def list_versions( async def get_version( self, - request: version.GetVersionRequest = None, + request: Union[version.GetVersionRequest, 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]] = (), ) -> version.Version: r"""Retrieves the specified agent version. Args: - request (:class:`google.cloud.dialogflow_v2.types.GetVersionRequest`): + request (Union[google.cloud.dialogflow_v2.types.GetVersionRequest, dict]): The request object. The request message for [Versions.GetVersion][google.cloud.dialogflow.v2.Versions.GetVersion]. name (:class:`str`): @@ -334,11 +336,11 @@ async def get_version( async def create_version( self, - request: gcd_version.CreateVersionRequest = None, + request: Union[gcd_version.CreateVersionRequest, dict] = None, *, parent: str = None, version: gcd_version.Version = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_version.Version: @@ -347,7 +349,7 @@ async def create_version( "default" environment. Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateVersionRequest`): + request (Union[google.cloud.dialogflow_v2.types.CreateVersionRequest, dict]): The request object. The request message for [Versions.CreateVersion][google.cloud.dialogflow.v2.Versions.CreateVersion]. parent (:class:`str`): @@ -437,11 +439,11 @@ async def create_version( async def update_version( self, - request: gcd_version.UpdateVersionRequest = None, + request: Union[gcd_version.UpdateVersionRequest, dict] = None, *, version: gcd_version.Version = 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]] = (), ) -> gcd_version.Version: @@ -452,7 +454,7 @@ async def update_version( version resource. Args: - request (:class:`google.cloud.dialogflow_v2.types.UpdateVersionRequest`): + request (Union[google.cloud.dialogflow_v2.types.UpdateVersionRequest, dict]): The request object. The request message for [Versions.UpdateVersion][google.cloud.dialogflow.v2.Versions.UpdateVersion]. version (:class:`google.cloud.dialogflow_v2.types.Version`): @@ -545,17 +547,17 @@ async def update_version( async def delete_version( self, - request: version.DeleteVersionRequest = None, + request: Union[version.DeleteVersionRequest, 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"""Delete the specified agent version. Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteVersionRequest`): + request (Union[google.cloud.dialogflow_v2.types.DeleteVersionRequest, dict]): The request object. The request message for [Versions.DeleteVersion][google.cloud.dialogflow.v2.Versions.DeleteVersion]. name (:class:`str`): diff --git a/google/cloud/dialogflow_v2/services/versions/client.py b/google/cloud/dialogflow_v2/services/versions/client.py index 64a1a55fd..6bc82222a 100644 --- a/google/cloud/dialogflow_v2/services/versions/client.py +++ b/google/cloud/dialogflow_v2/services/versions/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.dialogflow_v2.services.versions import pagers from google.cloud.dialogflow_v2.types import version from google.cloud.dialogflow_v2.types import version as gcd_version @@ -352,7 +354,7 @@ def list_versions( request: Union[version.ListVersionsRequest, 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.ListVersionsPager: @@ -436,7 +438,7 @@ def get_version( request: Union[version.GetVersionRequest, 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]] = (), ) -> version.Version: @@ -529,7 +531,7 @@ def create_version( *, parent: str = None, version: gcd_version.Version = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_version.Version: @@ -632,7 +634,7 @@ def update_version( *, version: gcd_version.Version = 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]] = (), ) -> gcd_version.Version: @@ -739,7 +741,7 @@ def delete_version( request: Union[version.DeleteVersionRequest, 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: diff --git a/google/cloud/dialogflow_v2/services/versions/transports/base.py b/google/cloud/dialogflow_v2/services/versions/transports/base.py index 7f54bedbf..b61589172 100644 --- a/google/cloud/dialogflow_v2/services/versions/transports/base.py +++ b/google/cloud/dialogflow_v2/services/versions/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 @@ -39,15 +38,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 VersionsTransport(abc.ABC): """Abstract transport class for Versions.""" @@ -100,7 +90,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 @@ -133,29 +123,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/dialogflow_v2/services/versions/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py index ea3c282a3..dcd914910 100644 --- a/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/versions/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/dialogflow_v2/types/agent.py b/google/cloud/dialogflow_v2/types/agent.py index 7cee91fec..26fb8c771 100644 --- a/google/cloud/dialogflow_v2/types/agent.py +++ b/google/cloud/dialogflow_v2/types/agent.py @@ -269,13 +269,22 @@ class ExportAgentResponse(proto.Message): r"""The response message for [Agents.ExportAgent][google.cloud.dialogflow.v2.Agents.ExportAgent]. + 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: agent_uri (str): The URI to a file containing the exported agent. This field is populated only if ``agent_uri`` is specified in ``ExportAgentRequest``. + This field is a member of `oneof`_ ``agent``. agent_content (bytes): Zip compressed raw byte content for agent. + This field is a member of `oneof`_ ``agent``. """ agent_uri = proto.Field(proto.STRING, number=1, oneof="agent",) @@ -286,6 +295,13 @@ class ImportAgentRequest(proto.Message): r"""The request message for [Agents.ImportAgent][google.cloud.dialogflow.v2.Agents.ImportAgent]. + 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: parent (str): Required. The project that the agent to import is associated @@ -294,8 +310,10 @@ class ImportAgentRequest(proto.Message): The URI to a Google Cloud Storage file containing the agent to import. Note: The URI must start with "gs://". + This field is a member of `oneof`_ ``agent``. agent_content (bytes): Zip compressed raw byte content for agent. + This field is a member of `oneof`_ ``agent``. """ parent = proto.Field(proto.STRING, number=1,) @@ -307,6 +325,13 @@ class RestoreAgentRequest(proto.Message): r"""The request message for [Agents.RestoreAgent][google.cloud.dialogflow.v2.Agents.RestoreAgent]. + 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: parent (str): Required. The project that the agent to restore is @@ -315,8 +340,10 @@ class RestoreAgentRequest(proto.Message): The URI to a Google Cloud Storage file containing the agent to restore. Note: The URI must start with "gs://". + This field is a member of `oneof`_ ``agent``. agent_content (bytes): Zip compressed raw byte content for agent. + This field is a member of `oneof`_ ``agent``. """ parent = proto.Field(proto.STRING, number=1,) diff --git a/google/cloud/dialogflow_v2/types/answer_record.py b/google/cloud/dialogflow_v2/types/answer_record.py index 93f3c4caf..ea69fa34d 100644 --- a/google/cloud/dialogflow_v2/types/answer_record.py +++ b/google/cloud/dialogflow_v2/types/answer_record.py @@ -64,6 +64,9 @@ class AnswerRecord(proto.Message): to call the [UpdateAnswerRecord][] method to send feedback about a specific answer that they believe is wrong. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): The unique identifier of this answer record. Format: @@ -76,6 +79,7 @@ class AnswerRecord(proto.Message): agent_assistant_record (google.cloud.dialogflow_v2.types.AgentAssistantRecord): Output only. The record for human agent assistant. + This field is a member of `oneof`_ ``record``. """ name = proto.Field(proto.STRING, number=1,) @@ -167,11 +171,15 @@ class AnswerFeedback(proto.Message): r"""Represents feedback the customer has about the quality & correctness of a certain answer in a conversation. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: correctness_level (google.cloud.dialogflow_v2.types.AnswerFeedback.CorrectnessLevel): The correctness level of the specific answer. agent_assistant_detail_feedback (google.cloud.dialogflow_v2.types.AgentAssistantFeedback): Detail feedback of agent assist suggestions. + This field is a member of `oneof`_ ``detail_feedback``. clicked (bool): Indicates whether the answer/item was clicked by the human agent or not. Default to false. @@ -269,11 +277,20 @@ class DocumentEfficiency(proto.Enum): class AgentAssistantRecord(proto.Message): r"""Represents a record of a human agent assist answer. + 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: article_suggestion_answer (google.cloud.dialogflow_v2.types.ArticleAnswer): Output only. The article suggestion answer. + This field is a member of `oneof`_ ``answer``. faq_answer (google.cloud.dialogflow_v2.types.FaqAnswer): Output only. The FAQ answer. + This field is a member of `oneof`_ ``answer``. """ article_suggestion_answer = proto.Field( diff --git a/google/cloud/dialogflow_v2/types/conversation_event.py b/google/cloud/dialogflow_v2/types/conversation_event.py index 193259b4f..2a13785c8 100644 --- a/google/cloud/dialogflow_v2/types/conversation_event.py +++ b/google/cloud/dialogflow_v2/types/conversation_event.py @@ -28,6 +28,9 @@ class ConversationEvent(proto.Message): r"""Represents a notification sent to Pub/Sub subscribers for conversation lifecycle events. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: conversation (str): The unique identifier of the conversation this notification @@ -41,6 +44,7 @@ class ConversationEvent(proto.Message): UNRECOVERABLE_ERROR_IN_PHONE_CALL. new_message_payload (google.cloud.dialogflow_v2.types.Message): Payload of NEW_MESSAGE event. + This field is a member of `oneof`_ ``payload``. """ class Type(proto.Enum): diff --git a/google/cloud/dialogflow_v2/types/conversation_profile.py b/google/cloud/dialogflow_v2/types/conversation_profile.py index d76938f1c..134709715 100644 --- a/google/cloud/dialogflow_v2/types/conversation_profile.py +++ b/google/cloud/dialogflow_v2/types/conversation_profile.py @@ -365,16 +365,26 @@ class SuggestionConfig(proto.Message): class SuggestionQueryConfig(proto.Message): r"""Config for suggestion query. + 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: knowledge_base_query_source (google.cloud.dialogflow_v2.types.HumanAgentAssistantConfig.SuggestionQueryConfig.KnowledgeBaseQuerySource): Query from knowledgebase. It is used by: ARTICLE_SUGGESTION, FAQ. + This field is a member of `oneof`_ ``query_source``. document_query_source (google.cloud.dialogflow_v2.types.HumanAgentAssistantConfig.SuggestionQueryConfig.DocumentQuerySource): Query from knowledge base document. It is used by: SMART_REPLY, SMART_COMPOSE. + This field is a member of `oneof`_ ``query_source``. dialogflow_query_source (google.cloud.dialogflow_v2.types.HumanAgentAssistantConfig.SuggestionQueryConfig.DialogflowQuerySource): Query from Dialogflow agent. It is used by DIALOGFLOW_ASSIST. + This field is a member of `oneof`_ ``query_source``. max_results (int): Maximum number of results to return. Currently, if unset, defaults to 10. And the max @@ -571,11 +581,20 @@ class HumanAgentHandoffConfig(proto.Message): Currently, this feature is not general available, please contact Google to get access. + 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: live_person_config (google.cloud.dialogflow_v2.types.HumanAgentHandoffConfig.LivePersonConfig): Uses LivePerson (https://www.liveperson.com). + This field is a member of `oneof`_ ``agent_service``. salesforce_live_agent_config (google.cloud.dialogflow_v2.types.HumanAgentHandoffConfig.SalesforceLiveAgentConfig): Uses Salesforce Live Agent. + This field is a member of `oneof`_ ``agent_service``. """ class LivePersonConfig(proto.Message): diff --git a/google/cloud/dialogflow_v2/types/document.py b/google/cloud/dialogflow_v2/types/document.py index 45efa7a75..3cbb40320 100644 --- a/google/cloud/dialogflow_v2/types/document.py +++ b/google/cloud/dialogflow_v2/types/document.py @@ -46,6 +46,13 @@ class Document(proto.Message): Note: The ``projects.agent.knowledgeBases.documents`` resource is deprecated; only use ``projects.knowledgeBases.documents``. + 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): Optional. The document resource name. The name must be empty @@ -71,9 +78,11 @@ class Document(proto.Message): URLs for showing documents in Google Cloud Storage (i.e. the URL in your browser) are not supported. Instead use the ``gs://`` format URI described above. + This field is a member of `oneof`_ ``source``. raw_content (bytes): The raw content of the document. This field is only permitted for EXTRACTIVE_QA and FAQ knowledge types. + This field is a member of `oneof`_ ``source``. enable_auto_reload (bool): Optional. If true, we try to automatically reload the document every day (at a time picked by the system). If @@ -250,6 +259,9 @@ class ReloadDocumentRequest(proto.Message): r"""Request message for [Documents.ReloadDocument][google.cloud.dialogflow.v2.Documents.ReloadDocument]. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): Required. The name of the document to reload. Format: @@ -260,6 +272,7 @@ class ReloadDocumentRequest(proto.Message): For documents stored in Google Cloud Storage, these URIs must have the form ``gs:///``. + This field is a member of `oneof`_ ``source``. """ name = proto.Field(proto.STRING, number=1,) diff --git a/google/cloud/dialogflow_v2/types/entity_type.py b/google/cloud/dialogflow_v2/types/entity_type.py index 8384ae360..cfa1fc77c 100644 --- a/google/cloud/dialogflow_v2/types/entity_type.py +++ b/google/cloud/dialogflow_v2/types/entity_type.py @@ -269,6 +269,13 @@ class BatchUpdateEntityTypesRequest(proto.Message): r"""The request message for [EntityTypes.BatchUpdateEntityTypes][google.cloud.dialogflow.v2.EntityTypes.BatchUpdateEntityTypes]. + 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: parent (str): Required. The name of the agent to update or create entity @@ -279,9 +286,11 @@ class BatchUpdateEntityTypesRequest(proto.Message): file format can either be a serialized proto (of EntityBatch type) or a JSON object. Note: The URI must start with "gs://". + This field is a member of `oneof`_ ``entity_type_batch``. entity_type_batch_inline (google.cloud.dialogflow_v2.types.EntityTypeBatch): The collection of entity types to update or create. + This field is a member of `oneof`_ ``entity_type_batch``. language_code (str): Optional. The language used to access language-specific data. If not specified, the agent's default language is diff --git a/google/cloud/dialogflow_v2/types/fulfillment.py b/google/cloud/dialogflow_v2/types/fulfillment.py index a54cb19d0..90b1b5017 100644 --- a/google/cloud/dialogflow_v2/types/fulfillment.py +++ b/google/cloud/dialogflow_v2/types/fulfillment.py @@ -36,6 +36,9 @@ class Fulfillment(proto.Message): For more information, see the `fulfillment guide `__. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): Required. The unique identifier of the fulfillment. @@ -52,6 +55,7 @@ class Fulfillment(proto.Message): Environment. generic_web_service (google.cloud.dialogflow_v2.types.Fulfillment.GenericWebService): Configuration for a generic web service. + This field is a member of `oneof`_ ``fulfillment``. enabled (bool): Optional. Whether fulfillment is enabled. features (Sequence[google.cloud.dialogflow_v2.types.Fulfillment.Feature]): diff --git a/google/cloud/dialogflow_v2/types/intent.py b/google/cloud/dialogflow_v2/types/intent.py index f53b9b3fb..fe2123ea3 100644 --- a/google/cloud/dialogflow_v2/types/intent.py +++ b/google/cloud/dialogflow_v2/types/intent.py @@ -310,39 +310,60 @@ class Message(proto.Message): response messages `__. + 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: text (google.cloud.dialogflow_v2.types.Intent.Message.Text): The text response. + This field is a member of `oneof`_ ``message``. image (google.cloud.dialogflow_v2.types.Intent.Message.Image): The image response. + This field is a member of `oneof`_ ``message``. quick_replies (google.cloud.dialogflow_v2.types.Intent.Message.QuickReplies): The quick replies response. + This field is a member of `oneof`_ ``message``. card (google.cloud.dialogflow_v2.types.Intent.Message.Card): The card response. + This field is a member of `oneof`_ ``message``. payload (google.protobuf.struct_pb2.Struct): A custom platform-specific response. + This field is a member of `oneof`_ ``message``. simple_responses (google.cloud.dialogflow_v2.types.Intent.Message.SimpleResponses): The voice and text-only responses for Actions on Google. + This field is a member of `oneof`_ ``message``. basic_card (google.cloud.dialogflow_v2.types.Intent.Message.BasicCard): The basic card response for Actions on Google. + This field is a member of `oneof`_ ``message``. suggestions (google.cloud.dialogflow_v2.types.Intent.Message.Suggestions): The suggestion chips for Actions on Google. + This field is a member of `oneof`_ ``message``. link_out_suggestion (google.cloud.dialogflow_v2.types.Intent.Message.LinkOutSuggestion): The link out suggestion chip for Actions on Google. + This field is a member of `oneof`_ ``message``. list_select (google.cloud.dialogflow_v2.types.Intent.Message.ListSelect): The list card response for Actions on Google. + This field is a member of `oneof`_ ``message``. carousel_select (google.cloud.dialogflow_v2.types.Intent.Message.CarouselSelect): The carousel card response for Actions on Google. + This field is a member of `oneof`_ ``message``. browse_carousel_card (google.cloud.dialogflow_v2.types.Intent.Message.BrowseCarouselCard): Browse carousel card for Actions on Google. + This field is a member of `oneof`_ ``message``. table_card (google.cloud.dialogflow_v2.types.Intent.Message.TableCard): Table card for Actions on Google. + This field is a member of `oneof`_ ``message``. media_content (google.cloud.dialogflow_v2.types.Intent.Message.MediaContent): The media content card for Actions on Google. + This field is a member of `oneof`_ ``message``. platform (google.cloud.dialogflow_v2.types.Intent.Message.Platform): Optional. The platform that this message is intended for. @@ -680,6 +701,13 @@ class ResponseMediaType(proto.Enum): class ResponseMediaObject(proto.Message): r"""Response media object for media content card. + 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. Name of media card. @@ -688,9 +716,11 @@ class ResponseMediaObject(proto.Message): large_image (google.cloud.dialogflow_v2.types.Intent.Message.Image): Optional. Image to display above media content. + This field is a member of `oneof`_ ``image``. icon (google.cloud.dialogflow_v2.types.Intent.Message.Image): Optional. Icon to display above media content. + This field is a member of `oneof`_ ``image``. content_url (str): Required. Url where the media is stored. """ @@ -1187,6 +1217,13 @@ class DeleteIntentRequest(proto.Message): class BatchUpdateIntentsRequest(proto.Message): r""" + 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: parent (str): Required. The name of the agent to update or create intents @@ -1197,9 +1234,11 @@ class BatchUpdateIntentsRequest(proto.Message): format can either be a serialized proto (of IntentBatch type) or JSON object. Note: The URI must start with "gs://". + This field is a member of `oneof`_ ``intent_batch``. intent_batch_inline (google.cloud.dialogflow_v2.types.IntentBatch): The collection of intents to update or create. + This field is a member of `oneof`_ ``intent_batch``. language_code (str): Optional. The language used to access language-specific data. If not specified, the agent's default language is diff --git a/google/cloud/dialogflow_v2/types/participant.py b/google/cloud/dialogflow_v2/types/participant.py index 0194fd9f8..58327d8e8 100644 --- a/google/cloud/dialogflow_v2/types/participant.py +++ b/google/cloud/dialogflow_v2/types/participant.py @@ -217,6 +217,13 @@ class AnalyzeContentRequest(proto.Message): r"""The request message for [Participants.AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent]. + 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: participant (str): Required. The name of the participant this text comes from. @@ -224,8 +231,10 @@ class AnalyzeContentRequest(proto.Message): ``projects//locations//conversations//participants/``. text_input (google.cloud.dialogflow_v2.types.TextInput): The natural language text to be processed. + This field is a member of `oneof`_ ``input``. event_input (google.cloud.dialogflow_v2.types.EventInput): An input event to send to Dialogflow. + This field is a member of `oneof`_ ``input``. reply_audio_config (google.cloud.dialogflow_v2.types.OutputAudioConfig): Speech synthesis configuration. The speech synthesis settings for a virtual @@ -573,14 +582,24 @@ class SuggestionResult(proto.Message): as well as [HumanAgentAssistantEvent][google.cloud.dialogflow.v2.HumanAgentAssistantEvent]. + 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: error (google.rpc.status_pb2.Status): Error status if the request failed. + This field is a member of `oneof`_ ``suggestion_response``. suggest_articles_response (google.cloud.dialogflow_v2.types.SuggestArticlesResponse): SuggestArticlesResponse if request is for ARTICLE_SUGGESTION. + This field is a member of `oneof`_ ``suggestion_response``. suggest_faq_answers_response (google.cloud.dialogflow_v2.types.SuggestFaqAnswersResponse): SuggestFaqAnswersResponse if request is for FAQ_ANSWER. + This field is a member of `oneof`_ ``suggestion_response``. """ error = proto.Field( diff --git a/google/cloud/dialogflow_v2/types/session.py b/google/cloud/dialogflow_v2/types/session.py index d72dde079..4176f553f 100644 --- a/google/cloud/dialogflow_v2/types/session.py +++ b/google/cloud/dialogflow_v2/types/session.py @@ -229,14 +229,24 @@ class QueryInput(proto.Message): 3. An event that specifies which intent to trigger. + 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: audio_config (google.cloud.dialogflow_v2.types.InputAudioConfig): Instructs the speech recognizer how to process the speech audio. + This field is a member of `oneof`_ ``input``. text (google.cloud.dialogflow_v2.types.TextInput): The natural language text to be processed. + This field is a member of `oneof`_ ``input``. event (google.cloud.dialogflow_v2.types.EventInput): The event to be processed. + This field is a member of `oneof`_ ``input``. """ audio_config = proto.Field( diff --git a/google/cloud/dialogflow_v2beta1/services/agents/async_client.py b/google/cloud/dialogflow_v2beta1/services/agents/async_client.py index a326d0ed9..49f01ac60 100644 --- a/google/cloud/dialogflow_v2beta1/services/agents/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/agents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2beta1.services.agents import pagers @@ -161,17 +163,17 @@ def __init__( async def get_agent( self, - request: agent.GetAgentRequest = None, + request: Union[agent.GetAgentRequest, 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]] = (), ) -> agent.Agent: r"""Retrieves the specified agent. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetAgentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetAgentRequest, dict]): The request object. The request message for [Agents.GetAgent][google.cloud.dialogflow.v2beta1.Agents.GetAgent]. parent (:class:`str`): @@ -242,10 +244,10 @@ async def get_agent( async def set_agent( self, - request: gcd_agent.SetAgentRequest = None, + request: Union[gcd_agent.SetAgentRequest, dict] = None, *, agent: gcd_agent.Agent = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_agent.Agent: @@ -256,7 +258,7 @@ async def set_agent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.SetAgentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.SetAgentRequest, dict]): The request object. The request message for [Agents.SetAgent][google.cloud.dialogflow.v2beta1.Agents.SetAgent]. agent (:class:`google.cloud.dialogflow_v2beta1.types.Agent`): @@ -326,17 +328,17 @@ async def set_agent( async def delete_agent( self, - request: agent.DeleteAgentRequest = None, + request: Union[agent.DeleteAgentRequest, 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]] = (), ) -> None: r"""Deletes the specified agent. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteAgentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteAgentRequest, dict]): The request object. The request message for [Agents.DeleteAgent][google.cloud.dialogflow.v2beta1.Agents.DeleteAgent]. parent (:class:`str`): @@ -391,10 +393,10 @@ async def delete_agent( async def search_agents( self, - request: agent.SearchAgentsRequest = None, + request: Union[agent.SearchAgentsRequest, 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.SearchAgentsAsyncPager: @@ -406,7 +408,7 @@ async def search_agents( Sub-Collections `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.SearchAgentsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.SearchAgentsRequest, dict]): The request object. The request message for [Agents.SearchAgents][google.cloud.dialogflow.v2beta1.Agents.SearchAgents]. parent (:class:`str`): @@ -477,10 +479,10 @@ async def search_agents( async def train_agent( self, - request: agent.TrainAgentRequest = None, + request: Union[agent.TrainAgentRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -501,7 +503,7 @@ async def train_agent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.TrainAgentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.TrainAgentRequest, dict]): The request object. The request message for [Agents.TrainAgent][google.cloud.dialogflow.v2beta1.Agents.TrainAgent]. parent (:class:`str`): @@ -584,10 +586,10 @@ async def train_agent( async def export_agent( self, - request: agent.ExportAgentRequest = None, + request: Union[agent.ExportAgentRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -604,7 +606,7 @@ async def export_agent( [ExportAgentResponse][google.cloud.dialogflow.v2beta1.ExportAgentResponse] Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ExportAgentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ExportAgentRequest, dict]): The request object. The request message for [Agents.ExportAgent][google.cloud.dialogflow.v2beta1.Agents.ExportAgent]. parent (:class:`str`): @@ -678,9 +680,9 @@ async def export_agent( async def import_agent( self, - request: agent.ImportAgentRequest = None, + request: Union[agent.ImportAgentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -716,7 +718,7 @@ async def import_agent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ImportAgentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ImportAgentRequest, dict]): The request object. The request message for [Agents.ImportAgent][google.cloud.dialogflow.v2beta1.Agents.ImportAgent]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -777,9 +779,9 @@ async def import_agent( async def restore_agent( self, - request: agent.RestoreAgentRequest = None, + request: Union[agent.RestoreAgentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -813,7 +815,7 @@ async def restore_agent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.RestoreAgentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.RestoreAgentRequest, dict]): The request object. The request message for [Agents.RestoreAgent][google.cloud.dialogflow.v2beta1.Agents.RestoreAgent]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -874,9 +876,9 @@ async def restore_agent( async def get_validation_result( self, - request: agent.GetValidationResultRequest = None, + request: Union[agent.GetValidationResultRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> validation_result.ValidationResult: @@ -885,7 +887,7 @@ async def get_validation_result( automatically when training is completed. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetValidationResultRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetValidationResultRequest, dict]): The request object. The request message for [Agents.GetValidationResult][google.cloud.dialogflow.v2beta1.Agents.GetValidationResult]. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/dialogflow_v2beta1/services/agents/client.py b/google/cloud/dialogflow_v2beta1/services/agents/client.py index 8356aa25b..fc4a2fe82 100644 --- a/google/cloud/dialogflow_v2beta1/services/agents/client.py +++ b/google/cloud/dialogflow_v2beta1/services/agents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2beta1.services.agents import pagers @@ -353,7 +355,7 @@ def get_agent( request: Union[agent.GetAgentRequest, 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]] = (), ) -> agent.Agent: @@ -434,7 +436,7 @@ def set_agent( request: Union[gcd_agent.SetAgentRequest, dict] = None, *, agent: gcd_agent.Agent = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_agent.Agent: @@ -518,7 +520,7 @@ def delete_agent( request: Union[agent.DeleteAgentRequest, 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]] = (), ) -> None: @@ -583,7 +585,7 @@ def search_agents( request: Union[agent.SearchAgentsRequest, 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.SearchAgentsPager: @@ -669,7 +671,7 @@ def train_agent( request: Union[agent.TrainAgentRequest, 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]] = (), ) -> operation.Operation: @@ -776,7 +778,7 @@ def export_agent( request: Union[agent.ExportAgentRequest, 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]] = (), ) -> operation.Operation: @@ -869,7 +871,7 @@ def import_agent( self, request: Union[agent.ImportAgentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -969,7 +971,7 @@ def restore_agent( self, request: Union[agent.RestoreAgentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1067,7 +1069,7 @@ def get_validation_result( self, request: Union[agent.GetValidationResultRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> validation_result.ValidationResult: diff --git a/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py b/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py index 52eda1d9a..9c8d40d12 100644 --- a/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/agents/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 @@ -42,15 +41,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 AgentsTransport(abc.ABC): """Abstract transport class for Agents.""" @@ -103,7 +93,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 @@ -136,29 +126,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 = { @@ -203,7 +170,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py b/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py index 7039ecdaa..cd36e4ad2 100644 --- a/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py +++ b/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py @@ -116,7 +116,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py index f6e5ef2cc..a5c1208a9 100644 --- a/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -163,7 +162,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py b/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py index 04a9c89a4..510ed9f0d 100644 --- a/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py @@ -20,13 +20,15 @@ import pkg_resources import warnings -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.dialogflow_v2beta1.services.answer_records import pagers from google.cloud.dialogflow_v2beta1.types import answer_record from google.cloud.dialogflow_v2beta1.types import answer_record as gcd_answer_record @@ -170,9 +172,9 @@ def __init__( async def get_answer_record( self, - request: answer_record.GetAnswerRecordRequest = None, + request: Union[answer_record.GetAnswerRecordRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> answer_record.AnswerRecord: @@ -180,7 +182,7 @@ async def get_answer_record( Retrieves a specific answer record. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetAnswerRecordRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetAnswerRecordRequest, dict]): The request object. Request message for [AnswerRecords.GetAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.GetAnswerRecord]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -256,10 +258,10 @@ async def get_answer_record( async def list_answer_records( self, - request: answer_record.ListAnswerRecordsRequest = None, + request: Union[answer_record.ListAnswerRecordsRequest, 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.ListAnswerRecordsAsyncPager: @@ -267,7 +269,7 @@ async def list_answer_records( specified project in reverse chronological order. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListAnswerRecordsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListAnswerRecordsRequest, dict]): The request object. Request message for [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecords.ListAnswerRecords]. parent (:class:`str`): @@ -338,18 +340,18 @@ async def list_answer_records( async def update_answer_record( self, - request: gcd_answer_record.UpdateAnswerRecordRequest = None, + request: Union[gcd_answer_record.UpdateAnswerRecordRequest, dict] = None, *, answer_record: gcd_answer_record.AnswerRecord = 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]] = (), ) -> gcd_answer_record.AnswerRecord: r"""Updates the specified answer record. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateAnswerRecordRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateAnswerRecordRequest, dict]): The request object. Request message for [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.UpdateAnswerRecord]. answer_record (:class:`google.cloud.dialogflow_v2beta1.types.AnswerRecord`): diff --git a/google/cloud/dialogflow_v2beta1/services/answer_records/client.py b/google/cloud/dialogflow_v2beta1/services/answer_records/client.py index 15753c253..8a2145595 100644 --- a/google/cloud/dialogflow_v2beta1/services/answer_records/client.py +++ b/google/cloud/dialogflow_v2beta1/services/answer_records/client.py @@ -31,6 +31,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.dialogflow_v2beta1.services.answer_records import pagers from google.cloud.dialogflow_v2beta1.types import answer_record from google.cloud.dialogflow_v2beta1.types import answer_record as gcd_answer_record @@ -353,7 +355,7 @@ def get_answer_record( self, request: Union[answer_record.GetAnswerRecordRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> answer_record.AnswerRecord: @@ -440,7 +442,7 @@ def list_answer_records( request: Union[answer_record.ListAnswerRecordsRequest, 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.ListAnswerRecordsPager: @@ -523,7 +525,7 @@ def update_answer_record( *, answer_record: gcd_answer_record.AnswerRecord = 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]] = (), ) -> gcd_answer_record.AnswerRecord: diff --git a/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py b/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py index 45289e34d..4e9260b45 100644 --- a/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/answer_records/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 AnswerRecordsTransport(abc.ABC): """Abstract transport class for AnswerRecords.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py index a0a58b327..5c20f3e22 100644 --- a/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/answer_records/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/dialogflow_v2beta1/services/contexts/async_client.py b/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py index a5f84a254..74dec419f 100644 --- a/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/contexts/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.dialogflow_v2beta1.services.contexts import pagers from google.cloud.dialogflow_v2beta1.types import context from google.cloud.dialogflow_v2beta1.types import context as gcd_context @@ -160,10 +162,10 @@ def __init__( async def list_contexts( self, - request: context.ListContextsRequest = None, + request: Union[context.ListContextsRequest, 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.ListContextsAsyncPager: @@ -171,7 +173,7 @@ async def list_contexts( session. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListContextsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListContextsRequest, dict]): The request object. The request message for [Contexts.ListContexts][google.cloud.dialogflow.v2beta1.Contexts.ListContexts]. parent (:class:`str`): @@ -251,17 +253,17 @@ async def list_contexts( async def get_context( self, - request: context.GetContextRequest = None, + request: Union[context.GetContextRequest, 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]] = (), ) -> context.Context: r"""Retrieves the specified context. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetContextRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetContextRequest, dict]): The request object. The request message for [Contexts.GetContext][google.cloud.dialogflow.v2beta1.Contexts.GetContext]. name (:class:`str`): @@ -348,11 +350,11 @@ async def get_context( async def create_context( self, - request: gcd_context.CreateContextRequest = None, + request: Union[gcd_context.CreateContextRequest, dict] = None, *, parent: str = None, context: gcd_context.Context = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_context.Context: @@ -361,7 +363,7 @@ async def create_context( context. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateContextRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateContextRequest, dict]): The request object. The request message for [Contexts.CreateContext][google.cloud.dialogflow.v2beta1.Contexts.CreateContext]. parent (:class:`str`): @@ -456,18 +458,18 @@ async def create_context( async def update_context( self, - request: gcd_context.UpdateContextRequest = None, + request: Union[gcd_context.UpdateContextRequest, dict] = None, *, context: gcd_context.Context = 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]] = (), ) -> gcd_context.Context: r"""Updates the specified context. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateContextRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateContextRequest, dict]): The request object. The request message for [Contexts.UpdateContext][google.cloud.dialogflow.v2beta1.Contexts.UpdateContext]. context (:class:`google.cloud.dialogflow_v2beta1.types.Context`): @@ -554,17 +556,17 @@ async def update_context( async def delete_context( self, - request: context.DeleteContextRequest = None, + request: Union[context.DeleteContextRequest, 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 the specified context. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteContextRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteContextRequest, dict]): The request object. The request message for [Contexts.DeleteContext][google.cloud.dialogflow.v2beta1.Contexts.DeleteContext]. name (:class:`str`): @@ -628,17 +630,17 @@ async def delete_context( async def delete_all_contexts( self, - request: context.DeleteAllContextsRequest = None, + request: Union[context.DeleteAllContextsRequest, 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]] = (), ) -> None: r"""Deletes all active contexts in the specified session. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteAllContextsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteAllContextsRequest, dict]): The request object. The request message for [Contexts.DeleteAllContexts][google.cloud.dialogflow.v2beta1.Contexts.DeleteAllContexts]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2beta1/services/contexts/client.py b/google/cloud/dialogflow_v2beta1/services/contexts/client.py index 83de06ec8..e948a51d9 100644 --- a/google/cloud/dialogflow_v2beta1/services/contexts/client.py +++ b/google/cloud/dialogflow_v2beta1/services/contexts/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.dialogflow_v2beta1.services.contexts import pagers from google.cloud.dialogflow_v2beta1.types import context from google.cloud.dialogflow_v2beta1.types import context as gcd_context @@ -355,7 +357,7 @@ def list_contexts( request: Union[context.ListContextsRequest, 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.ListContextsPager: @@ -446,7 +448,7 @@ def get_context( request: Union[context.GetContextRequest, 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]] = (), ) -> context.Context: @@ -544,7 +546,7 @@ def create_context( *, parent: str = None, context: gcd_context.Context = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_context.Context: @@ -652,7 +654,7 @@ def update_context( *, context: gcd_context.Context = 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]] = (), ) -> gcd_context.Context: @@ -749,7 +751,7 @@ def delete_context( request: Union[context.DeleteContextRequest, 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: @@ -823,7 +825,7 @@ def delete_all_contexts( request: Union[context.DeleteAllContextsRequest, 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]] = (), ) -> None: diff --git a/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py b/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py index 1c78c1438..8ec7016a0 100644 --- a/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/contexts/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 @@ -39,15 +38,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 ContextsTransport(abc.ABC): """Abstract transport class for Contexts.""" @@ -100,7 +90,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 @@ -133,29 +123,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/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py index 787b76711..73c8d97b9 100644 --- a/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/contexts/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/dialogflow_v2beta1/services/conversation_profiles/async_client.py b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py index c39cf892f..6cfeb103c 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/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.dialogflow_v2beta1.services.conversation_profiles import pagers from google.cloud.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import conversation_profile @@ -196,10 +198,12 @@ def __init__( async def list_conversation_profiles( self, - request: conversation_profile.ListConversationProfilesRequest = None, + request: Union[ + conversation_profile.ListConversationProfilesRequest, 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.ListConversationProfilesAsyncPager: @@ -207,7 +211,7 @@ async def list_conversation_profiles( specified project. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListConversationProfilesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListConversationProfilesRequest, dict]): The request object. The request message for [ConversationProfiles.ListConversationProfiles][google.cloud.dialogflow.v2beta1.ConversationProfiles.ListConversationProfiles]. parent (:class:`str`): @@ -278,17 +282,17 @@ async def list_conversation_profiles( async def get_conversation_profile( self, - request: conversation_profile.GetConversationProfileRequest = None, + request: Union[conversation_profile.GetConversationProfileRequest, 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]] = (), ) -> conversation_profile.ConversationProfile: r"""Retrieves the specified conversation profile. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetConversationProfileRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetConversationProfileRequest, dict]): The request object. The request message for [ConversationProfiles.GetConversationProfile][google.cloud.dialogflow.v2beta1.ConversationProfiles.GetConversationProfile]. name (:class:`str`): @@ -350,11 +354,13 @@ async def get_conversation_profile( async def create_conversation_profile( self, - request: gcd_conversation_profile.CreateConversationProfileRequest = None, + request: Union[ + gcd_conversation_profile.CreateConversationProfileRequest, dict + ] = None, *, parent: str = None, conversation_profile: gcd_conversation_profile.ConversationProfile = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_conversation_profile.ConversationProfile: @@ -367,7 +373,7 @@ async def create_conversation_profile( API. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateConversationProfileRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateConversationProfileRequest, dict]): The request object. The request message for [ConversationProfiles.CreateConversationProfile][google.cloud.dialogflow.v2beta1.ConversationProfiles.CreateConversationProfile]. parent (:class:`str`): @@ -438,11 +444,13 @@ async def create_conversation_profile( async def update_conversation_profile( self, - request: gcd_conversation_profile.UpdateConversationProfileRequest = None, + request: Union[ + gcd_conversation_profile.UpdateConversationProfileRequest, dict + ] = None, *, conversation_profile: gcd_conversation_profile.ConversationProfile = 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]] = (), ) -> gcd_conversation_profile.ConversationProfile: @@ -455,7 +463,7 @@ async def update_conversation_profile( API. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateConversationProfileRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateConversationProfileRequest, dict]): The request object. The request message for [ConversationProfiles.UpdateConversationProfile][google.cloud.dialogflow.v2beta1.ConversationProfiles.UpdateConversationProfile]. conversation_profile (:class:`google.cloud.dialogflow_v2beta1.types.ConversationProfile`): @@ -527,17 +535,19 @@ async def update_conversation_profile( async def delete_conversation_profile( self, - request: conversation_profile.DeleteConversationProfileRequest = None, + request: Union[ + conversation_profile.DeleteConversationProfileRequest, 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 the specified conversation profile. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteConversationProfileRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteConversationProfileRequest, dict]): The request object. The request message for [ConversationProfiles.DeleteConversationProfile][google.cloud.dialogflow.v2beta1.ConversationProfiles.DeleteConversationProfile]. This operation fails if the conversation profile is diff --git a/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py index 36390e7ac..7ecdfa0d6 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py +++ b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/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.dialogflow_v2beta1.services.conversation_profiles import pagers from google.cloud.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import conversation_profile @@ -442,7 +444,7 @@ def list_conversation_profiles( ] = 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.ListConversationProfilesPager: @@ -528,7 +530,7 @@ def get_conversation_profile( request: Union[conversation_profile.GetConversationProfileRequest, 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]] = (), ) -> conversation_profile.ConversationProfile: @@ -603,7 +605,7 @@ def create_conversation_profile( *, parent: str = None, conversation_profile: gcd_conversation_profile.ConversationProfile = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_conversation_profile.ConversationProfile: @@ -697,7 +699,7 @@ def update_conversation_profile( *, conversation_profile: gcd_conversation_profile.ConversationProfile = 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]] = (), ) -> gcd_conversation_profile.ConversationProfile: @@ -791,7 +793,7 @@ def delete_conversation_profile( ] = 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: diff --git a/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py index 5449ff769..f11ae7f80 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/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 @@ -41,15 +40,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 ConversationProfilesTransport(abc.ABC): """Abstract transport class for ConversationProfiles.""" @@ -102,7 +92,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 @@ -135,29 +125,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/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py index 18aded68f..6c684682b 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/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/dialogflow_v2beta1/services/conversations/async_client.py b/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py index 3fbacbcd7..b119af07a 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/conversations/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.dialogflow_v2beta1.services.conversations import pagers from google.cloud.dialogflow_v2beta1.types import conversation from google.cloud.dialogflow_v2beta1.types import conversation as gcd_conversation @@ -176,11 +178,11 @@ def __init__( async def create_conversation( self, - request: gcd_conversation.CreateConversationRequest = None, + request: Union[gcd_conversation.CreateConversationRequest, dict] = None, *, parent: str = None, conversation: gcd_conversation.Conversation = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_conversation.Conversation: @@ -207,7 +209,7 @@ async def create_conversation( is triggered, conversation will transfer to Assist Stage. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateConversationRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateConversationRequest, dict]): The request object. The request message for [Conversations.CreateConversation][google.cloud.dialogflow.v2beta1.Conversations.CreateConversation]. parent (:class:`str`): @@ -281,10 +283,10 @@ async def create_conversation( async def list_conversations( self, - request: conversation.ListConversationsRequest = None, + request: Union[conversation.ListConversationsRequest, 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.ListConversationsAsyncPager: @@ -292,7 +294,7 @@ async def list_conversations( specified project. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListConversationsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListConversationsRequest, dict]): The request object. The request message for [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. parent (:class:`str`): @@ -363,17 +365,17 @@ async def list_conversations( async def get_conversation( self, - request: conversation.GetConversationRequest = None, + request: Union[conversation.GetConversationRequest, 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]] = (), ) -> conversation.Conversation: r"""Retrieves the specific conversation. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetConversationRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetConversationRequest, dict]): The request object. The request message for [Conversations.GetConversation][google.cloud.dialogflow.v2beta1.Conversations.GetConversation]. name (:class:`str`): @@ -439,10 +441,10 @@ async def get_conversation( async def complete_conversation( self, - request: conversation.CompleteConversationRequest = None, + request: Union[conversation.CompleteConversationRequest, 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]] = (), ) -> conversation.Conversation: @@ -451,7 +453,7 @@ async def complete_conversation( days. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CompleteConversationRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CompleteConversationRequest, dict]): The request object. The request message for [Conversations.CompleteConversation][google.cloud.dialogflow.v2beta1.Conversations.CompleteConversation]. name (:class:`str`): @@ -518,10 +520,10 @@ async def complete_conversation( async def batch_create_messages( self, - request: conversation.BatchCreateMessagesRequest = None, + request: Union[conversation.BatchCreateMessagesRequest, 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]] = (), ) -> conversation.BatchCreateMessagesResponse: @@ -530,7 +532,7 @@ async def batch_create_messages( conversation. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.BatchCreateMessagesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.BatchCreateMessagesRequest, dict]): The request object. The request message for [Conversations.BatchCreateMessagesRequest][]. parent (:class:`str`): @@ -592,10 +594,10 @@ async def batch_create_messages( async def list_messages( self, - request: conversation.ListMessagesRequest = None, + request: Union[conversation.ListMessagesRequest, 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.ListMessagesAsyncPager: @@ -606,7 +608,7 @@ async def list_messages( and empty page_token. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListMessagesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListMessagesRequest, dict]): The request object. The request message for [Conversations.ListMessages][google.cloud.dialogflow.v2beta1.Conversations.ListMessages]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2beta1/services/conversations/client.py b/google/cloud/dialogflow_v2beta1/services/conversations/client.py index 0bef29367..dcac3ecaf 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversations/client.py +++ b/google/cloud/dialogflow_v2beta1/services/conversations/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.dialogflow_v2beta1.services.conversations import pagers from google.cloud.dialogflow_v2beta1.types import conversation from google.cloud.dialogflow_v2beta1.types import conversation as gcd_conversation @@ -387,7 +389,7 @@ def create_conversation( *, parent: str = None, conversation: gcd_conversation.Conversation = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_conversation.Conversation: @@ -491,7 +493,7 @@ def list_conversations( request: Union[conversation.ListConversationsRequest, 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.ListConversationsPager: @@ -573,7 +575,7 @@ def get_conversation( request: Union[conversation.GetConversationRequest, 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]] = (), ) -> conversation.Conversation: @@ -649,7 +651,7 @@ def complete_conversation( request: Union[conversation.CompleteConversationRequest, 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]] = (), ) -> conversation.Conversation: @@ -728,7 +730,7 @@ def batch_create_messages( request: Union[conversation.BatchCreateMessagesRequest, 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]] = (), ) -> conversation.BatchCreateMessagesResponse: @@ -802,7 +804,7 @@ def list_messages( request: Union[conversation.ListMessagesRequest, 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.ListMessagesPager: diff --git a/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py b/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py index 56052daae..29c7cf129 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/conversations/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 ConversationsTransport(abc.ABC): """Abstract transport class for Conversations.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py index 4c3d93a62..29d8095ae 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/conversations/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/dialogflow_v2beta1/services/documents/async_client.py b/google/cloud/dialogflow_v2beta1/services/documents/async_client.py index b00b957cf..6d8cf6678 100644 --- a/google/cloud/dialogflow_v2beta1/services/documents/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/documents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2beta1.services.documents import pagers @@ -165,10 +167,10 @@ def __init__( async def list_documents( self, - request: document.ListDocumentsRequest = None, + request: Union[document.ListDocumentsRequest, 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.ListDocumentsAsyncPager: @@ -178,7 +180,7 @@ async def list_documents( is deprecated; only use ``projects.knowledgeBases.documents``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListDocumentsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListDocumentsRequest, dict]): The request object. Request message for [Documents.ListDocuments][google.cloud.dialogflow.v2beta1.Documents.ListDocuments]. parent (:class:`str`): @@ -249,10 +251,10 @@ async def list_documents( async def get_document( self, - request: document.GetDocumentRequest = None, + request: Union[document.GetDocumentRequest, 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]] = (), ) -> document.Document: @@ -262,7 +264,7 @@ async def get_document( is deprecated; only use ``projects.knowledgeBases.documents``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetDocumentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetDocumentRequest, dict]): The request object. Request message for [Documents.GetDocument][google.cloud.dialogflow.v2beta1.Documents.GetDocument]. name (:class:`str`): @@ -330,11 +332,11 @@ async def get_document( async def create_document( self, - request: gcd_document.CreateDocumentRequest = None, + request: Union[gcd_document.CreateDocumentRequest, dict] = None, *, parent: str = None, document: gcd_document.Document = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -354,7 +356,7 @@ async def create_document( is deprecated; only use ``projects.knowledgeBases.documents``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateDocumentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateDocumentRequest, dict]): The request object. Request message for [Documents.CreateDocument][google.cloud.dialogflow.v2beta1.Documents.CreateDocument]. parent (:class:`str`): @@ -442,9 +444,9 @@ async def create_document( async def import_documents( self, - request: document.ImportDocumentsRequest = None, + request: Union[document.ImportDocumentsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -463,7 +465,7 @@ async def import_documents( [ImportDocumentsResponse][google.cloud.dialogflow.v2beta1.ImportDocumentsResponse] Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ImportDocumentsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ImportDocumentsRequest, dict]): The request object. Request message for [Documents.ImportDocuments][google.cloud.dialogflow.v2beta1.Documents.ImportDocuments]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -515,10 +517,10 @@ async def import_documents( async def delete_document( self, - request: document.DeleteDocumentRequest = None, + request: Union[document.DeleteDocumentRequest, 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]] = (), ) -> operation_async.AsyncOperation: @@ -538,7 +540,7 @@ async def delete_document( is deprecated; only use ``projects.knowledgeBases.documents``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteDocumentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteDocumentRequest, dict]): The request object. Request message for [Documents.DeleteDocument][google.cloud.dialogflow.v2beta1.Documents.DeleteDocument]. name (:class:`str`): @@ -620,11 +622,11 @@ async def delete_document( async def update_document( self, - request: gcd_document.UpdateDocumentRequest = None, + request: Union[gcd_document.UpdateDocumentRequest, dict] = None, *, document: gcd_document.Document = 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]] = (), ) -> operation_async.AsyncOperation: @@ -644,7 +646,7 @@ async def update_document( is deprecated; only use ``projects.knowledgeBases.documents``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateDocumentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateDocumentRequest, dict]): The request object. Request message for [Documents.UpdateDocument][google.cloud.dialogflow.v2beta1.Documents.UpdateDocument]. document (:class:`google.cloud.dialogflow_v2beta1.types.Document`): @@ -734,11 +736,11 @@ async def update_document( async def reload_document( self, - request: document.ReloadDocumentRequest = None, + request: Union[document.ReloadDocumentRequest, dict] = None, *, name: str = None, gcs_source: gcs.GcsSource = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -766,7 +768,7 @@ async def reload_document( is deprecated; only use ``projects.knowledgeBases.documents``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ReloadDocumentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ReloadDocumentRequest, dict]): The request object. Request message for [Documents.ReloadDocument][google.cloud.dialogflow.v2beta1.Documents.ReloadDocument]. name (:class:`str`): diff --git a/google/cloud/dialogflow_v2beta1/services/documents/client.py b/google/cloud/dialogflow_v2beta1/services/documents/client.py index 47356b4a5..69ef91126 100644 --- a/google/cloud/dialogflow_v2beta1/services/documents/client.py +++ b/google/cloud/dialogflow_v2beta1/services/documents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2beta1.services.documents import pagers @@ -358,7 +360,7 @@ def list_documents( request: Union[document.ListDocumentsRequest, 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.ListDocumentsPager: @@ -442,7 +444,7 @@ def get_document( request: Union[document.GetDocumentRequest, 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]] = (), ) -> document.Document: @@ -524,7 +526,7 @@ def create_document( *, parent: str = None, document: gcd_document.Document = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -634,7 +636,7 @@ def import_documents( self, request: Union[document.ImportDocumentsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -709,7 +711,7 @@ def delete_document( request: Union[document.DeleteDocumentRequest, 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]] = (), ) -> operation.Operation: @@ -815,7 +817,7 @@ def update_document( *, document: gcd_document.Document = 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]] = (), ) -> operation.Operation: @@ -929,7 +931,7 @@ def reload_document( *, name: str = None, gcs_source: gcs.GcsSource = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py b/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py index 5641d1a96..a7fb387bb 100644 --- a/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/documents/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 @@ -40,15 +39,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 DocumentsTransport(abc.ABC): """Abstract transport class for Documents.""" @@ -101,7 +91,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 @@ -134,29 +124,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 = { @@ -193,7 +160,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py b/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py index 6722914c5..d85c0c062 100644 --- a/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py +++ b/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py @@ -114,7 +114,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py index cfaad0c1f..eddfd67c5 100644 --- a/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -161,7 +160,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py b/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py index ad0c87258..7dfeb8770 100644 --- a/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/entity_types/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2beta1.services.entity_types import pagers @@ -167,11 +169,11 @@ def __init__( async def list_entity_types( self, - request: entity_type.ListEntityTypesRequest = None, + request: Union[entity_type.ListEntityTypesRequest, dict] = None, *, parent: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEntityTypesAsyncPager: @@ -179,7 +181,7 @@ async def list_entity_types( agent. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListEntityTypesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListEntityTypesRequest, dict]): The request object. The request message for [EntityTypes.ListEntityTypes][google.cloud.dialogflow.v2beta1.EntityTypes.ListEntityTypes]. parent (:class:`str`): @@ -264,18 +266,18 @@ async def list_entity_types( async def get_entity_type( self, - request: entity_type.GetEntityTypeRequest = None, + request: Union[entity_type.GetEntityTypeRequest, dict] = None, *, name: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> entity_type.EntityType: r"""Retrieves the specified entity type. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetEntityTypeRequest, dict]): The request object. The request message for [EntityTypes.GetEntityType][google.cloud.dialogflow.v2beta1.EntityTypes.GetEntityType]. name (:class:`str`): @@ -364,12 +366,12 @@ async def get_entity_type( async def create_entity_type( self, - request: gcd_entity_type.CreateEntityTypeRequest = None, + request: Union[gcd_entity_type.CreateEntityTypeRequest, dict] = None, *, parent: str = None, entity_type: gcd_entity_type.EntityType = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_entity_type.EntityType: @@ -380,7 +382,7 @@ async def create_entity_type( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateEntityTypeRequest, dict]): The request object. The request message for [EntityTypes.CreateEntityType][google.cloud.dialogflow.v2beta1.EntityTypes.CreateEntityType]. parent (:class:`str`): @@ -476,12 +478,12 @@ async def create_entity_type( async def update_entity_type( self, - request: gcd_entity_type.UpdateEntityTypeRequest = None, + request: Union[gcd_entity_type.UpdateEntityTypeRequest, dict] = None, *, entity_type: gcd_entity_type.EntityType = None, language_code: str = 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]] = (), ) -> gcd_entity_type.EntityType: @@ -492,7 +494,7 @@ async def update_entity_type( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateEntityTypeRequest, dict]): The request object. The request message for [EntityTypes.UpdateEntityType][google.cloud.dialogflow.v2beta1.EntityTypes.UpdateEntityType]. entity_type (:class:`google.cloud.dialogflow_v2beta1.types.EntityType`): @@ -587,10 +589,10 @@ async def update_entity_type( async def delete_entity_type( self, - request: entity_type.DeleteEntityTypeRequest = None, + request: Union[entity_type.DeleteEntityTypeRequest, 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: @@ -601,7 +603,7 @@ async def delete_entity_type( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteEntityTypeRequest, dict]): The request object. The request message for [EntityTypes.DeleteEntityType][google.cloud.dialogflow.v2beta1.EntityTypes.DeleteEntityType]. name (:class:`str`): @@ -658,9 +660,9 @@ async def delete_entity_type( async def batch_update_entity_types( self, - request: entity_type.BatchUpdateEntityTypesRequest = None, + request: Union[entity_type.BatchUpdateEntityTypesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -681,7 +683,7 @@ async def batch_update_entity_types( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.BatchUpdateEntityTypesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.BatchUpdateEntityTypesRequest, dict]): The request object. The request message for [EntityTypes.BatchUpdateEntityTypes][google.cloud.dialogflow.v2beta1.EntityTypes.BatchUpdateEntityTypes]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -733,11 +735,11 @@ async def batch_update_entity_types( async def batch_delete_entity_types( self, - request: entity_type.BatchDeleteEntityTypesRequest = None, + request: Union[entity_type.BatchDeleteEntityTypesRequest, dict] = None, *, parent: str = None, entity_type_names: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -758,7 +760,7 @@ async def batch_delete_entity_types( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.BatchDeleteEntityTypesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.BatchDeleteEntityTypesRequest, dict]): The request object. The request message for [EntityTypes.BatchDeleteEntityTypes][google.cloud.dialogflow.v2beta1.EntityTypes.BatchDeleteEntityTypes]. parent (:class:`str`): @@ -852,12 +854,12 @@ async def batch_delete_entity_types( async def batch_create_entities( self, - request: entity_type.BatchCreateEntitiesRequest = None, + request: Union[entity_type.BatchCreateEntitiesRequest, dict] = None, *, parent: str = None, entities: Sequence[entity_type.EntityType.Entity] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -878,7 +880,7 @@ async def batch_create_entities( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.BatchCreateEntitiesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.BatchCreateEntitiesRequest, dict]): The request object. The request message for [EntityTypes.BatchCreateEntities][google.cloud.dialogflow.v2beta1.EntityTypes.BatchCreateEntities]. parent (:class:`str`): @@ -982,12 +984,12 @@ async def batch_create_entities( async def batch_update_entities( self, - request: entity_type.BatchUpdateEntitiesRequest = None, + request: Union[entity_type.BatchUpdateEntitiesRequest, dict] = None, *, parent: str = None, entities: Sequence[entity_type.EntityType.Entity] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1010,7 +1012,7 @@ async def batch_update_entities( message `__ Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.BatchUpdateEntitiesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.BatchUpdateEntitiesRequest, dict]): The request object. The request message for [EntityTypes.BatchUpdateEntities][google.cloud.dialogflow.v2beta1.EntityTypes.BatchUpdateEntities]. parent (:class:`str`): @@ -1116,12 +1118,12 @@ async def batch_update_entities( async def batch_delete_entities( self, - request: entity_type.BatchDeleteEntitiesRequest = None, + request: Union[entity_type.BatchDeleteEntitiesRequest, dict] = None, *, parent: str = None, entity_values: Sequence[str] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1142,7 +1144,7 @@ async def batch_delete_entities( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.BatchDeleteEntitiesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.BatchDeleteEntitiesRequest, dict]): The request object. The request message for [EntityTypes.BatchDeleteEntities][google.cloud.dialogflow.v2beta1.EntityTypes.BatchDeleteEntities]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2beta1/services/entity_types/client.py b/google/cloud/dialogflow_v2beta1/services/entity_types/client.py index ac3dd274f..e4ab4ef44 100644 --- a/google/cloud/dialogflow_v2beta1/services/entity_types/client.py +++ b/google/cloud/dialogflow_v2beta1/services/entity_types/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2beta1.services.entity_types import pagers @@ -358,7 +360,7 @@ def list_entity_types( *, parent: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEntityTypesPager: @@ -455,7 +457,7 @@ def get_entity_type( *, name: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> entity_type.EntityType: @@ -556,7 +558,7 @@ def create_entity_type( parent: str = None, entity_type: gcd_entity_type.EntityType = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_entity_type.EntityType: @@ -668,7 +670,7 @@ def update_entity_type( entity_type: gcd_entity_type.EntityType = None, language_code: str = 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]] = (), ) -> gcd_entity_type.EntityType: @@ -777,7 +779,7 @@ def delete_entity_type( request: Union[entity_type.DeleteEntityTypeRequest, 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: @@ -847,7 +849,7 @@ def batch_update_entity_types( self, request: Union[entity_type.BatchUpdateEntityTypesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -927,7 +929,7 @@ def batch_delete_entity_types( *, parent: str = None, entity_type_names: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1049,7 +1051,7 @@ def batch_create_entities( parent: str = None, entities: Sequence[entity_type.EntityType.Entity] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1179,7 +1181,7 @@ def batch_update_entities( parent: str = None, entities: Sequence[entity_type.EntityType.Entity] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1313,7 +1315,7 @@ def batch_delete_entities( parent: str = None, entity_values: Sequence[str] = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py b/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py index c05259169..b069d4f67 100644 --- a/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/entity_types/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 @@ -41,15 +40,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 EntityTypesTransport(abc.ABC): """Abstract transport class for EntityTypes.""" @@ -102,7 +92,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 @@ -135,29 +125,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 = { @@ -213,7 +180,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py b/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py index 5d6708fb4..2e8ea789d 100644 --- a/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py +++ b/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py @@ -115,7 +115,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py index b00b22f00..3a2779b8b 100644 --- a/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -162,7 +161,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2beta1/services/environments/async_client.py b/google/cloud/dialogflow_v2beta1/services/environments/async_client.py index a6ddd0bcd..6fb03112b 100644 --- a/google/cloud/dialogflow_v2beta1/services/environments/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/environments/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.dialogflow_v2beta1.services.environments import pagers from google.cloud.dialogflow_v2beta1.types import environment from google.cloud.dialogflow_v2beta1.types import fulfillment @@ -167,10 +169,10 @@ def __init__( async def list_environments( self, - request: environment.ListEnvironmentsRequest = None, + request: Union[environment.ListEnvironmentsRequest, 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.ListEnvironmentsAsyncPager: @@ -178,7 +180,7 @@ async def list_environments( specified agent. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListEnvironmentsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListEnvironmentsRequest, dict]): The request object. The request message for [Environments.ListEnvironments][google.cloud.dialogflow.v2beta1.Environments.ListEnvironments]. parent (:class:`str`): @@ -251,16 +253,16 @@ async def list_environments( async def get_environment( self, - request: environment.GetEnvironmentRequest = None, + request: Union[environment.GetEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: r"""Retrieves the specified agent environment. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetEnvironmentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetEnvironmentRequest, dict]): The request object. The request message for [Environments.GetEnvironment][google.cloud.dialogflow.v2beta1.Environments.GetEnvironment]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -319,16 +321,16 @@ async def get_environment( async def create_environment( self, - request: environment.CreateEnvironmentRequest = None, + request: Union[environment.CreateEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: r"""Creates an agent environment. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateEnvironmentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateEnvironmentRequest, dict]): The request object. The request message for [Environments.CreateEnvironment][google.cloud.dialogflow.v2beta1.Environments.CreateEnvironment]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -387,9 +389,9 @@ async def create_environment( async def update_environment( self, - request: environment.UpdateEnvironmentRequest = None, + request: Union[environment.UpdateEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: @@ -408,7 +410,7 @@ async def update_environment( draft to a version before calling this function. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateEnvironmentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateEnvironmentRequest, dict]): The request object. The request message for [Environments.UpdateEnvironment][google.cloud.dialogflow.v2beta1.Environments.UpdateEnvironment]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -469,16 +471,16 @@ async def update_environment( async def delete_environment( self, - request: environment.DeleteEnvironmentRequest = None, + request: Union[environment.DeleteEnvironmentRequest, dict] = 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 the specified agent environment. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteEnvironmentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteEnvironmentRequest, dict]): The request object. The request message for [Environments.DeleteEnvironment][google.cloud.dialogflow.v2beta1.Environments.DeleteEnvironment]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -511,16 +513,16 @@ async def delete_environment( async def get_environment_history( self, - request: environment.GetEnvironmentHistoryRequest = None, + request: Union[environment.GetEnvironmentHistoryRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GetEnvironmentHistoryAsyncPager: r"""Gets the history of the specified environment. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetEnvironmentHistoryRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetEnvironmentHistoryRequest, dict]): The request object. The request message for [Environments.GetEnvironmentHistory][google.cloud.dialogflow.v2beta1.Environments.GetEnvironmentHistory]. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/dialogflow_v2beta1/services/environments/client.py b/google/cloud/dialogflow_v2beta1/services/environments/client.py index 4128a3b92..e7ebcefa7 100644 --- a/google/cloud/dialogflow_v2beta1/services/environments/client.py +++ b/google/cloud/dialogflow_v2beta1/services/environments/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.dialogflow_v2beta1.services.environments import pagers from google.cloud.dialogflow_v2beta1.types import environment from google.cloud.dialogflow_v2beta1.types import fulfillment @@ -379,7 +381,7 @@ def list_environments( request: Union[environment.ListEnvironmentsRequest, 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.ListEnvironmentsPager: @@ -462,7 +464,7 @@ def get_environment( self, request: Union[environment.GetEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: @@ -531,7 +533,7 @@ def create_environment( self, request: Union[environment.CreateEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: @@ -600,7 +602,7 @@ def update_environment( self, request: Union[environment.UpdateEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: @@ -683,7 +685,7 @@ def delete_environment( self, request: Union[environment.DeleteEnvironmentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -726,7 +728,7 @@ def get_environment_history( self, request: Union[environment.GetEnvironmentHistoryRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GetEnvironmentHistoryPager: diff --git a/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py b/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py index 763c346f6..8d2f62ae1 100644 --- a/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/environments/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 EnvironmentsTransport(abc.ABC): """Abstract transport class for Environments.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py index fd9980680..fec967de3 100644 --- a/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/environments/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/dialogflow_v2beta1/services/fulfillments/async_client.py b/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py index bbe089bbb..13404c662 100644 --- a/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/fulfillments/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.dialogflow_v2beta1.types import fulfillment from google.cloud.dialogflow_v2beta1.types import fulfillment as gcd_fulfillment from google.protobuf import field_mask_pb2 # type: ignore @@ -162,17 +164,17 @@ def __init__( async def get_fulfillment( self, - request: fulfillment.GetFulfillmentRequest = None, + request: Union[fulfillment.GetFulfillmentRequest, 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]] = (), ) -> fulfillment.Fulfillment: r"""Retrieves the fulfillment. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetFulfillmentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetFulfillmentRequest, dict]): The request object. The request message for [Fulfillments.GetFulfillment][google.cloud.dialogflow.v2beta1.Fulfillments.GetFulfillment]. name (:class:`str`): @@ -246,18 +248,18 @@ async def get_fulfillment( async def update_fulfillment( self, - request: gcd_fulfillment.UpdateFulfillmentRequest = None, + request: Union[gcd_fulfillment.UpdateFulfillmentRequest, dict] = None, *, fulfillment: gcd_fulfillment.Fulfillment = 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]] = (), ) -> gcd_fulfillment.Fulfillment: r"""Updates the fulfillment. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateFulfillmentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateFulfillmentRequest, dict]): The request object. The request message for [Fulfillments.UpdateFulfillment][google.cloud.dialogflow.v2beta1.Fulfillments.UpdateFulfillment]. fulfillment (:class:`google.cloud.dialogflow_v2beta1.types.Fulfillment`): diff --git a/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py b/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py index d10f10499..a7bd7861e 100644 --- a/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py +++ b/google/cloud/dialogflow_v2beta1/services/fulfillments/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.dialogflow_v2beta1.types import fulfillment from google.cloud.dialogflow_v2beta1.types import fulfillment as gcd_fulfillment from google.protobuf import field_mask_pb2 # type: ignore @@ -348,7 +350,7 @@ def get_fulfillment( request: Union[fulfillment.GetFulfillmentRequest, 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]] = (), ) -> fulfillment.Fulfillment: @@ -433,7 +435,7 @@ def update_fulfillment( *, fulfillment: gcd_fulfillment.Fulfillment = 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]] = (), ) -> gcd_fulfillment.Fulfillment: diff --git a/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py b/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py index 3ca8956a1..9b24bedf2 100644 --- a/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/fulfillments/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 FulfillmentsTransport(abc.ABC): """Abstract transport class for Fulfillments.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py index aeefa86bd..5e19b8e6d 100644 --- a/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/fulfillments/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/dialogflow_v2beta1/services/intents/async_client.py b/google/cloud/dialogflow_v2beta1/services/intents/async_client.py index 12c00278f..70c37604a 100644 --- a/google/cloud/dialogflow_v2beta1/services/intents/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/intents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2beta1.services.intents import pagers @@ -166,11 +168,11 @@ def __init__( async def list_intents( self, - request: intent.ListIntentsRequest = None, + request: Union[intent.ListIntentsRequest, dict] = None, *, parent: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIntentsAsyncPager: @@ -178,7 +180,7 @@ async def list_intents( agent. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListIntentsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListIntentsRequest, dict]): The request object. The request message for [Intents.ListIntents][google.cloud.dialogflow.v2beta1.Intents.ListIntents]. parent (:class:`str`): @@ -269,18 +271,18 @@ async def list_intents( async def get_intent( self, - request: intent.GetIntentRequest = None, + request: Union[intent.GetIntentRequest, dict] = None, *, name: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> intent.Intent: r"""Retrieves the specified intent. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetIntentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetIntentRequest, dict]): The request object. The request message for [Intents.GetIntent][google.cloud.dialogflow.v2beta1.Intents.GetIntent]. name (:class:`str`): @@ -364,12 +366,12 @@ async def get_intent( async def create_intent( self, - request: gcd_intent.CreateIntentRequest = None, + request: Union[gcd_intent.CreateIntentRequest, dict] = None, *, parent: str = None, intent: gcd_intent.Intent = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_intent.Intent: @@ -380,7 +382,7 @@ async def create_intent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateIntentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateIntentRequest, dict]): The request object. The request message for [Intents.CreateIntent][google.cloud.dialogflow.v2beta1.Intents.CreateIntent]. parent (:class:`str`): @@ -472,12 +474,12 @@ async def create_intent( async def update_intent( self, - request: gcd_intent.UpdateIntentRequest = None, + request: Union[gcd_intent.UpdateIntentRequest, dict] = None, *, intent: gcd_intent.Intent = None, update_mask: field_mask_pb2.FieldMask = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_intent.Intent: @@ -488,7 +490,7 @@ async def update_intent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateIntentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateIntentRequest, dict]): The request object. The request message for [Intents.UpdateIntent][google.cloud.dialogflow.v2beta1.Intents.UpdateIntent]. intent (:class:`google.cloud.dialogflow_v2beta1.types.Intent`): @@ -579,10 +581,10 @@ async def update_intent( async def delete_intent( self, - request: intent.DeleteIntentRequest = None, + request: Union[intent.DeleteIntentRequest, 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: @@ -594,7 +596,7 @@ async def delete_intent( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteIntentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteIntentRequest, dict]): The request object. The request message for [Intents.DeleteIntent][google.cloud.dialogflow.v2beta1.Intents.DeleteIntent]. name (:class:`str`): @@ -654,12 +656,12 @@ async def delete_intent( async def batch_update_intents( self, - request: intent.BatchUpdateIntentsRequest = None, + request: Union[intent.BatchUpdateIntentsRequest, dict] = None, *, parent: str = None, intent_batch_uri: str = None, intent_batch_inline: intent.IntentBatch = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -680,7 +682,7 @@ async def batch_update_intents( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.BatchUpdateIntentsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.BatchUpdateIntentsRequest, dict]): The request object. The request message for [Intents.BatchUpdateIntents][google.cloud.dialogflow.v2beta1.Intents.BatchUpdateIntents]. parent (:class:`str`): @@ -778,11 +780,11 @@ async def batch_update_intents( async def batch_delete_intents( self, - request: intent.BatchDeleteIntentsRequest = None, + request: Union[intent.BatchDeleteIntentsRequest, dict] = None, *, parent: str = None, intents: Sequence[intent.Intent] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -803,7 +805,7 @@ async def batch_delete_intents( documentation `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.BatchDeleteIntentsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.BatchDeleteIntentsRequest, dict]): The request object. The request message for [Intents.BatchDeleteIntents][google.cloud.dialogflow.v2beta1.Intents.BatchDeleteIntents]. parent (:class:`str`): diff --git a/google/cloud/dialogflow_v2beta1/services/intents/client.py b/google/cloud/dialogflow_v2beta1/services/intents/client.py index 280d15741..19354cb12 100644 --- a/google/cloud/dialogflow_v2beta1/services/intents/client.py +++ b/google/cloud/dialogflow_v2beta1/services/intents/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.dialogflow_v2beta1.services.intents import pagers @@ -373,7 +375,7 @@ def list_intents( *, parent: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIntentsPager: @@ -476,7 +478,7 @@ def get_intent( *, name: str = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> intent.Intent: @@ -572,7 +574,7 @@ def create_intent( parent: str = None, intent: gcd_intent.Intent = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_intent.Intent: @@ -680,7 +682,7 @@ def update_intent( intent: gcd_intent.Intent = None, update_mask: field_mask_pb2.FieldMask = None, language_code: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_intent.Intent: @@ -785,7 +787,7 @@ def delete_intent( request: Union[intent.DeleteIntentRequest, 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: @@ -862,7 +864,7 @@ def batch_update_intents( parent: str = None, intent_batch_uri: str = None, intent_batch_inline: intent.IntentBatch = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -985,7 +987,7 @@ def batch_delete_intents( *, parent: str = None, intents: Sequence[intent.Intent] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: diff --git a/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py b/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py index 1f27cddb9..cb7506ae5 100644 --- a/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/intents/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 @@ -41,15 +40,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 IntentsTransport(abc.ABC): """Abstract transport class for Intents.""" @@ -102,7 +92,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 @@ -135,29 +125,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 = { @@ -198,7 +165,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py b/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py index 42a414a2e..9fe716ba9 100644 --- a/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py +++ b/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py @@ -115,7 +115,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py index 46d8e3e6d..d05ba185e 100644 --- a/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -162,7 +161,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py index 5c7784662..2df411390 100644 --- a/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/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.dialogflow_v2beta1.services.knowledge_bases import pagers from google.cloud.dialogflow_v2beta1.types import knowledge_base from google.cloud.dialogflow_v2beta1.types import knowledge_base as gcd_knowledge_base @@ -169,10 +171,10 @@ def __init__( async def list_knowledge_bases( self, - request: knowledge_base.ListKnowledgeBasesRequest = None, + request: Union[knowledge_base.ListKnowledgeBasesRequest, 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.ListKnowledgeBasesAsyncPager: @@ -182,7 +184,7 @@ async def list_knowledge_bases( deprecated; only use ``projects.knowledgeBases``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListKnowledgeBasesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListKnowledgeBasesRequest, dict]): The request object. Request message for [KnowledgeBases.ListKnowledgeBases][google.cloud.dialogflow.v2beta1.KnowledgeBases.ListKnowledgeBases]. parent (:class:`str`): @@ -253,10 +255,10 @@ async def list_knowledge_bases( async def get_knowledge_base( self, - request: knowledge_base.GetKnowledgeBaseRequest = None, + request: Union[knowledge_base.GetKnowledgeBaseRequest, 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]] = (), ) -> knowledge_base.KnowledgeBase: @@ -266,7 +268,7 @@ async def get_knowledge_base( deprecated; only use ``projects.knowledgeBases``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetKnowledgeBaseRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetKnowledgeBaseRequest, dict]): The request object. Request message for [KnowledgeBases.GetKnowledgeBase][google.cloud.dialogflow.v2beta1.KnowledgeBases.GetKnowledgeBase]. name (:class:`str`): @@ -338,11 +340,11 @@ async def get_knowledge_base( async def create_knowledge_base( self, - request: gcd_knowledge_base.CreateKnowledgeBaseRequest = None, + request: Union[gcd_knowledge_base.CreateKnowledgeBaseRequest, dict] = None, *, parent: str = None, knowledge_base: gcd_knowledge_base.KnowledgeBase = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_knowledge_base.KnowledgeBase: @@ -352,7 +354,7 @@ async def create_knowledge_base( deprecated; only use ``projects.knowledgeBases``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateKnowledgeBaseRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateKnowledgeBaseRequest, dict]): The request object. Request message for [KnowledgeBases.CreateKnowledgeBase][google.cloud.dialogflow.v2beta1.KnowledgeBases.CreateKnowledgeBase]. parent (:class:`str`): @@ -433,10 +435,10 @@ async def create_knowledge_base( async def delete_knowledge_base( self, - request: knowledge_base.DeleteKnowledgeBaseRequest = None, + request: Union[knowledge_base.DeleteKnowledgeBaseRequest, 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: @@ -446,7 +448,7 @@ async def delete_knowledge_base( deprecated; only use ``projects.knowledgeBases``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteKnowledgeBaseRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteKnowledgeBaseRequest, dict]): The request object. Request message for [KnowledgeBases.DeleteKnowledgeBase][google.cloud.dialogflow.v2beta1.KnowledgeBases.DeleteKnowledgeBase]. name (:class:`str`): @@ -501,11 +503,11 @@ async def delete_knowledge_base( async def update_knowledge_base( self, - request: gcd_knowledge_base.UpdateKnowledgeBaseRequest = None, + request: Union[gcd_knowledge_base.UpdateKnowledgeBaseRequest, dict] = None, *, knowledge_base: gcd_knowledge_base.KnowledgeBase = 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]] = (), ) -> gcd_knowledge_base.KnowledgeBase: @@ -515,7 +517,7 @@ async def update_knowledge_base( deprecated; only use ``projects.knowledgeBases``. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateKnowledgeBaseRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateKnowledgeBaseRequest, dict]): The request object. Request message for [KnowledgeBases.UpdateKnowledgeBase][google.cloud.dialogflow.v2beta1.KnowledgeBases.UpdateKnowledgeBase]. knowledge_base (:class:`google.cloud.dialogflow_v2beta1.types.KnowledgeBase`): diff --git a/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py index 6d0acf2f4..c416f2b9d 100644 --- a/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py +++ b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/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.dialogflow_v2beta1.services.knowledge_bases import pagers from google.cloud.dialogflow_v2beta1.types import knowledge_base from google.cloud.dialogflow_v2beta1.types import knowledge_base as gcd_knowledge_base @@ -355,7 +357,7 @@ def list_knowledge_bases( request: Union[knowledge_base.ListKnowledgeBasesRequest, 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.ListKnowledgeBasesPager: @@ -439,7 +441,7 @@ def get_knowledge_base( request: Union[knowledge_base.GetKnowledgeBaseRequest, 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]] = (), ) -> knowledge_base.KnowledgeBase: @@ -525,7 +527,7 @@ def create_knowledge_base( *, parent: str = None, knowledge_base: gcd_knowledge_base.KnowledgeBase = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_knowledge_base.KnowledgeBase: @@ -619,7 +621,7 @@ def delete_knowledge_base( request: Union[knowledge_base.DeleteKnowledgeBaseRequest, 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: @@ -688,7 +690,7 @@ def update_knowledge_base( *, knowledge_base: gcd_knowledge_base.KnowledgeBase = 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]] = (), ) -> gcd_knowledge_base.KnowledgeBase: diff --git a/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py index 0c0d2ff2c..6362f67a5 100644 --- a/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/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 @@ -39,15 +38,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 KnowledgeBasesTransport(abc.ABC): """Abstract transport class for KnowledgeBases.""" @@ -100,7 +90,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 @@ -133,29 +123,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/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py index d02786d4b..5bd509612 100644 --- a/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/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/dialogflow_v2beta1/services/participants/async_client.py b/google/cloud/dialogflow_v2beta1/services/participants/async_client.py index 60a9a6e76..eab29e9e3 100644 --- a/google/cloud/dialogflow_v2beta1/services/participants/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/participants/async_client.py @@ -20,13 +20,15 @@ import pkg_resources import warnings -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.dialogflow_v2beta1.services.participants import pagers from google.cloud.dialogflow_v2beta1.types import participant from google.cloud.dialogflow_v2beta1.types import participant as gcd_participant @@ -177,18 +179,18 @@ def __init__( async def create_participant( self, - request: gcd_participant.CreateParticipantRequest = None, + request: Union[gcd_participant.CreateParticipantRequest, dict] = None, *, parent: str = None, participant: gcd_participant.Participant = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_participant.Participant: r"""Creates a new participant in a conversation. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateParticipantRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateParticipantRequest, dict]): The request object. The request message for [Participants.CreateParticipant][google.cloud.dialogflow.v2beta1.Participants.CreateParticipant]. parent (:class:`str`): @@ -257,17 +259,17 @@ async def create_participant( async def get_participant( self, - request: participant.GetParticipantRequest = None, + request: Union[participant.GetParticipantRequest, 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]] = (), ) -> participant.Participant: r"""Retrieves a conversation participant. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetParticipantRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetParticipantRequest, dict]): The request object. The request message for [Participants.GetParticipant][google.cloud.dialogflow.v2beta1.Participants.GetParticipant]. name (:class:`str`): @@ -328,10 +330,10 @@ async def get_participant( async def list_participants( self, - request: participant.ListParticipantsRequest = None, + request: Union[participant.ListParticipantsRequest, 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.ListParticipantsAsyncPager: @@ -339,7 +341,7 @@ async def list_participants( conversation. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListParticipantsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListParticipantsRequest, dict]): The request object. The request message for [Participants.ListParticipants][google.cloud.dialogflow.v2beta1.Participants.ListParticipants]. parent (:class:`str`): @@ -410,18 +412,18 @@ async def list_participants( async def update_participant( self, - request: gcd_participant.UpdateParticipantRequest = None, + request: Union[gcd_participant.UpdateParticipantRequest, dict] = None, *, participant: gcd_participant.Participant = 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]] = (), ) -> gcd_participant.Participant: r"""Updates the specified participant. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateParticipantRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateParticipantRequest, dict]): The request object. The request message for [Participants.UpdateParticipant][google.cloud.dialogflow.v2beta1.Participants.UpdateParticipant]. participant (:class:`google.cloud.dialogflow_v2beta1.types.Participant`): @@ -491,12 +493,12 @@ async def update_participant( async def analyze_content( self, - request: gcd_participant.AnalyzeContentRequest = None, + request: Union[gcd_participant.AnalyzeContentRequest, dict] = None, *, participant: str = None, text_input: session.TextInput = None, event_input: session.EventInput = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_participant.AnalyzeContentResponse: @@ -508,7 +510,7 @@ async def analyze_content( environments `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.AnalyzeContentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.AnalyzeContentRequest, dict]): The request object. The request message for [Participants.AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent]. participant (:class:`str`): @@ -597,10 +599,10 @@ async def analyze_content( async def suggest_articles( self, - request: participant.SuggestArticlesRequest = None, + request: Union[participant.SuggestArticlesRequest, 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]] = (), ) -> participant.SuggestArticlesResponse: @@ -615,7 +617,7 @@ async def suggest_articles( conversation context in the real time. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.SuggestArticlesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.SuggestArticlesRequest, dict]): The request object. The request message for [Participants.SuggestArticles][google.cloud.dialogflow.v2beta1.Participants.SuggestArticles]. parent (:class:`str`): @@ -677,10 +679,10 @@ async def suggest_articles( async def suggest_faq_answers( self, - request: participant.SuggestFaqAnswersRequest = None, + request: Union[participant.SuggestFaqAnswersRequest, 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]] = (), ) -> participant.SuggestFaqAnswersResponse: @@ -688,7 +690,7 @@ async def suggest_faq_answers( specific historical messages. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.SuggestFaqAnswersRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.SuggestFaqAnswersRequest, dict]): The request object. The request message for [Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2beta1.Participants.SuggestFaqAnswers]. parent (:class:`str`): @@ -750,10 +752,10 @@ async def suggest_faq_answers( async def suggest_smart_replies( self, - request: participant.SuggestSmartRepliesRequest = None, + request: Union[participant.SuggestSmartRepliesRequest, 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]] = (), ) -> participant.SuggestSmartRepliesResponse: @@ -761,7 +763,7 @@ async def suggest_smart_replies( specific historical messages. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.SuggestSmartRepliesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.SuggestSmartRepliesRequest, dict]): The request object. The request message for [Participants.SuggestSmartReplies][google.cloud.dialogflow.v2beta1.Participants.SuggestSmartReplies]. parent (:class:`str`): @@ -823,9 +825,9 @@ async def suggest_smart_replies( async def list_suggestions( self, - request: participant.ListSuggestionsRequest = None, + request: Union[participant.ListSuggestionsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSuggestionsAsyncPager: @@ -851,7 +853,7 @@ async def list_suggestions( and empty page_token. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListSuggestionsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListSuggestionsRequest, dict]): The request object. The request message for [Participants.ListSuggestions][google.cloud.dialogflow.v2beta1.Participants.ListSuggestions]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -904,9 +906,9 @@ async def list_suggestions( async def compile_suggestion( self, - request: participant.CompileSuggestionRequest = None, + request: Union[participant.CompileSuggestionRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> participant.CompileSuggestionResponse: @@ -927,7 +929,7 @@ async def compile_suggestion( conversation context in the real time. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CompileSuggestionRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CompileSuggestionRequest, dict]): The request object. The request message for [Participants.CompileSuggestion][google.cloud.dialogflow.v2beta1.Participants.CompileSuggestion]. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/dialogflow_v2beta1/services/participants/client.py b/google/cloud/dialogflow_v2beta1/services/participants/client.py index 9f639afb3..046052fce 100644 --- a/google/cloud/dialogflow_v2beta1/services/participants/client.py +++ b/google/cloud/dialogflow_v2beta1/services/participants/client.py @@ -31,6 +31,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.dialogflow_v2beta1.services.participants import pagers from google.cloud.dialogflow_v2beta1.types import participant from google.cloud.dialogflow_v2beta1.types import participant as gcd_participant @@ -434,7 +436,7 @@ def create_participant( *, parent: str = None, participant: gcd_participant.Participant = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_participant.Participant: @@ -513,7 +515,7 @@ def get_participant( request: Union[participant.GetParticipantRequest, 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]] = (), ) -> participant.Participant: @@ -584,7 +586,7 @@ def list_participants( request: Union[participant.ListParticipantsRequest, 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.ListParticipantsPager: @@ -667,7 +669,7 @@ def update_participant( *, participant: gcd_participant.Participant = 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]] = (), ) -> gcd_participant.Participant: @@ -749,7 +751,7 @@ def analyze_content( participant: str = None, text_input: session.TextInput = None, event_input: session.EventInput = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_participant.AnalyzeContentResponse: @@ -844,7 +846,7 @@ def suggest_articles( request: Union[participant.SuggestArticlesRequest, 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]] = (), ) -> participant.SuggestArticlesResponse: @@ -924,7 +926,7 @@ def suggest_faq_answers( request: Union[participant.SuggestFaqAnswersRequest, 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]] = (), ) -> participant.SuggestFaqAnswersResponse: @@ -997,7 +999,7 @@ def suggest_smart_replies( request: Union[participant.SuggestSmartRepliesRequest, 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]] = (), ) -> participant.SuggestSmartRepliesResponse: @@ -1069,7 +1071,7 @@ def list_suggestions( self, request: Union[participant.ListSuggestionsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSuggestionsPager: @@ -1151,7 +1153,7 @@ def compile_suggestion( self, request: Union[participant.CompileSuggestionRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> participant.CompileSuggestionResponse: diff --git a/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py b/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py index cac2d2624..8664a4616 100644 --- a/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/participants/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 ParticipantsTransport(abc.ABC): """Abstract transport class for Participants.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py index 8cac31f55..f7185c8b3 100644 --- a/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/participants/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/dialogflow_v2beta1/services/session_entity_types/async_client.py b/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py index 9c6a2343a..7953d8f18 100644 --- a/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/session_entity_types/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.dialogflow_v2beta1.services.session_entity_types import pagers from google.cloud.dialogflow_v2beta1.types import entity_type from google.cloud.dialogflow_v2beta1.types import session_entity_type @@ -175,10 +177,10 @@ def __init__( async def list_session_entity_types( self, - request: session_entity_type.ListSessionEntityTypesRequest = None, + request: Union[session_entity_type.ListSessionEntityTypesRequest, 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.ListSessionEntityTypesAsyncPager: @@ -189,7 +191,7 @@ async def list_session_entity_types( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListSessionEntityTypesRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListSessionEntityTypesRequest, dict]): The request object. The request message for [SessionEntityTypes.ListSessionEntityTypes][google.cloud.dialogflow.v2beta1.SessionEntityTypes.ListSessionEntityTypes]. parent (:class:`str`): @@ -269,10 +271,10 @@ async def list_session_entity_types( async def get_session_entity_type( self, - request: session_entity_type.GetSessionEntityTypeRequest = None, + request: Union[session_entity_type.GetSessionEntityTypeRequest, 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]] = (), ) -> session_entity_type.SessionEntityType: @@ -282,7 +284,7 @@ async def get_session_entity_type( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetSessionEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetSessionEntityTypeRequest, dict]): The request object. The request message for [SessionEntityTypes.GetSessionEntityType][google.cloud.dialogflow.v2beta1.SessionEntityTypes.GetSessionEntityType]. name (:class:`str`): @@ -361,11 +363,13 @@ async def get_session_entity_type( async def create_session_entity_type( self, - request: gcd_session_entity_type.CreateSessionEntityTypeRequest = None, + request: Union[ + gcd_session_entity_type.CreateSessionEntityTypeRequest, dict + ] = None, *, parent: str = None, session_entity_type: gcd_session_entity_type.SessionEntityType = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session_entity_type.SessionEntityType: @@ -378,7 +382,7 @@ async def create_session_entity_type( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateSessionEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateSessionEntityTypeRequest, dict]): The request object. The request message for [SessionEntityTypes.CreateSessionEntityType][google.cloud.dialogflow.v2beta1.SessionEntityTypes.CreateSessionEntityType]. parent (:class:`str`): @@ -466,11 +470,13 @@ async def create_session_entity_type( async def update_session_entity_type( self, - request: gcd_session_entity_type.UpdateSessionEntityTypeRequest = None, + request: Union[ + gcd_session_entity_type.UpdateSessionEntityTypeRequest, dict + ] = None, *, session_entity_type: gcd_session_entity_type.SessionEntityType = 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]] = (), ) -> gcd_session_entity_type.SessionEntityType: @@ -480,7 +486,7 @@ async def update_session_entity_type( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateSessionEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateSessionEntityTypeRequest, dict]): The request object. The request message for [SessionEntityTypes.UpdateSessionEntityType][google.cloud.dialogflow.v2beta1.SessionEntityTypes.UpdateSessionEntityType]. session_entity_type (:class:`google.cloud.dialogflow_v2beta1.types.SessionEntityType`): @@ -560,10 +566,10 @@ async def update_session_entity_type( async def delete_session_entity_type( self, - request: session_entity_type.DeleteSessionEntityTypeRequest = None, + request: Union[session_entity_type.DeleteSessionEntityTypeRequest, 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: @@ -573,7 +579,7 @@ async def delete_session_entity_type( use session entities with Google Assistant integration. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteSessionEntityTypeRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteSessionEntityTypeRequest, dict]): The request object. The request message for [SessionEntityTypes.DeleteSessionEntityType][google.cloud.dialogflow.v2beta1.SessionEntityTypes.DeleteSessionEntityType]. name (:class:`str`): diff --git a/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py b/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py index fae84b7e1..4519053bc 100644 --- a/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py +++ b/google/cloud/dialogflow_v2beta1/services/session_entity_types/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.dialogflow_v2beta1.services.session_entity_types import pagers from google.cloud.dialogflow_v2beta1.types import entity_type from google.cloud.dialogflow_v2beta1.types import session_entity_type @@ -361,7 +363,7 @@ def list_session_entity_types( request: Union[session_entity_type.ListSessionEntityTypesRequest, 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.ListSessionEntityTypesPager: @@ -457,7 +459,7 @@ def get_session_entity_type( request: Union[session_entity_type.GetSessionEntityTypeRequest, 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]] = (), ) -> session_entity_type.SessionEntityType: @@ -552,7 +554,7 @@ def create_session_entity_type( *, parent: str = None, session_entity_type: gcd_session_entity_type.SessionEntityType = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session_entity_type.SessionEntityType: @@ -663,7 +665,7 @@ def update_session_entity_type( *, session_entity_type: gcd_session_entity_type.SessionEntityType = 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]] = (), ) -> gcd_session_entity_type.SessionEntityType: @@ -760,7 +762,7 @@ def delete_session_entity_type( request: Union[session_entity_type.DeleteSessionEntityTypeRequest, 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: diff --git a/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py b/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py index 291a54f86..35ac3244f 100644 --- a/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/session_entity_types/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 @@ -41,15 +40,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 SessionEntityTypesTransport(abc.ABC): """Abstract transport class for SessionEntityTypes.""" @@ -102,7 +92,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 @@ -135,29 +125,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/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py index 9f2fba0ce..6d561ca9d 100644 --- a/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/session_entity_types/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/dialogflow_v2beta1/services/sessions/async_client.py b/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py index 809a6cc66..a1ceba60e 100644 --- a/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py @@ -28,13 +28,15 @@ ) 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.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import session from google.cloud.dialogflow_v2beta1.types import session as gcd_session @@ -180,11 +182,11 @@ def __init__( async def detect_intent( self, - request: gcd_session.DetectIntentRequest = None, + request: Union[gcd_session.DetectIntentRequest, dict] = None, *, session: str = None, query_input: gcd_session.QueryInput = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session.DetectIntentResponse: @@ -205,7 +207,7 @@ async def detect_intent( environments `__. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DetectIntentRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DetectIntentRequest, dict]): The request object. The request to detect user's intent. session (:class:`str`): Required. The name of the session this query is sent to. @@ -316,7 +318,7 @@ def streaming_detect_intent( self, requests: AsyncIterator[session.StreamingDetectIntentRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[session.StreamingDetectIntentResponse]]: @@ -388,11 +390,12 @@ def streaming_detect_intent( Multiple response messages can be returned in order: - 1. If the input was set to streaming audio, the first - one or more messages contain recognition_result. - Each recognition_result represents a more complete - transcript of what the user said. The last - recognition_result has is_final set to true. + 1. If the StreamingDetectIntentRequest.input_audio + field was set, the recognition_result field is + populated for one or more messages. See the + [StreamingRecognitionResult][google.cloud.dialogflow.v2beta1.StreamingRecognitionResult] + message for details about the result message + sequence. 2. The next message contains response_id, query_result, alternative_query_results and optionally webhook_status if a WebHook was called. diff --git a/google/cloud/dialogflow_v2beta1/services/sessions/client.py b/google/cloud/dialogflow_v2beta1/services/sessions/client.py index c65e7f3b0..1b3be6270 100644 --- a/google/cloud/dialogflow_v2beta1/services/sessions/client.py +++ b/google/cloud/dialogflow_v2beta1/services/sessions/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.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import session from google.cloud.dialogflow_v2beta1.types import session as gcd_session @@ -417,7 +419,7 @@ def detect_intent( *, session: str = None, query_input: gcd_session.QueryInput = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_session.DetectIntentResponse: @@ -540,7 +542,7 @@ def streaming_detect_intent( self, requests: Iterator[session.StreamingDetectIntentRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[session.StreamingDetectIntentResponse]: @@ -612,11 +614,12 @@ def streaming_detect_intent( Multiple response messages can be returned in order: - 1. If the input was set to streaming audio, the first - one or more messages contain recognition_result. - Each recognition_result represents a more complete - transcript of what the user said. The last - recognition_result has is_final set to true. + 1. If the StreamingDetectIntentRequest.input_audio + field was set, the recognition_result field is + populated for one or more messages. See the + [StreamingRecognitionResult][google.cloud.dialogflow.v2beta1.StreamingRecognitionResult] + message for details about the result message + sequence. 2. The next message contains response_id, query_result, alternative_query_results and optionally webhook_status if a WebHook was called. diff --git a/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py b/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py index 2405c4855..1055460bd 100644 --- a/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/sessions/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 SessionsTransport(abc.ABC): """Abstract transport class for Sessions.""" @@ -99,7 +89,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 @@ -132,29 +122,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/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py index 6bcd2247a..9fc280e6d 100644 --- a/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/sessions/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/dialogflow_v2beta1/services/versions/async_client.py b/google/cloud/dialogflow_v2beta1/services/versions/async_client.py index 7a110a13f..cc1c0ce1d 100644 --- a/google/cloud/dialogflow_v2beta1/services/versions/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/versions/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.dialogflow_v2beta1.services.versions import pagers from google.cloud.dialogflow_v2beta1.types import version from google.cloud.dialogflow_v2beta1.types import version as gcd_version @@ -160,10 +162,10 @@ def __init__( async def list_versions( self, - request: version.ListVersionsRequest = None, + request: Union[version.ListVersionsRequest, 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.ListVersionsAsyncPager: @@ -171,7 +173,7 @@ async def list_versions( agent. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListVersionsRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.ListVersionsRequest, dict]): The request object. The request message for [Versions.ListVersions][google.cloud.dialogflow.v2beta1.Versions.ListVersions]. parent (:class:`str`): @@ -244,17 +246,17 @@ async def list_versions( async def get_version( self, - request: version.GetVersionRequest = None, + request: Union[version.GetVersionRequest, 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]] = (), ) -> version.Version: r"""Retrieves the specified agent version. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.GetVersionRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.GetVersionRequest, dict]): The request object. The request message for [Versions.GetVersion][google.cloud.dialogflow.v2beta1.Versions.GetVersion]. name (:class:`str`): @@ -336,11 +338,11 @@ async def get_version( async def create_version( self, - request: gcd_version.CreateVersionRequest = None, + request: Union[gcd_version.CreateVersionRequest, dict] = None, *, parent: str = None, version: gcd_version.Version = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_version.Version: @@ -349,7 +351,7 @@ async def create_version( "default" environment. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateVersionRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.CreateVersionRequest, dict]): The request object. The request message for [Versions.CreateVersion][google.cloud.dialogflow.v2beta1.Versions.CreateVersion]. parent (:class:`str`): @@ -439,11 +441,11 @@ async def create_version( async def update_version( self, - request: gcd_version.UpdateVersionRequest = None, + request: Union[gcd_version.UpdateVersionRequest, dict] = None, *, version: gcd_version.Version = 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]] = (), ) -> gcd_version.Version: @@ -454,7 +456,7 @@ async def update_version( version resource. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.UpdateVersionRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.UpdateVersionRequest, dict]): The request object. The request message for [Versions.UpdateVersion][google.cloud.dialogflow.v2beta1.Versions.UpdateVersion]. version (:class:`google.cloud.dialogflow_v2beta1.types.Version`): @@ -547,17 +549,17 @@ async def update_version( async def delete_version( self, - request: version.DeleteVersionRequest = None, + request: Union[version.DeleteVersionRequest, 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"""Delete the specified agent version. Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteVersionRequest`): + request (Union[google.cloud.dialogflow_v2beta1.types.DeleteVersionRequest, dict]): The request object. The request message for [Versions.DeleteVersion][google.cloud.dialogflow.v2beta1.Versions.DeleteVersion]. name (:class:`str`): diff --git a/google/cloud/dialogflow_v2beta1/services/versions/client.py b/google/cloud/dialogflow_v2beta1/services/versions/client.py index bb797812e..5b6417a26 100644 --- a/google/cloud/dialogflow_v2beta1/services/versions/client.py +++ b/google/cloud/dialogflow_v2beta1/services/versions/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.dialogflow_v2beta1.services.versions import pagers from google.cloud.dialogflow_v2beta1.types import version from google.cloud.dialogflow_v2beta1.types import version as gcd_version @@ -354,7 +356,7 @@ def list_versions( request: Union[version.ListVersionsRequest, 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.ListVersionsPager: @@ -438,7 +440,7 @@ def get_version( request: Union[version.GetVersionRequest, 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]] = (), ) -> version.Version: @@ -531,7 +533,7 @@ def create_version( *, parent: str = None, version: gcd_version.Version = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_version.Version: @@ -634,7 +636,7 @@ def update_version( *, version: gcd_version.Version = 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]] = (), ) -> gcd_version.Version: @@ -741,7 +743,7 @@ def delete_version( request: Union[version.DeleteVersionRequest, 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: diff --git a/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py b/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py index 5c94d418b..e48bddc5b 100644 --- a/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/versions/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 @@ -39,15 +38,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 VersionsTransport(abc.ABC): """Abstract transport class for Versions.""" @@ -100,7 +90,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 @@ -133,29 +123,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/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py b/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py index e315e4190..3e64a349d 100644 --- a/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2beta1/services/versions/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/dialogflow_v2beta1/types/agent.py b/google/cloud/dialogflow_v2beta1/types/agent.py index a7ef49936..300c5cccc 100644 --- a/google/cloud/dialogflow_v2beta1/types/agent.py +++ b/google/cloud/dialogflow_v2beta1/types/agent.py @@ -294,13 +294,22 @@ class ExportAgentResponse(proto.Message): r"""The response message for [Agents.ExportAgent][google.cloud.dialogflow.v2beta1.Agents.ExportAgent]. + 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: agent_uri (str): The URI to a file containing the exported agent. This field is populated only if ``agent_uri`` is specified in ``ExportAgentRequest``. + This field is a member of `oneof`_ ``agent``. agent_content (bytes): Zip compressed raw byte content for agent. + This field is a member of `oneof`_ ``agent``. """ agent_uri = proto.Field(proto.STRING, number=1, oneof="agent",) @@ -311,6 +320,13 @@ class ImportAgentRequest(proto.Message): r"""The request message for [Agents.ImportAgent][google.cloud.dialogflow.v2beta1.Agents.ImportAgent]. + 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: parent (str): Required. The project that the agent to import is associated @@ -320,8 +336,10 @@ class ImportAgentRequest(proto.Message): The URI to a Google Cloud Storage file containing the agent to import. Note: The URI must start with "gs://". + This field is a member of `oneof`_ ``agent``. agent_content (bytes): Zip compressed raw byte content for agent. + This field is a member of `oneof`_ ``agent``. """ parent = proto.Field(proto.STRING, number=1,) @@ -333,6 +351,13 @@ class RestoreAgentRequest(proto.Message): r"""The request message for [Agents.RestoreAgent][google.cloud.dialogflow.v2beta1.Agents.RestoreAgent]. + 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: parent (str): Required. The project that the agent to restore is @@ -342,8 +367,10 @@ class RestoreAgentRequest(proto.Message): The URI to a Google Cloud Storage file containing the agent to restore. Note: The URI must start with "gs://". + This field is a member of `oneof`_ ``agent``. agent_content (bytes): Zip compressed raw byte content for agent. + This field is a member of `oneof`_ ``agent``. """ parent = proto.Field(proto.STRING, number=1,) diff --git a/google/cloud/dialogflow_v2beta1/types/answer_record.py b/google/cloud/dialogflow_v2beta1/types/answer_record.py index 95dc47038..e0107128e 100644 --- a/google/cloud/dialogflow_v2beta1/types/answer_record.py +++ b/google/cloud/dialogflow_v2beta1/types/answer_record.py @@ -65,6 +65,9 @@ class AnswerRecord(proto.Message): to call the [UpdateAnswerRecord][] method to send feedback about a specific answer that they believe is wrong. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): The unique identifier of this answer record. Required for @@ -79,6 +82,7 @@ class AnswerRecord(proto.Message): agent_assistant_record (google.cloud.dialogflow_v2beta1.types.AgentAssistantRecord): Output only. The record for human agent assistant. + This field is a member of `oneof`_ ``record``. """ name = proto.Field(proto.STRING, number=1,) @@ -91,11 +95,20 @@ class AnswerRecord(proto.Message): class AgentAssistantRecord(proto.Message): r"""Represents a record of a human agent assistant answer. + 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: article_suggestion_answer (google.cloud.dialogflow_v2beta1.types.ArticleAnswer): Output only. The article suggestion answer. + This field is a member of `oneof`_ ``answer``. faq_answer (google.cloud.dialogflow_v2beta1.types.FaqAnswer): Output only. The FAQ answer. + This field is a member of `oneof`_ ``answer``. """ article_suggestion_answer = proto.Field( @@ -110,12 +123,16 @@ class AnswerFeedback(proto.Message): r"""Represents feedback the customer has about the quality & correctness of a certain answer in a conversation. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: correctness_level (google.cloud.dialogflow_v2beta1.types.AnswerFeedback.CorrectnessLevel): The correctness level of the specific answer. agent_assistant_detail_feedback (google.cloud.dialogflow_v2beta1.types.AgentAssistantFeedback): Optional. Detail feedback of agent assistant suggestions. + This field is a member of `oneof`_ ``detail_feedback``. clicked (bool): Indicates whether the answer/item was clicked by the human agent or not. Default to false. diff --git a/google/cloud/dialogflow_v2beta1/types/conversation_event.py b/google/cloud/dialogflow_v2beta1/types/conversation_event.py index dee158441..cd7c678d3 100644 --- a/google/cloud/dialogflow_v2beta1/types/conversation_event.py +++ b/google/cloud/dialogflow_v2beta1/types/conversation_event.py @@ -28,6 +28,9 @@ class ConversationEvent(proto.Message): r"""Represents a notification sent to Pub/Sub subscribers for conversation lifecycle events. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: conversation (str): Required. The unique identifier of the conversation this @@ -41,6 +44,7 @@ class ConversationEvent(proto.Message): for type UNRECOVERABLE_ERROR_IN_PHONE_CALL. new_message_payload (google.cloud.dialogflow_v2beta1.types.Message): Payload of NEW_MESSAGE event. + This field is a member of `oneof`_ ``payload``. """ class Type(proto.Enum): diff --git a/google/cloud/dialogflow_v2beta1/types/conversation_profile.py b/google/cloud/dialogflow_v2beta1/types/conversation_profile.py index 0cb67df87..d30d9c933 100644 --- a/google/cloud/dialogflow_v2beta1/types/conversation_profile.py +++ b/google/cloud/dialogflow_v2beta1/types/conversation_profile.py @@ -267,16 +267,26 @@ class SuggestionConfig(proto.Message): class SuggestionQueryConfig(proto.Message): r"""Config for suggestion query. + 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: knowledge_base_query_source (google.cloud.dialogflow_v2beta1.types.HumanAgentAssistantConfig.SuggestionQueryConfig.KnowledgeBaseQuerySource): Query from knowledgebase. It is used by: ARTICLE_SUGGESTION, FAQ. + This field is a member of `oneof`_ ``query_source``. document_query_source (google.cloud.dialogflow_v2beta1.types.HumanAgentAssistantConfig.SuggestionQueryConfig.DocumentQuerySource): Query from knowledge base document. It is used by: SMART_REPLY, SMART_COMPOSE. + This field is a member of `oneof`_ ``query_source``. dialogflow_query_source (google.cloud.dialogflow_v2beta1.types.HumanAgentAssistantConfig.SuggestionQueryConfig.DialogflowQuerySource): Query from Dialogflow agent. It is used by DIALOGFLOW_ASSIST. + This field is a member of `oneof`_ ``query_source``. max_results (int): Maximum number of results to return. Currently, if unset, defaults to 10. And the max @@ -474,11 +484,20 @@ class HumanAgentHandoffConfig(proto.Message): Currently, this feature is not general available, please contact Google to get access. + 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: live_person_config (google.cloud.dialogflow_v2beta1.types.HumanAgentHandoffConfig.LivePersonConfig): Uses LivePerson (https://www.liveperson.com). + This field is a member of `oneof`_ ``agent_service``. salesforce_live_agent_config (google.cloud.dialogflow_v2beta1.types.HumanAgentHandoffConfig.SalesforceLiveAgentConfig): Uses Salesforce Live Agent. + This field is a member of `oneof`_ ``agent_service``. """ class LivePersonConfig(proto.Message): diff --git a/google/cloud/dialogflow_v2beta1/types/document.py b/google/cloud/dialogflow_v2beta1/types/document.py index cf33e0898..69a890c6f 100644 --- a/google/cloud/dialogflow_v2beta1/types/document.py +++ b/google/cloud/dialogflow_v2beta1/types/document.py @@ -50,6 +50,13 @@ class Document(proto.Message): Note: The ``projects.agent.knowledgeBases.documents`` resource is deprecated; only use ``projects.knowledgeBases.documents``. + 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): Optional. The document resource name. The name must be empty @@ -75,14 +82,17 @@ class Document(proto.Message): URLs for showing documents in Google Cloud Storage (i.e. the URL in your browser) are not supported. Instead use the ``gs://`` format URI described above. + This field is a member of `oneof`_ ``source``. content (str): The raw content of the document. This field is only permitted for EXTRACTIVE_QA and FAQ knowledge types. Note: This field is in the process of being deprecated, please use raw_content instead. + This field is a member of `oneof`_ ``source``. raw_content (bytes): The raw content of the document. This field is only permitted for EXTRACTIVE_QA and FAQ knowledge types. + This field is a member of `oneof`_ ``source``. enable_auto_reload (bool): Optional. If true, we try to automatically reload the document every day (at a time picked by the system). If @@ -259,6 +269,9 @@ class ImportDocumentsRequest(proto.Message): r"""Request message for [Documents.ImportDocuments][google.cloud.dialogflow.v2beta1.Documents.ImportDocuments]. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent (str): Required. The knowledge base to import documents into. @@ -271,6 +284,7 @@ class ImportDocumentsRequest(proto.Message): These URIs may have the forms ``gs:///``. ``gs:////*.``. + This field is a member of `oneof`_ ``source``. document_template (google.cloud.dialogflow_v2beta1.types.ImportDocumentTemplate): Required. Document template used for importing all the documents. @@ -383,6 +397,9 @@ class ReloadDocumentRequest(proto.Message): r"""Request message for [Documents.ReloadDocument][google.cloud.dialogflow.v2beta1.Documents.ReloadDocument]. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): Required. The name of the document to reload. Format: @@ -391,6 +408,7 @@ class ReloadDocumentRequest(proto.Message): The path for a Cloud Storage source file for reloading document content. If not provided, the Document's existing source will be reloaded. + This field is a member of `oneof`_ ``source``. import_gcs_custom_metadata (bool): Whether to import custom metadata from Google Cloud Storage. Only valid when the document diff --git a/google/cloud/dialogflow_v2beta1/types/entity_type.py b/google/cloud/dialogflow_v2beta1/types/entity_type.py index 1a7bf7754..b2c694f30 100644 --- a/google/cloud/dialogflow_v2beta1/types/entity_type.py +++ b/google/cloud/dialogflow_v2beta1/types/entity_type.py @@ -282,6 +282,13 @@ class BatchUpdateEntityTypesRequest(proto.Message): r"""The request message for [EntityTypes.BatchUpdateEntityTypes][google.cloud.dialogflow.v2beta1.EntityTypes.BatchUpdateEntityTypes]. + 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: parent (str): Required. The name of the agent to update or create entity @@ -295,9 +302,11 @@ class BatchUpdateEntityTypesRequest(proto.Message): file format can either be a serialized proto (of EntityBatch type) or a JSON object. Note: The URI must start with "gs://". + This field is a member of `oneof`_ ``entity_type_batch``. entity_type_batch_inline (google.cloud.dialogflow_v2beta1.types.EntityTypeBatch): The collection of entity types to update or create. + This field is a member of `oneof`_ ``entity_type_batch``. language_code (str): Optional. The language used to access language-specific data. If not specified, the agent's default language is diff --git a/google/cloud/dialogflow_v2beta1/types/fulfillment.py b/google/cloud/dialogflow_v2beta1/types/fulfillment.py index ed3d1a3db..d6ff49e7e 100644 --- a/google/cloud/dialogflow_v2beta1/types/fulfillment.py +++ b/google/cloud/dialogflow_v2beta1/types/fulfillment.py @@ -36,6 +36,9 @@ class Fulfillment(proto.Message): For more information, see the `fulfillment guide `__. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): Required. The unique identifier of the fulfillment. @@ -52,6 +55,7 @@ class Fulfillment(proto.Message): Environment. generic_web_service (google.cloud.dialogflow_v2beta1.types.Fulfillment.GenericWebService): Configuration for a generic web service. + This field is a member of `oneof`_ ``fulfillment``. enabled (bool): Whether fulfillment is enabled. features (Sequence[google.cloud.dialogflow_v2beta1.types.Fulfillment.Feature]): diff --git a/google/cloud/dialogflow_v2beta1/types/intent.py b/google/cloud/dialogflow_v2beta1/types/intent.py index 19e65cb00..2070fe812 100644 --- a/google/cloud/dialogflow_v2beta1/types/intent.py +++ b/google/cloud/dialogflow_v2beta1/types/intent.py @@ -324,56 +324,83 @@ class Parameter(proto.Message): class Message(proto.Message): r"""Corresponds to the ``Response`` field in the Dialogflow console. + 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: text (google.cloud.dialogflow_v2beta1.types.Intent.Message.Text): Returns a text response. + This field is a member of `oneof`_ ``message``. image (google.cloud.dialogflow_v2beta1.types.Intent.Message.Image): Displays an image. + This field is a member of `oneof`_ ``message``. quick_replies (google.cloud.dialogflow_v2beta1.types.Intent.Message.QuickReplies): Displays quick replies. + This field is a member of `oneof`_ ``message``. card (google.cloud.dialogflow_v2beta1.types.Intent.Message.Card): Displays a card. + This field is a member of `oneof`_ ``message``. payload (google.protobuf.struct_pb2.Struct): A custom platform-specific response. + This field is a member of `oneof`_ ``message``. simple_responses (google.cloud.dialogflow_v2beta1.types.Intent.Message.SimpleResponses): Returns a voice or text-only response for Actions on Google. + This field is a member of `oneof`_ ``message``. basic_card (google.cloud.dialogflow_v2beta1.types.Intent.Message.BasicCard): Displays a basic card for Actions on Google. + This field is a member of `oneof`_ ``message``. suggestions (google.cloud.dialogflow_v2beta1.types.Intent.Message.Suggestions): Displays suggestion chips for Actions on Google. + This field is a member of `oneof`_ ``message``. link_out_suggestion (google.cloud.dialogflow_v2beta1.types.Intent.Message.LinkOutSuggestion): Displays a link out suggestion chip for Actions on Google. + This field is a member of `oneof`_ ``message``. list_select (google.cloud.dialogflow_v2beta1.types.Intent.Message.ListSelect): Displays a list card for Actions on Google. + This field is a member of `oneof`_ ``message``. carousel_select (google.cloud.dialogflow_v2beta1.types.Intent.Message.CarouselSelect): Displays a carousel card for Actions on Google. + This field is a member of `oneof`_ ``message``. telephony_play_audio (google.cloud.dialogflow_v2beta1.types.Intent.Message.TelephonyPlayAudio): Plays audio from a file in Telephony Gateway. + This field is a member of `oneof`_ ``message``. telephony_synthesize_speech (google.cloud.dialogflow_v2beta1.types.Intent.Message.TelephonySynthesizeSpeech): Synthesizes speech in Telephony Gateway. + This field is a member of `oneof`_ ``message``. telephony_transfer_call (google.cloud.dialogflow_v2beta1.types.Intent.Message.TelephonyTransferCall): Transfers the call in Telephony Gateway. + This field is a member of `oneof`_ ``message``. rbm_text (google.cloud.dialogflow_v2beta1.types.Intent.Message.RbmText): Rich Business Messaging (RBM) text response. RBM allows businesses to send enriched and branded versions of SMS. See https://jibe.google.com/business-messaging. + This field is a member of `oneof`_ ``message``. rbm_standalone_rich_card (google.cloud.dialogflow_v2beta1.types.Intent.Message.RbmStandaloneCard): Standalone Rich Business Messaging (RBM) rich card response. + This field is a member of `oneof`_ ``message``. rbm_carousel_rich_card (google.cloud.dialogflow_v2beta1.types.Intent.Message.RbmCarouselCard): Rich Business Messaging (RBM) carousel rich card response. + This field is a member of `oneof`_ ``message``. browse_carousel_card (google.cloud.dialogflow_v2beta1.types.Intent.Message.BrowseCarouselCard): Browse carousel card for Actions on Google. + This field is a member of `oneof`_ ``message``. table_card (google.cloud.dialogflow_v2beta1.types.Intent.Message.TableCard): Table card for Actions on Google. + This field is a member of `oneof`_ ``message``. media_content (google.cloud.dialogflow_v2beta1.types.Intent.Message.MediaContent): The media content card for Actions on Google. + This field is a member of `oneof`_ ``message``. platform (google.cloud.dialogflow_v2beta1.types.Intent.Message.Platform): Optional. The platform that this message is intended for. @@ -727,12 +754,21 @@ class TelephonySynthesizeSpeech(proto.Message): at request-level or can come from the agent-level synthesizer config. + 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: text (str): The raw text to be synthesized. + This field is a member of `oneof`_ ``source``. ssml (str): The SSML to be synthesized. For more information, see `SSML `__. + This field is a member of `oneof`_ ``source``. """ text = proto.Field(proto.STRING, number=1, oneof="source",) @@ -950,13 +986,22 @@ class RbmSuggestion(proto.Message): user to easily select/click a predefined response or perform an action (like opening a web uri). + 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: reply (google.cloud.dialogflow_v2beta1.types.Intent.Message.RbmSuggestedReply): Predefined replies for user to select instead of typing + This field is a member of `oneof`_ ``suggestion``. action (google.cloud.dialogflow_v2beta1.types.Intent.Message.RbmSuggestedAction): Predefined client side actions that user can choose + This field is a member of `oneof`_ ``suggestion``. """ reply = proto.Field( @@ -994,6 +1039,13 @@ class RbmSuggestedAction(proto.Message): r"""Rich Business Messaging (RBM) suggested client-side action that the user can choose from the card. + 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: text (str): Text to display alongside the action. @@ -1006,12 +1058,15 @@ class RbmSuggestedAction(proto.Message): dial (google.cloud.dialogflow_v2beta1.types.Intent.Message.RbmSuggestedAction.RbmSuggestedActionDial): Suggested client side action: Dial a phone number + This field is a member of `oneof`_ ``action``. open_url (google.cloud.dialogflow_v2beta1.types.Intent.Message.RbmSuggestedAction.RbmSuggestedActionOpenUri): Suggested client side action: Open a URI on device + This field is a member of `oneof`_ ``action``. share_location (google.cloud.dialogflow_v2beta1.types.Intent.Message.RbmSuggestedAction.RbmSuggestedActionShareLocation): Suggested client side action: Share user location + This field is a member of `oneof`_ ``action``. """ class RbmSuggestedActionDial(proto.Message): @@ -1088,6 +1143,13 @@ class ResponseMediaType(proto.Enum): class ResponseMediaObject(proto.Message): r"""Response media object for media content card. + 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. Name of media card. @@ -1096,9 +1158,11 @@ class ResponseMediaObject(proto.Message): large_image (google.cloud.dialogflow_v2beta1.types.Intent.Message.Image): Optional. Image to display above media content. + This field is a member of `oneof`_ ``image``. icon (google.cloud.dialogflow_v2beta1.types.Intent.Message.Image): Optional. Icon to display above media content. + This field is a member of `oneof`_ ``image``. content_url (str): Required. Url where the media is stored. """ @@ -1639,6 +1703,13 @@ class BatchUpdateIntentsRequest(proto.Message): r"""The request message for [Intents.BatchUpdateIntents][google.cloud.dialogflow.v2beta1.Intents.BatchUpdateIntents]. + 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: parent (str): Required. The name of the agent to update or create intents @@ -1652,9 +1723,11 @@ class BatchUpdateIntentsRequest(proto.Message): format can either be a serialized proto (of IntentBatch type) or JSON object. Note: The URI must start with "gs://". + This field is a member of `oneof`_ ``intent_batch``. intent_batch_inline (google.cloud.dialogflow_v2beta1.types.IntentBatch): The collection of intents to update or create. + This field is a member of `oneof`_ ``intent_batch``. language_code (str): Optional. The language used to access language-specific data. If not specified, the agent's default language is diff --git a/google/cloud/dialogflow_v2beta1/types/participant.py b/google/cloud/dialogflow_v2beta1/types/participant.py index 05ff2cf9b..fa115c822 100644 --- a/google/cloud/dialogflow_v2beta1/types/participant.py +++ b/google/cloud/dialogflow_v2beta1/types/participant.py @@ -283,11 +283,19 @@ class OutputAudio(proto.Message): class AutomatedAgentReply(proto.Message): r"""Represents a response from an automated agent. + 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: detect_intent_response (google.cloud.dialogflow_v2beta1.types.DetectIntentResponse): Response of the Dialogflow [Sessions.DetectIntent][google.cloud.dialogflow.v2beta1.Sessions.DetectIntent] call. + This field is a member of `oneof`_ ``response``. response_messages (Sequence[google.cloud.dialogflow_v2beta1.types.ResponseMessage]): Response messages from the automated agent. intent (str): @@ -296,9 +304,11 @@ class AutomatedAgentReply(proto.Message): ``projects//locations/ /agent/intents/``. For a V3 query, the value format is ``projects//locations/ /agents//intents/``. + This field is a member of `oneof`_ ``match``. event (str): Event name if an event is triggered for the query. + This field is a member of `oneof`_ ``match``. match_confidence (float): The confidence of the match. Values range from 0.0 (completely uncertain) to 1.0 @@ -376,6 +386,13 @@ class AnalyzeContentRequest(proto.Message): r"""The request message for [Participants.AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent]. + 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: participant (str): Required. The name of the participant this text comes from. @@ -383,8 +400,10 @@ class AnalyzeContentRequest(proto.Message): ``projects//locations//conversations//participants/``. text_input (google.cloud.dialogflow_v2beta1.types.TextInput): The natural language text to be processed. + This field is a member of `oneof`_ ``input``. event_input (google.cloud.dialogflow_v2beta1.types.EventInput): An input event to send to Dialogflow. + This field is a member of `oneof`_ ``input``. reply_audio_config (google.cloud.dialogflow_v2beta1.types.OutputAudioConfig): Speech synthesis configuration. The speech synthesis settings for a virtual @@ -661,16 +680,27 @@ class SuggestionResult(proto.Message): as well as [HumanAgentAssistantEvent][google.cloud.dialogflow.v2beta1.HumanAgentAssistantEvent]. + 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: error (google.rpc.status_pb2.Status): Error status if the request failed. + This field is a member of `oneof`_ ``suggestion_response``. suggest_articles_response (google.cloud.dialogflow_v2beta1.types.SuggestArticlesResponse): SuggestArticlesResponse if request is for ARTICLE_SUGGESTION. + This field is a member of `oneof`_ ``suggestion_response``. suggest_faq_answers_response (google.cloud.dialogflow_v2beta1.types.SuggestFaqAnswersResponse): SuggestFaqAnswersResponse if request is for FAQ_ANSWER. + This field is a member of `oneof`_ ``suggestion_response``. suggest_smart_replies_response (google.cloud.dialogflow_v2beta1.types.SuggestSmartRepliesResponse): SuggestSmartRepliesResponse if request is for SMART_REPLY. + This field is a member of `oneof`_ ``suggestion_response``. """ error = proto.Field( @@ -1088,21 +1118,33 @@ class CompileSuggestionResponse(proto.Message): class ResponseMessage(proto.Message): r"""Response messages from an automated agent. + 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: text (google.cloud.dialogflow_v2beta1.types.ResponseMessage.Text): Returns a text response. + This field is a member of `oneof`_ ``message``. payload (google.protobuf.struct_pb2.Struct): Returns a response containing a custom, platform-specific payload. + This field is a member of `oneof`_ ``message``. live_agent_handoff (google.cloud.dialogflow_v2beta1.types.ResponseMessage.LiveAgentHandoff): Hands off conversation to a live agent. + This field is a member of `oneof`_ ``message``. end_interaction (google.cloud.dialogflow_v2beta1.types.ResponseMessage.EndInteraction): A signal that indicates the interaction with the Dialogflow agent has ended. + This field is a member of `oneof`_ ``message``. telephony_transfer_call (google.cloud.dialogflow_v2beta1.types.ResponseMessage.TelephonyTransferCall): A signal that the client should transfer the phone call connected to this agent to a third- party endpoint. + This field is a member of `oneof`_ ``message``. """ class Text(proto.Message): @@ -1148,12 +1190,21 @@ class TelephonyTransferCall(proto.Message): r"""Represents the signal that telles the client to transfer the phone call connected to the agent to a third-party endpoint. + 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: phone_number (str): Transfer the call to a phone number in `E.164 format `__. + This field is a member of `oneof`_ ``endpoint``. sip_uri (str): Transfer the call to a SIP endpoint. + This field is a member of `oneof`_ ``endpoint``. """ phone_number = proto.Field(proto.STRING, number=1, oneof="endpoint",) diff --git a/google/cloud/dialogflow_v2beta1/types/session.py b/google/cloud/dialogflow_v2beta1/types/session.py index 4f915db4b..84a7f82ff 100644 --- a/google/cloud/dialogflow_v2beta1/types/session.py +++ b/google/cloud/dialogflow_v2beta1/types/session.py @@ -263,17 +263,28 @@ class QueryInput(proto.Message): 3. An event that specifies which intent to trigger. + 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: audio_config (google.cloud.dialogflow_v2beta1.types.InputAudioConfig): Instructs the speech recognizer how to process the speech audio. + This field is a member of `oneof`_ ``input``. text (google.cloud.dialogflow_v2beta1.types.TextInput): The natural language text to be processed. + This field is a member of `oneof`_ ``input``. event (google.cloud.dialogflow_v2beta1.types.EventInput): The event to be processed. + This field is a member of `oneof`_ ``input``. dtmf (google.cloud.dialogflow_v2beta1.types.TelephonyDtmfEvents): The DTMF digits used to invoke intent and fill in parameter value. + This field is a member of `oneof`_ ``input``. """ audio_config = proto.Field( @@ -632,11 +643,11 @@ class StreamingDetectIntentResponse(proto.Message): Multiple response messages can be returned in order: - 1. If the input was set to streaming audio, the first one or more - messages contain ``recognition_result``. Each - ``recognition_result`` represents a more complete transcript of - what the user said. The last ``recognition_result`` has - ``is_final`` set to ``true``. + 1. If the ``StreamingDetectIntentRequest.input_audio`` field was + set, the ``recognition_result`` field is populated for one or + more messages. See the + [StreamingRecognitionResult][google.cloud.dialogflow.v2beta1.StreamingRecognitionResult] + message for details about the result message sequence. 2. The next message contains ``response_id``, ``query_result``, ``alternative_query_results`` and optionally ``webhook_status`` @@ -706,33 +717,42 @@ class StreamingRecognitionResult(proto.Message): the audio that is currently being processed or an indication that this is the end of the single requested utterance. - Example: - - 1. transcript: "tube" - - 2. transcript: "to be a" - - 3. transcript: "to be" - - 4. transcript: "to be or not to be" is_final: true - - 5. transcript: " that's" - - 6. transcript: " that is" - - 7. message_type: ``END_OF_SINGLE_UTTERANCE`` - - 8. transcript: " that is the question" is_final: true - - Only two of the responses contain final results (#4 and #8 indicated - by ``is_final: true``). Concatenating these generates the full - transcript: "to be or not to be that is the question". - - In each response we populate: - - - for ``TRANSCRIPT``: ``transcript`` and possibly ``is_final``. - - - for ``END_OF_SINGLE_UTTERANCE``: only ``message_type``. + While end-user audio is being processed, Dialogflow sends a series + of results. Each result may contain a ``transcript`` value. A + transcript represents a portion of the utterance. While the + recognizer is processing audio, transcript values may be interim + values or finalized values. Once a transcript is finalized, the + ``is_final`` value is set to true and processing continues for the + next transcript. + + If + ``StreamingDetectIntentRequest.query_input.audio_config.single_utterance`` + was true, and the recognizer has completed processing audio, the + ``message_type`` value is set to \`END_OF_SINGLE_UTTERANCE and the + following (last) result contains the last finalized transcript. + + The complete end-user utterance is determined by concatenating the + finalized transcript values received for the series of results. + + In the following example, single utterance is enabled. In the case + where single utterance is not enabled, result 7 would not occur. + + :: + + Num | transcript | message_type | is_final + --- | ----------------------- | ----------------------- | -------- + 1 | "tube" | TRANSCRIPT | false + 2 | "to be a" | TRANSCRIPT | false + 3 | "to be" | TRANSCRIPT | false + 4 | "to be or not to be" | TRANSCRIPT | true + 5 | "that's" | TRANSCRIPT | false + 6 | "that is | TRANSCRIPT | false + 7 | unset | END_OF_SINGLE_UTTERANCE | unset + 8 | " that is the question" | TRANSCRIPT | true + + Concatenating the finalized transcripts with ``is_final`` set to + true, the complete utterance becomes "to be or not to be that is the + question". Attributes: message_type (google.cloud.dialogflow_v2beta1.types.StreamingRecognitionResult.MessageType): diff --git a/setup.py b/setup.py index 350b875c3..8e068fcfe 100644 --- a/setup.py +++ b/setup.py @@ -25,9 +25,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", ] package_root = os.path.abspath(os.path.dirname(__file__)) diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index fcce18a22..30a8ed74a 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -2,9 +2,7 @@ # are correct in setup.py # List all library dependencies and extras in this file. # Pin the version to the lower bound. - # e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", # Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.10.0 -packaging==14.3 diff --git a/tests/unit/gapic/dialogflow_v2/test_agents.py b/tests/unit/gapic/dialogflow_v2/test_agents.py index 3ee58070e..49d57d2b3 100644 --- a/tests/unit/gapic/dialogflow_v2/test_agents.py +++ b/tests/unit/gapic/dialogflow_v2/test_agents.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.dialogflow_v2.services.agents import AgentsClient from google.cloud.dialogflow_v2.services.agents import pagers from google.cloud.dialogflow_v2.services.agents import transports -from google.cloud.dialogflow_v2.services.agents.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import agent from google.cloud.dialogflow_v2.types import agent as gcd_agent from google.cloud.dialogflow_v2.types import validation_result @@ -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" @@ -200,7 +182,7 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -217,7 +199,7 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -234,7 +216,7 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -263,7 +245,7 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -318,7 +300,7 @@ def test_agents_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 @@ -360,7 +342,7 @@ def test_agents_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, @@ -382,7 +364,7 @@ def test_agents_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, @@ -409,7 +391,7 @@ def test_agents_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, @@ -436,7 +418,7 @@ def test_agents_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", @@ -2340,7 +2322,6 @@ def test_agents_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_agents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2364,29 +2345,6 @@ def test_agents_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_agents_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.dialogflow_v2.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.AgentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_agents_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( @@ -2398,7 +2356,6 @@ def test_agents_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_agents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2414,26 +2371,10 @@ def test_agents_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_agents_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) - AgentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.AgentsGrpcTransport, transports.AgentsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_agents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2450,26 +2391,6 @@ def test_agents_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.AgentsGrpcTransport, transports.AgentsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_agents_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_answer_records.py b/tests/unit/gapic/dialogflow_v2/test_answer_records.py index 45e45f6af..34eb0d4b4 100644 --- a/tests/unit/gapic/dialogflow_v2/test_answer_records.py +++ b/tests/unit/gapic/dialogflow_v2/test_answer_records.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.dialogflow_v2.services.answer_records import AnswerRecordsClient from google.cloud.dialogflow_v2.services.answer_records import pagers from google.cloud.dialogflow_v2.services.answer_records import transports -from google.cloud.dialogflow_v2.services.answer_records.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import answer_record from google.cloud.dialogflow_v2.types import answer_record as gcd_answer_record from google.cloud.dialogflow_v2.types import participant @@ -48,20 +44,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" @@ -218,7 +200,7 @@ def test_answer_records_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, @@ -235,7 +217,7 @@ def test_answer_records_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, @@ -252,7 +234,7 @@ def test_answer_records_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, @@ -281,7 +263,7 @@ def test_answer_records_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, @@ -340,7 +322,7 @@ def test_answer_records_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 @@ -382,7 +364,7 @@ def test_answer_records_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, @@ -404,7 +386,7 @@ def test_answer_records_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, @@ -435,7 +417,7 @@ def test_answer_records_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, @@ -466,7 +448,7 @@ def test_answer_records_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", @@ -1237,7 +1219,6 @@ def test_answer_records_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_answer_records_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1261,29 +1242,6 @@ def test_answer_records_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_answer_records_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.dialogflow_v2.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.AnswerRecordsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_answer_records_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( @@ -1295,7 +1253,6 @@ def test_answer_records_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_answer_records_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1311,21 +1268,6 @@ def test_answer_records_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_answer_records_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) - AnswerRecordsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1333,7 +1275,6 @@ def test_answer_records_auth_adc_old_google_auth(): transports.AnswerRecordsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_answer_records_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1350,29 +1291,6 @@ def test_answer_records_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.AnswerRecordsGrpcTransport, - transports.AnswerRecordsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_answer_records_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_contexts.py b/tests/unit/gapic/dialogflow_v2/test_contexts.py index dbe31e5c0..9acdd0a97 100644 --- a/tests/unit/gapic/dialogflow_v2/test_contexts.py +++ b/tests/unit/gapic/dialogflow_v2/test_contexts.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.dialogflow_v2.services.contexts import ContextsClient from google.cloud.dialogflow_v2.services.contexts import pagers from google.cloud.dialogflow_v2.services.contexts import transports -from google.cloud.dialogflow_v2.services.contexts.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import context from google.cloud.dialogflow_v2.types import context as gcd_context from google.oauth2 import service_account @@ -47,20 +43,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" @@ -200,7 +182,7 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -217,7 +199,7 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -234,7 +216,7 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -263,7 +245,7 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -320,7 +302,7 @@ def test_contexts_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 @@ -362,7 +344,7 @@ def test_contexts_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, @@ -384,7 +366,7 @@ def test_contexts_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, @@ -411,7 +393,7 @@ def test_contexts_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, @@ -438,7 +420,7 @@ def test_contexts_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", @@ -1894,7 +1876,6 @@ def test_contexts_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_contexts_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1918,29 +1899,6 @@ def test_contexts_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_contexts_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.dialogflow_v2.services.contexts.transports.ContextsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ContextsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_contexts_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( @@ -1952,7 +1910,6 @@ def test_contexts_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_contexts_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1968,26 +1925,10 @@ def test_contexts_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_contexts_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) - ContextsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.ContextsGrpcTransport, transports.ContextsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_contexts_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2004,26 +1945,6 @@ def test_contexts_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.ContextsGrpcTransport, transports.ContextsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_contexts_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py b/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py index a71f91d10..a826e3395 100644 --- a/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py +++ b/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.dialogflow_v2.services.conversation_profiles import pagers from google.cloud.dialogflow_v2.services.conversation_profiles import transports -from google.cloud.dialogflow_v2.services.conversation_profiles.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import conversation_profile from google.cloud.dialogflow_v2.types import ( @@ -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" @@ -229,7 +211,7 @@ def test_conversation_profiles_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, @@ -246,7 +228,7 @@ def test_conversation_profiles_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, @@ -263,7 +245,7 @@ def test_conversation_profiles_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, @@ -292,7 +274,7 @@ def test_conversation_profiles_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, @@ -361,7 +343,7 @@ def test_conversation_profiles_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 @@ -403,7 +385,7 @@ def test_conversation_profiles_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, @@ -425,7 +407,7 @@ def test_conversation_profiles_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, @@ -460,7 +442,7 @@ def test_conversation_profiles_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, @@ -495,7 +477,7 @@ def test_conversation_profiles_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", @@ -2039,7 +2021,6 @@ def test_conversation_profiles_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_conversation_profiles_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2063,29 +2044,6 @@ def test_conversation_profiles_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_conversation_profiles_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.dialogflow_v2.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ConversationProfilesTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_conversation_profiles_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( @@ -2097,7 +2055,6 @@ def test_conversation_profiles_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_conversation_profiles_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2113,21 +2070,6 @@ def test_conversation_profiles_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_conversation_profiles_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) - ConversationProfilesClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2135,7 +2077,6 @@ def test_conversation_profiles_auth_adc_old_google_auth(): transports.ConversationProfilesGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_conversation_profiles_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2152,29 +2093,6 @@ def test_conversation_profiles_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ConversationProfilesGrpcTransport, - transports.ConversationProfilesGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_conversation_profiles_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_conversations.py b/tests/unit/gapic/dialogflow_v2/test_conversations.py index 3b3e1d7b4..a22748e53 100644 --- a/tests/unit/gapic/dialogflow_v2/test_conversations.py +++ b/tests/unit/gapic/dialogflow_v2/test_conversations.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.dialogflow_v2.services.conversations import ConversationsClient from google.cloud.dialogflow_v2.services.conversations import pagers from google.cloud.dialogflow_v2.services.conversations import transports -from google.cloud.dialogflow_v2.services.conversations.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import conversation from google.cloud.dialogflow_v2.types import conversation as gcd_conversation from google.cloud.dialogflow_v2.types import participant @@ -47,20 +43,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" @@ -217,7 +199,7 @@ def test_conversations_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, @@ -234,7 +216,7 @@ def test_conversations_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, @@ -251,7 +233,7 @@ def test_conversations_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, @@ -280,7 +262,7 @@ def test_conversations_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, @@ -339,7 +321,7 @@ def test_conversations_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 @@ -381,7 +363,7 @@ def test_conversations_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, @@ -403,7 +385,7 @@ def test_conversations_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, @@ -434,7 +416,7 @@ def test_conversations_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, @@ -465,7 +447,7 @@ def test_conversations_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", @@ -2065,7 +2047,6 @@ def test_conversations_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_conversations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2089,29 +2070,6 @@ def test_conversations_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_conversations_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.dialogflow_v2.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ConversationsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_conversations_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( @@ -2123,7 +2081,6 @@ def test_conversations_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_conversations_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2139,21 +2096,6 @@ def test_conversations_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_conversations_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) - ConversationsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2161,7 +2103,6 @@ def test_conversations_auth_adc_old_google_auth(): transports.ConversationsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_conversations_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2178,29 +2119,6 @@ def test_conversations_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ConversationsGrpcTransport, - transports.ConversationsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_conversations_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_documents.py b/tests/unit/gapic/dialogflow_v2/test_documents.py index 909e21f43..cf6e461c4 100644 --- a/tests/unit/gapic/dialogflow_v2/test_documents.py +++ b/tests/unit/gapic/dialogflow_v2/test_documents.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.dialogflow_v2.services.documents import DocumentsClient from google.cloud.dialogflow_v2.services.documents import pagers from google.cloud.dialogflow_v2.services.documents import transports -from google.cloud.dialogflow_v2.services.documents.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import document from google.cloud.dialogflow_v2.types import document as gcd_document from google.longrunning import operations_pb2 @@ -53,20 +49,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" @@ -210,7 +192,7 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -227,7 +209,7 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -244,7 +226,7 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -273,7 +255,7 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -330,7 +312,7 @@ def test_documents_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 @@ -372,7 +354,7 @@ def test_documents_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, @@ -394,7 +376,7 @@ def test_documents_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, @@ -425,7 +407,7 @@ def test_documents_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, @@ -456,7 +438,7 @@ def test_documents_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", @@ -1962,7 +1944,6 @@ def test_documents_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_documents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1986,29 +1967,6 @@ def test_documents_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_documents_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.dialogflow_v2.services.documents.transports.DocumentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_documents_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( @@ -2020,7 +1978,6 @@ def test_documents_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_documents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2036,26 +1993,10 @@ def test_documents_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_documents_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) - DocumentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.DocumentsGrpcTransport, transports.DocumentsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_documents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2072,26 +2013,6 @@ def test_documents_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.DocumentsGrpcTransport, transports.DocumentsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_documents_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_entity_types.py b/tests/unit/gapic/dialogflow_v2/test_entity_types.py index 555f967fe..1281df773 100644 --- a/tests/unit/gapic/dialogflow_v2/test_entity_types.py +++ b/tests/unit/gapic/dialogflow_v2/test_entity_types.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.dialogflow_v2.services.entity_types import EntityTypesClient from google.cloud.dialogflow_v2.services.entity_types import pagers from google.cloud.dialogflow_v2.services.entity_types import transports -from google.cloud.dialogflow_v2.services.entity_types.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import entity_type from google.cloud.dialogflow_v2.types import entity_type as gcd_entity_type from google.longrunning import operations_pb2 @@ -51,20 +47,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" @@ -212,7 +194,7 @@ def test_entity_types_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, @@ -229,7 +211,7 @@ def test_entity_types_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, @@ -246,7 +228,7 @@ def test_entity_types_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, @@ -275,7 +257,7 @@ def test_entity_types_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, @@ -332,7 +314,7 @@ def test_entity_types_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 @@ -374,7 +356,7 @@ def test_entity_types_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, @@ -396,7 +378,7 @@ def test_entity_types_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, @@ -427,7 +409,7 @@ def test_entity_types_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, @@ -458,7 +440,7 @@ def test_entity_types_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", @@ -2965,7 +2947,6 @@ def test_entity_types_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2989,29 +2970,6 @@ def test_entity_types_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_entity_types_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.dialogflow_v2.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.EntityTypesTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_entity_types_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( @@ -3023,7 +2981,6 @@ def test_entity_types_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_entity_types_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3039,26 +2996,10 @@ def test_entity_types_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_entity_types_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) - EntityTypesClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.EntityTypesGrpcTransport, transports.EntityTypesGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_entity_types_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3075,26 +3016,6 @@ def test_entity_types_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.EntityTypesGrpcTransport, transports.EntityTypesGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_entity_types_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_environments.py b/tests/unit/gapic/dialogflow_v2/test_environments.py index 739974e60..73f38b9d0 100644 --- a/tests/unit/gapic/dialogflow_v2/test_environments.py +++ b/tests/unit/gapic/dialogflow_v2/test_environments.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.dialogflow_v2.services.environments import EnvironmentsClient from google.cloud.dialogflow_v2.services.environments import pagers from google.cloud.dialogflow_v2.services.environments import transports -from google.cloud.dialogflow_v2.services.environments.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import environment from google.cloud.dialogflow_v2.types import fulfillment @@ -48,20 +44,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" @@ -209,7 +191,7 @@ def test_environments_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, @@ -226,7 +208,7 @@ def test_environments_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, @@ -243,7 +225,7 @@ def test_environments_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, @@ -272,7 +254,7 @@ def test_environments_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, @@ -329,7 +311,7 @@ def test_environments_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 @@ -371,7 +353,7 @@ def test_environments_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, @@ -393,7 +375,7 @@ def test_environments_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, @@ -424,7 +406,7 @@ def test_environments_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, @@ -455,7 +437,7 @@ def test_environments_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", @@ -1883,7 +1865,6 @@ def test_environments_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_environments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1907,29 +1888,6 @@ def test_environments_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_environments_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.dialogflow_v2.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.EnvironmentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_environments_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( @@ -1941,7 +1899,6 @@ def test_environments_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_environments_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1957,21 +1914,6 @@ def test_environments_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_environments_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) - EnvironmentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1979,7 +1921,6 @@ def test_environments_auth_adc_old_google_auth(): transports.EnvironmentsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_environments_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1996,29 +1937,6 @@ def test_environments_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.EnvironmentsGrpcTransport, - transports.EnvironmentsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_environments_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_fulfillments.py b/tests/unit/gapic/dialogflow_v2/test_fulfillments.py index b402a42f4..0b664419d 100644 --- a/tests/unit/gapic/dialogflow_v2/test_fulfillments.py +++ b/tests/unit/gapic/dialogflow_v2/test_fulfillments.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -35,9 +34,6 @@ from google.cloud.dialogflow_v2.services.fulfillments import FulfillmentsAsyncClient from google.cloud.dialogflow_v2.services.fulfillments import FulfillmentsClient from google.cloud.dialogflow_v2.services.fulfillments import transports -from google.cloud.dialogflow_v2.services.fulfillments.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import fulfillment from google.cloud.dialogflow_v2.types import fulfillment as gcd_fulfillment from google.oauth2 import service_account @@ -45,20 +41,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" @@ -206,7 +188,7 @@ def test_fulfillments_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, @@ -223,7 +205,7 @@ def test_fulfillments_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, @@ -240,7 +222,7 @@ def test_fulfillments_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, @@ -269,7 +251,7 @@ def test_fulfillments_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, @@ -326,7 +308,7 @@ def test_fulfillments_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 @@ -368,7 +350,7 @@ def test_fulfillments_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, @@ -390,7 +372,7 @@ def test_fulfillments_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, @@ -421,7 +403,7 @@ def test_fulfillments_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, @@ -452,7 +434,7 @@ def test_fulfillments_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", @@ -1040,7 +1022,6 @@ def test_fulfillments_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_fulfillments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1064,29 +1045,6 @@ def test_fulfillments_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_fulfillments_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.dialogflow_v2.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.FulfillmentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_fulfillments_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( @@ -1098,7 +1056,6 @@ def test_fulfillments_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_fulfillments_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1114,21 +1071,6 @@ def test_fulfillments_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_fulfillments_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) - FulfillmentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1136,7 +1078,6 @@ def test_fulfillments_auth_adc_old_google_auth(): transports.FulfillmentsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_fulfillments_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1153,29 +1094,6 @@ def test_fulfillments_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.FulfillmentsGrpcTransport, - transports.FulfillmentsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_fulfillments_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_intents.py b/tests/unit/gapic/dialogflow_v2/test_intents.py index 62599ff86..735913dd1 100644 --- a/tests/unit/gapic/dialogflow_v2/test_intents.py +++ b/tests/unit/gapic/dialogflow_v2/test_intents.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.dialogflow_v2.services.intents import IntentsClient from google.cloud.dialogflow_v2.services.intents import pagers from google.cloud.dialogflow_v2.services.intents import transports -from google.cloud.dialogflow_v2.services.intents.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import context from google.cloud.dialogflow_v2.types import intent from google.cloud.dialogflow_v2.types import intent as gcd_intent @@ -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" @@ -200,7 +182,7 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -217,7 +199,7 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -234,7 +216,7 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -263,7 +245,7 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -318,7 +300,7 @@ def test_intents_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 @@ -360,7 +342,7 @@ def test_intents_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, @@ -382,7 +364,7 @@ def test_intents_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, @@ -409,7 +391,7 @@ def test_intents_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, @@ -436,7 +418,7 @@ def test_intents_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", @@ -2368,7 +2350,6 @@ def test_intents_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_intents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2392,29 +2373,6 @@ def test_intents_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_intents_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.dialogflow_v2.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.IntentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_intents_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( @@ -2426,7 +2384,6 @@ def test_intents_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_intents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2442,26 +2399,10 @@ def test_intents_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_intents_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) - IntentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.IntentsGrpcTransport, transports.IntentsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_intents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2478,26 +2419,6 @@ def test_intents_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.IntentsGrpcTransport, transports.IntentsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_intents_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py b/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py index 9902723a3..35b6e616b 100644 --- a/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py +++ b/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.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.dialogflow_v2.services.knowledge_bases import KnowledgeBasesClient from google.cloud.dialogflow_v2.services.knowledge_bases import pagers from google.cloud.dialogflow_v2.services.knowledge_bases import transports -from google.cloud.dialogflow_v2.services.knowledge_bases.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import knowledge_base from google.cloud.dialogflow_v2.types import knowledge_base as gcd_knowledge_base from google.oauth2 import service_account @@ -48,20 +44,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" @@ -218,7 +200,7 @@ def test_knowledge_bases_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, @@ -235,7 +217,7 @@ def test_knowledge_bases_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, @@ -252,7 +234,7 @@ def test_knowledge_bases_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, @@ -281,7 +263,7 @@ def test_knowledge_bases_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, @@ -340,7 +322,7 @@ def test_knowledge_bases_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 @@ -382,7 +364,7 @@ def test_knowledge_bases_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, @@ -404,7 +386,7 @@ def test_knowledge_bases_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, @@ -435,7 +417,7 @@ def test_knowledge_bases_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, @@ -466,7 +448,7 @@ def test_knowledge_bases_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", @@ -1934,7 +1916,6 @@ def test_knowledge_bases_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_knowledge_bases_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1958,29 +1939,6 @@ def test_knowledge_bases_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_knowledge_bases_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.dialogflow_v2.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.KnowledgeBasesTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_knowledge_bases_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( @@ -1992,7 +1950,6 @@ def test_knowledge_bases_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_knowledge_bases_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2008,21 +1965,6 @@ def test_knowledge_bases_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_knowledge_bases_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) - KnowledgeBasesClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2030,7 +1972,6 @@ def test_knowledge_bases_auth_adc_old_google_auth(): transports.KnowledgeBasesGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_knowledge_bases_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2047,29 +1988,6 @@ def test_knowledge_bases_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.KnowledgeBasesGrpcTransport, - transports.KnowledgeBasesGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_knowledge_bases_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_participants.py b/tests/unit/gapic/dialogflow_v2/test_participants.py index deec9085a..9b0ff90d7 100644 --- a/tests/unit/gapic/dialogflow_v2/test_participants.py +++ b/tests/unit/gapic/dialogflow_v2/test_participants.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.dialogflow_v2.services.participants import ParticipantsClient from google.cloud.dialogflow_v2.services.participants import pagers from google.cloud.dialogflow_v2.services.participants import transports -from google.cloud.dialogflow_v2.services.participants.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import context from google.cloud.dialogflow_v2.types import entity_type @@ -53,20 +49,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" @@ -214,7 +196,7 @@ def test_participants_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_participants_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_participants_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_participants_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, @@ -334,7 +316,7 @@ def test_participants_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 @@ -376,7 +358,7 @@ def test_participants_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, @@ -398,7 +380,7 @@ def test_participants_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, @@ -429,7 +411,7 @@ def test_participants_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, @@ -460,7 +442,7 @@ def test_participants_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", @@ -2286,7 +2268,6 @@ def test_participants_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_participants_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2310,29 +2291,6 @@ def test_participants_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_participants_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.dialogflow_v2.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ParticipantsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_participants_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( @@ -2344,7 +2302,6 @@ def test_participants_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_participants_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2360,21 +2317,6 @@ def test_participants_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_participants_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) - ParticipantsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2382,7 +2324,6 @@ def test_participants_auth_adc_old_google_auth(): transports.ParticipantsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_participants_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2399,29 +2340,6 @@ def test_participants_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ParticipantsGrpcTransport, - transports.ParticipantsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_participants_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py b/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py index a4099f8e9..a1c88c206 100644 --- a/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py +++ b/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.dialogflow_v2.services.session_entity_types import pagers from google.cloud.dialogflow_v2.services.session_entity_types import transports -from google.cloud.dialogflow_v2.services.session_entity_types.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import entity_type from google.cloud.dialogflow_v2.types import session_entity_type from google.cloud.dialogflow_v2.types import ( @@ -53,20 +49,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_session_entity_types_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_session_entity_types_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_session_entity_types_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_session_entity_types_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, @@ -356,7 +338,7 @@ def test_session_entity_types_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 @@ -398,7 +380,7 @@ def test_session_entity_types_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, @@ -420,7 +402,7 @@ def test_session_entity_types_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, @@ -451,7 +433,7 @@ def test_session_entity_types_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, @@ -482,7 +464,7 @@ def test_session_entity_types_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", @@ -2018,7 +2000,6 @@ def test_session_entity_types_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_session_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2042,29 +2023,6 @@ def test_session_entity_types_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_session_entity_types_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.dialogflow_v2.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SessionEntityTypesTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_session_entity_types_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( @@ -2076,7 +2034,6 @@ def test_session_entity_types_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_session_entity_types_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2092,21 +2049,6 @@ def test_session_entity_types_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_session_entity_types_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) - SessionEntityTypesClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2114,7 +2056,6 @@ def test_session_entity_types_auth_adc_old_google_auth(): transports.SessionEntityTypesGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_session_entity_types_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2131,29 +2072,6 @@ def test_session_entity_types_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SessionEntityTypesGrpcTransport, - transports.SessionEntityTypesGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_session_entity_types_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_sessions.py b/tests/unit/gapic/dialogflow_v2/test_sessions.py index 4cc063739..f5a3ac35f 100644 --- a/tests/unit/gapic/dialogflow_v2/test_sessions.py +++ b/tests/unit/gapic/dialogflow_v2/test_sessions.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -35,9 +34,6 @@ from google.cloud.dialogflow_v2.services.sessions import SessionsAsyncClient from google.cloud.dialogflow_v2.services.sessions import SessionsClient from google.cloud.dialogflow_v2.services.sessions import transports -from google.cloud.dialogflow_v2.services.sessions.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import context from google.cloud.dialogflow_v2.types import entity_type @@ -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" @@ -205,7 +187,7 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -222,7 +204,7 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -239,7 +221,7 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -268,7 +250,7 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -325,7 +307,7 @@ def test_sessions_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 @@ -367,7 +349,7 @@ def test_sessions_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, @@ -389,7 +371,7 @@ def test_sessions_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, @@ -416,7 +398,7 @@ def test_sessions_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, @@ -443,7 +425,7 @@ def test_sessions_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", @@ -890,7 +872,6 @@ def test_sessions_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_sessions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -914,29 +895,6 @@ def test_sessions_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_sessions_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.dialogflow_v2.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SessionsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_sessions_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( @@ -948,7 +906,6 @@ def test_sessions_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_sessions_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -964,26 +921,10 @@ def test_sessions_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_sessions_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) - SessionsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.SessionsGrpcTransport, transports.SessionsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_sessions_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1000,26 +941,6 @@ def test_sessions_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.SessionsGrpcTransport, transports.SessionsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_sessions_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2/test_versions.py b/tests/unit/gapic/dialogflow_v2/test_versions.py index 4a4bdc7fc..408785487 100644 --- a/tests/unit/gapic/dialogflow_v2/test_versions.py +++ b/tests/unit/gapic/dialogflow_v2/test_versions.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.dialogflow_v2.services.versions import VersionsClient from google.cloud.dialogflow_v2.services.versions import pagers from google.cloud.dialogflow_v2.services.versions import transports -from google.cloud.dialogflow_v2.services.versions.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2.types import version from google.cloud.dialogflow_v2.types import version as gcd_version from google.oauth2 import service_account @@ -47,20 +43,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" @@ -200,7 +182,7 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -217,7 +199,7 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -234,7 +216,7 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -263,7 +245,7 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -320,7 +302,7 @@ def test_versions_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 @@ -362,7 +344,7 @@ def test_versions_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, @@ -384,7 +366,7 @@ def test_versions_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, @@ -411,7 +393,7 @@ def test_versions_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, @@ -438,7 +420,7 @@ def test_versions_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", @@ -1733,7 +1715,6 @@ def test_versions_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_versions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1757,29 +1738,6 @@ def test_versions_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_versions_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.dialogflow_v2.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.VersionsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_versions_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( @@ -1791,7 +1749,6 @@ def test_versions_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_versions_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1807,26 +1764,10 @@ def test_versions_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_versions_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) - VersionsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.VersionsGrpcTransport, transports.VersionsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_versions_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1843,26 +1784,6 @@ def test_versions_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.VersionsGrpcTransport, transports.VersionsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_versions_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_agents.py b/tests/unit/gapic/dialogflow_v2beta1/test_agents.py index 802b41e69..25ad14ce9 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_agents.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_agents.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.dialogflow_v2beta1.services.agents import AgentsClient from google.cloud.dialogflow_v2beta1.services.agents import pagers from google.cloud.dialogflow_v2beta1.services.agents import transports -from google.cloud.dialogflow_v2beta1.services.agents.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import agent from google.cloud.dialogflow_v2beta1.types import agent as gcd_agent from google.cloud.dialogflow_v2beta1.types import validation_result @@ -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" @@ -200,7 +182,7 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -217,7 +199,7 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -234,7 +216,7 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -263,7 +245,7 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -318,7 +300,7 @@ def test_agents_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 @@ -360,7 +342,7 @@ def test_agents_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, @@ -382,7 +364,7 @@ def test_agents_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, @@ -409,7 +391,7 @@ def test_agents_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, @@ -436,7 +418,7 @@ def test_agents_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", @@ -2340,7 +2322,6 @@ def test_agents_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_agents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2364,29 +2345,6 @@ def test_agents_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_agents_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.dialogflow_v2beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.AgentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_agents_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( @@ -2398,7 +2356,6 @@ def test_agents_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_agents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2414,26 +2371,10 @@ def test_agents_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_agents_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) - AgentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.AgentsGrpcTransport, transports.AgentsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_agents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2450,26 +2391,6 @@ def test_agents_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.AgentsGrpcTransport, transports.AgentsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_agents_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py b/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py index 4752acac8..09b58d2fa 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.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.dialogflow_v2beta1.services.answer_records import AnswerRecordsClient from google.cloud.dialogflow_v2beta1.services.answer_records import pagers from google.cloud.dialogflow_v2beta1.services.answer_records import transports -from google.cloud.dialogflow_v2beta1.services.answer_records.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import answer_record from google.cloud.dialogflow_v2beta1.types import answer_record as gcd_answer_record from google.cloud.dialogflow_v2beta1.types import participant @@ -50,20 +46,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" @@ -220,7 +202,7 @@ def test_answer_records_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, @@ -237,7 +219,7 @@ def test_answer_records_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, @@ -254,7 +236,7 @@ def test_answer_records_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, @@ -283,7 +265,7 @@ def test_answer_records_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, @@ -342,7 +324,7 @@ def test_answer_records_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 @@ -384,7 +366,7 @@ def test_answer_records_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, @@ -406,7 +388,7 @@ def test_answer_records_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, @@ -437,7 +419,7 @@ def test_answer_records_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, @@ -468,7 +450,7 @@ def test_answer_records_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", @@ -1389,7 +1371,6 @@ def test_answer_records_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_answer_records_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1413,29 +1394,6 @@ def test_answer_records_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_answer_records_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.dialogflow_v2beta1.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.AnswerRecordsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_answer_records_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( @@ -1447,7 +1405,6 @@ def test_answer_records_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_answer_records_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1463,21 +1420,6 @@ def test_answer_records_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_answer_records_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) - AnswerRecordsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1485,7 +1427,6 @@ def test_answer_records_auth_adc_old_google_auth(): transports.AnswerRecordsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_answer_records_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1502,29 +1443,6 @@ def test_answer_records_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.AnswerRecordsGrpcTransport, - transports.AnswerRecordsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_answer_records_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py b/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py index 759d26a91..c3333bfd4 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_contexts.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.dialogflow_v2beta1.services.contexts import ContextsClient from google.cloud.dialogflow_v2beta1.services.contexts import pagers from google.cloud.dialogflow_v2beta1.services.contexts import transports -from google.cloud.dialogflow_v2beta1.services.contexts.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import context from google.cloud.dialogflow_v2beta1.types import context as gcd_context from google.oauth2 import service_account @@ -47,20 +43,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" @@ -200,7 +182,7 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -217,7 +199,7 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -234,7 +216,7 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -263,7 +245,7 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -320,7 +302,7 @@ def test_contexts_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 @@ -362,7 +344,7 @@ def test_contexts_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, @@ -384,7 +366,7 @@ def test_contexts_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, @@ -411,7 +393,7 @@ def test_contexts_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, @@ -438,7 +420,7 @@ def test_contexts_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", @@ -1894,7 +1876,6 @@ def test_contexts_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_contexts_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1918,29 +1899,6 @@ def test_contexts_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_contexts_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.dialogflow_v2beta1.services.contexts.transports.ContextsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ContextsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_contexts_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( @@ -1952,7 +1910,6 @@ def test_contexts_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_contexts_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1968,26 +1925,10 @@ def test_contexts_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_contexts_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) - ContextsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.ContextsGrpcTransport, transports.ContextsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_contexts_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2004,26 +1945,6 @@ def test_contexts_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.ContextsGrpcTransport, transports.ContextsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_contexts_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py b/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py index b77252a19..2cd114fde 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.dialogflow_v2beta1.services.conversation_profiles import pagers from google.cloud.dialogflow_v2beta1.services.conversation_profiles import transports -from google.cloud.dialogflow_v2beta1.services.conversation_profiles.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import conversation_profile from google.cloud.dialogflow_v2beta1.types import ( @@ -55,20 +51,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_conversation_profiles_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_conversation_profiles_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_conversation_profiles_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_conversation_profiles_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_conversation_profiles_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_conversation_profiles_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_conversation_profiles_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, @@ -461,7 +443,7 @@ def test_conversation_profiles_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, @@ -496,7 +478,7 @@ def test_conversation_profiles_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", @@ -2064,7 +2046,6 @@ def test_conversation_profiles_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_conversation_profiles_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2088,29 +2069,6 @@ def test_conversation_profiles_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_conversation_profiles_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.dialogflow_v2beta1.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ConversationProfilesTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_conversation_profiles_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( @@ -2122,7 +2080,6 @@ def test_conversation_profiles_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_conversation_profiles_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2138,21 +2095,6 @@ def test_conversation_profiles_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_conversation_profiles_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) - ConversationProfilesClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2160,7 +2102,6 @@ def test_conversation_profiles_auth_adc_old_google_auth(): transports.ConversationProfilesGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_conversation_profiles_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2177,29 +2118,6 @@ def test_conversation_profiles_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ConversationProfilesGrpcTransport, - transports.ConversationProfilesGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_conversation_profiles_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py b/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py index b8f4e880a..ad606a1bc 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_conversations.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.dialogflow_v2beta1.services.conversations import ConversationsClient from google.cloud.dialogflow_v2beta1.services.conversations import pagers from google.cloud.dialogflow_v2beta1.services.conversations import transports -from google.cloud.dialogflow_v2beta1.services.conversations.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import conversation from google.cloud.dialogflow_v2beta1.types import conversation as gcd_conversation from google.cloud.dialogflow_v2beta1.types import participant @@ -51,20 +47,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" @@ -221,7 +203,7 @@ def test_conversations_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, @@ -238,7 +220,7 @@ def test_conversations_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, @@ -255,7 +237,7 @@ def test_conversations_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, @@ -284,7 +266,7 @@ def test_conversations_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, @@ -343,7 +325,7 @@ def test_conversations_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 @@ -385,7 +367,7 @@ def test_conversations_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, @@ -407,7 +389,7 @@ def test_conversations_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, @@ -438,7 +420,7 @@ def test_conversations_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, @@ -469,7 +451,7 @@ def test_conversations_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", @@ -2285,7 +2267,6 @@ def test_conversations_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_conversations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2309,29 +2290,6 @@ def test_conversations_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_conversations_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.dialogflow_v2beta1.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ConversationsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_conversations_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( @@ -2343,7 +2301,6 @@ def test_conversations_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_conversations_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2359,21 +2316,6 @@ def test_conversations_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_conversations_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) - ConversationsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2381,7 +2323,6 @@ def test_conversations_auth_adc_old_google_auth(): transports.ConversationsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_conversations_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2398,29 +2339,6 @@ def test_conversations_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ConversationsGrpcTransport, - transports.ConversationsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_conversations_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_documents.py b/tests/unit/gapic/dialogflow_v2beta1/test_documents.py index 35eed57bf..cc4dda0da 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_documents.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_documents.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.dialogflow_v2beta1.services.documents import DocumentsClient from google.cloud.dialogflow_v2beta1.services.documents import pagers from google.cloud.dialogflow_v2beta1.services.documents import transports -from google.cloud.dialogflow_v2beta1.services.documents.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import document from google.cloud.dialogflow_v2beta1.types import document as gcd_document from google.cloud.dialogflow_v2beta1.types import gcs @@ -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" @@ -211,7 +193,7 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -228,7 +210,7 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -245,7 +227,7 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -274,7 +256,7 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -331,7 +313,7 @@ def test_documents_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 @@ -373,7 +355,7 @@ def test_documents_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, @@ -395,7 +377,7 @@ def test_documents_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, @@ -426,7 +408,7 @@ def test_documents_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, @@ -457,7 +439,7 @@ def test_documents_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", @@ -2094,7 +2076,6 @@ def test_documents_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_documents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2118,29 +2099,6 @@ def test_documents_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_documents_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.dialogflow_v2beta1.services.documents.transports.DocumentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_documents_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( @@ -2152,7 +2110,6 @@ def test_documents_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_documents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2168,26 +2125,10 @@ def test_documents_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_documents_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) - DocumentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.DocumentsGrpcTransport, transports.DocumentsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_documents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2204,26 +2145,6 @@ def test_documents_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.DocumentsGrpcTransport, transports.DocumentsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_documents_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py b/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py index 2f31db3e3..6a9c6a16a 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.dialogflow_v2beta1.services.entity_types import EntityTypesClient from google.cloud.dialogflow_v2beta1.services.entity_types import pagers from google.cloud.dialogflow_v2beta1.services.entity_types import transports -from google.cloud.dialogflow_v2beta1.services.entity_types.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import entity_type from google.cloud.dialogflow_v2beta1.types import entity_type as gcd_entity_type from google.longrunning import operations_pb2 @@ -51,20 +47,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" @@ -212,7 +194,7 @@ def test_entity_types_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, @@ -229,7 +211,7 @@ def test_entity_types_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, @@ -246,7 +228,7 @@ def test_entity_types_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, @@ -275,7 +257,7 @@ def test_entity_types_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, @@ -332,7 +314,7 @@ def test_entity_types_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 @@ -374,7 +356,7 @@ def test_entity_types_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, @@ -396,7 +378,7 @@ def test_entity_types_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, @@ -427,7 +409,7 @@ def test_entity_types_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, @@ -458,7 +440,7 @@ def test_entity_types_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", @@ -2971,7 +2953,6 @@ def test_entity_types_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2995,29 +2976,6 @@ def test_entity_types_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_entity_types_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.dialogflow_v2beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.EntityTypesTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_entity_types_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( @@ -3029,7 +2987,6 @@ def test_entity_types_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_entity_types_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3045,26 +3002,10 @@ def test_entity_types_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_entity_types_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) - EntityTypesClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.EntityTypesGrpcTransport, transports.EntityTypesGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_entity_types_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3081,26 +3022,6 @@ def test_entity_types_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.EntityTypesGrpcTransport, transports.EntityTypesGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_entity_types_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_environments.py b/tests/unit/gapic/dialogflow_v2beta1/test_environments.py index 41e373b8a..83370f705 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_environments.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_environments.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.dialogflow_v2beta1.services.environments import EnvironmentsClient from google.cloud.dialogflow_v2beta1.services.environments import pagers from google.cloud.dialogflow_v2beta1.services.environments import transports -from google.cloud.dialogflow_v2beta1.services.environments.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import environment from google.cloud.dialogflow_v2beta1.types import fulfillment @@ -50,20 +46,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" @@ -211,7 +193,7 @@ def test_environments_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, @@ -228,7 +210,7 @@ def test_environments_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, @@ -245,7 +227,7 @@ def test_environments_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, @@ -274,7 +256,7 @@ def test_environments_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, @@ -331,7 +313,7 @@ def test_environments_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 @@ -373,7 +355,7 @@ def test_environments_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, @@ -395,7 +377,7 @@ def test_environments_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, @@ -426,7 +408,7 @@ def test_environments_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, @@ -457,7 +439,7 @@ def test_environments_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", @@ -1885,7 +1867,6 @@ def test_environments_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_environments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1909,29 +1890,6 @@ def test_environments_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_environments_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.dialogflow_v2beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.EnvironmentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_environments_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( @@ -1943,7 +1901,6 @@ def test_environments_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_environments_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1959,21 +1916,6 @@ def test_environments_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_environments_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) - EnvironmentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1981,7 +1923,6 @@ def test_environments_auth_adc_old_google_auth(): transports.EnvironmentsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_environments_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1998,29 +1939,6 @@ def test_environments_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.EnvironmentsGrpcTransport, - transports.EnvironmentsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_environments_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py b/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py index 21b26f833..c87fd48c6 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -37,9 +36,6 @@ ) from google.cloud.dialogflow_v2beta1.services.fulfillments import FulfillmentsClient from google.cloud.dialogflow_v2beta1.services.fulfillments import transports -from google.cloud.dialogflow_v2beta1.services.fulfillments.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import fulfillment from google.cloud.dialogflow_v2beta1.types import fulfillment as gcd_fulfillment from google.oauth2 import service_account @@ -47,20 +43,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" @@ -208,7 +190,7 @@ def test_fulfillments_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, @@ -225,7 +207,7 @@ def test_fulfillments_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, @@ -242,7 +224,7 @@ def test_fulfillments_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, @@ -271,7 +253,7 @@ def test_fulfillments_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, @@ -328,7 +310,7 @@ def test_fulfillments_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 @@ -370,7 +352,7 @@ def test_fulfillments_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, @@ -392,7 +374,7 @@ def test_fulfillments_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, @@ -423,7 +405,7 @@ def test_fulfillments_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, @@ -454,7 +436,7 @@ def test_fulfillments_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", @@ -1042,7 +1024,6 @@ def test_fulfillments_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_fulfillments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1066,29 +1047,6 @@ def test_fulfillments_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_fulfillments_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.dialogflow_v2beta1.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.FulfillmentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_fulfillments_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( @@ -1100,7 +1058,6 @@ def test_fulfillments_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_fulfillments_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1116,21 +1073,6 @@ def test_fulfillments_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_fulfillments_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) - FulfillmentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1138,7 +1080,6 @@ def test_fulfillments_auth_adc_old_google_auth(): transports.FulfillmentsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_fulfillments_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1155,29 +1096,6 @@ def test_fulfillments_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.FulfillmentsGrpcTransport, - transports.FulfillmentsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_fulfillments_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_intents.py b/tests/unit/gapic/dialogflow_v2beta1/test_intents.py index f9e411908..178525995 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_intents.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_intents.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.dialogflow_v2beta1.services.intents import IntentsClient from google.cloud.dialogflow_v2beta1.services.intents import pagers from google.cloud.dialogflow_v2beta1.services.intents import transports -from google.cloud.dialogflow_v2beta1.services.intents.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import context from google.cloud.dialogflow_v2beta1.types import intent from google.cloud.dialogflow_v2beta1.types import intent as gcd_intent @@ -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" @@ -200,7 +182,7 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -217,7 +199,7 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -234,7 +216,7 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -263,7 +245,7 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -318,7 +300,7 @@ def test_intents_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 @@ -360,7 +342,7 @@ def test_intents_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, @@ -382,7 +364,7 @@ def test_intents_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, @@ -409,7 +391,7 @@ def test_intents_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, @@ -436,7 +418,7 @@ def test_intents_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", @@ -2380,7 +2362,6 @@ def test_intents_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_intents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2404,29 +2385,6 @@ def test_intents_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_intents_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.dialogflow_v2beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.IntentsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_intents_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( @@ -2438,7 +2396,6 @@ def test_intents_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_intents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2454,26 +2411,10 @@ def test_intents_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_intents_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) - IntentsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.IntentsGrpcTransport, transports.IntentsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_intents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2490,26 +2431,6 @@ def test_intents_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.IntentsGrpcTransport, transports.IntentsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_intents_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py b/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py index 593d0e8b7..b22f1c5dc 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.dialogflow_v2beta1.services.knowledge_bases import pagers from google.cloud.dialogflow_v2beta1.services.knowledge_bases import transports -from google.cloud.dialogflow_v2beta1.services.knowledge_bases.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import knowledge_base from google.cloud.dialogflow_v2beta1.types import knowledge_base as gcd_knowledge_base from google.oauth2 import service_account @@ -50,20 +46,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" @@ -220,7 +202,7 @@ def test_knowledge_bases_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, @@ -237,7 +219,7 @@ def test_knowledge_bases_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, @@ -254,7 +236,7 @@ def test_knowledge_bases_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, @@ -283,7 +265,7 @@ def test_knowledge_bases_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, @@ -342,7 +324,7 @@ def test_knowledge_bases_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 @@ -384,7 +366,7 @@ def test_knowledge_bases_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, @@ -406,7 +388,7 @@ def test_knowledge_bases_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, @@ -437,7 +419,7 @@ def test_knowledge_bases_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, @@ -468,7 +450,7 @@ def test_knowledge_bases_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", @@ -1936,7 +1918,6 @@ def test_knowledge_bases_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_knowledge_bases_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1960,29 +1941,6 @@ def test_knowledge_bases_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_knowledge_bases_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.dialogflow_v2beta1.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.KnowledgeBasesTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_knowledge_bases_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( @@ -1994,7 +1952,6 @@ def test_knowledge_bases_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_knowledge_bases_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2010,21 +1967,6 @@ def test_knowledge_bases_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_knowledge_bases_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) - KnowledgeBasesClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2032,7 +1974,6 @@ def test_knowledge_bases_auth_adc_old_google_auth(): transports.KnowledgeBasesGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_knowledge_bases_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2049,29 +1990,6 @@ def test_knowledge_bases_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.KnowledgeBasesGrpcTransport, - transports.KnowledgeBasesGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_knowledge_bases_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_participants.py b/tests/unit/gapic/dialogflow_v2beta1/test_participants.py index 8a027f42c..5c314c799 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_participants.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_participants.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.dialogflow_v2beta1.services.participants import ParticipantsClient from google.cloud.dialogflow_v2beta1.services.participants import pagers from google.cloud.dialogflow_v2beta1.services.participants import transports -from google.cloud.dialogflow_v2beta1.services.participants.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import agent from google.cloud.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import context @@ -57,20 +53,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" @@ -218,7 +200,7 @@ def test_participants_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, @@ -235,7 +217,7 @@ def test_participants_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, @@ -252,7 +234,7 @@ def test_participants_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, @@ -281,7 +263,7 @@ def test_participants_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, @@ -338,7 +320,7 @@ def test_participants_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 @@ -380,7 +362,7 @@ def test_participants_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, @@ -402,7 +384,7 @@ def test_participants_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, @@ -433,7 +415,7 @@ def test_participants_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, @@ -464,7 +446,7 @@ def test_participants_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", @@ -2931,7 +2913,6 @@ def test_participants_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_participants_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2955,29 +2936,6 @@ def test_participants_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_participants_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.dialogflow_v2beta1.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ParticipantsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_participants_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( @@ -2989,7 +2947,6 @@ def test_participants_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_participants_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3005,21 +2962,6 @@ def test_participants_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_participants_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) - ParticipantsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3027,7 +2969,6 @@ def test_participants_auth_adc_old_google_auth(): transports.ParticipantsGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_participants_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3044,29 +2985,6 @@ def test_participants_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.ParticipantsGrpcTransport, - transports.ParticipantsGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_participants_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py b/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py index 33f0c8228..99310feae 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,9 +39,6 @@ ) from google.cloud.dialogflow_v2beta1.services.session_entity_types import pagers from google.cloud.dialogflow_v2beta1.services.session_entity_types import transports -from google.cloud.dialogflow_v2beta1.services.session_entity_types.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import entity_type from google.cloud.dialogflow_v2beta1.types import session_entity_type from google.cloud.dialogflow_v2beta1.types import ( @@ -53,20 +49,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_session_entity_types_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_session_entity_types_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_session_entity_types_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_session_entity_types_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, @@ -356,7 +338,7 @@ def test_session_entity_types_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 @@ -398,7 +380,7 @@ def test_session_entity_types_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, @@ -420,7 +402,7 @@ def test_session_entity_types_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, @@ -451,7 +433,7 @@ def test_session_entity_types_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, @@ -482,7 +464,7 @@ def test_session_entity_types_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", @@ -2018,7 +2000,6 @@ def test_session_entity_types_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_session_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2042,29 +2023,6 @@ def test_session_entity_types_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_session_entity_types_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.dialogflow_v2beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SessionEntityTypesTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_session_entity_types_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( @@ -2076,7 +2034,6 @@ def test_session_entity_types_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_session_entity_types_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2092,21 +2049,6 @@ def test_session_entity_types_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_session_entity_types_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) - SessionEntityTypesClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2114,7 +2056,6 @@ def test_session_entity_types_auth_adc_old_google_auth(): transports.SessionEntityTypesGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_session_entity_types_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2131,29 +2072,6 @@ def test_session_entity_types_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SessionEntityTypesGrpcTransport, - transports.SessionEntityTypesGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_session_entity_types_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py b/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py index f002b0020..02449a7d4 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -35,9 +34,6 @@ from google.cloud.dialogflow_v2beta1.services.sessions import SessionsAsyncClient from google.cloud.dialogflow_v2beta1.services.sessions import SessionsClient from google.cloud.dialogflow_v2beta1.services.sessions import transports -from google.cloud.dialogflow_v2beta1.services.sessions.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import agent from google.cloud.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import context @@ -53,20 +49,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" @@ -206,7 +188,7 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -223,7 +205,7 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -240,7 +222,7 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -269,7 +251,7 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -326,7 +308,7 @@ def test_sessions_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 @@ -368,7 +350,7 @@ def test_sessions_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, @@ -390,7 +372,7 @@ def test_sessions_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, @@ -417,7 +399,7 @@ def test_sessions_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, @@ -444,7 +426,7 @@ def test_sessions_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", @@ -891,7 +873,6 @@ def test_sessions_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_sessions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -915,29 +896,6 @@ def test_sessions_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_sessions_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.dialogflow_v2beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SessionsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_sessions_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( @@ -949,7 +907,6 @@ def test_sessions_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_sessions_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -965,26 +922,10 @@ def test_sessions_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_sessions_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) - SessionsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.SessionsGrpcTransport, transports.SessionsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_sessions_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1001,26 +942,6 @@ def test_sessions_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.SessionsGrpcTransport, transports.SessionsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_sessions_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_versions.py b/tests/unit/gapic/dialogflow_v2beta1/test_versions.py index 66c0dbfc9..a5679cb74 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_versions.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_versions.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.dialogflow_v2beta1.services.versions import VersionsClient from google.cloud.dialogflow_v2beta1.services.versions import pagers from google.cloud.dialogflow_v2beta1.services.versions import transports -from google.cloud.dialogflow_v2beta1.services.versions.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dialogflow_v2beta1.types import version from google.cloud.dialogflow_v2beta1.types import version as gcd_version from google.oauth2 import service_account @@ -47,20 +43,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" @@ -200,7 +182,7 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -217,7 +199,7 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -234,7 +216,7 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -263,7 +245,7 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -320,7 +302,7 @@ def test_versions_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 @@ -362,7 +344,7 @@ def test_versions_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, @@ -384,7 +366,7 @@ def test_versions_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, @@ -411,7 +393,7 @@ def test_versions_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, @@ -438,7 +420,7 @@ def test_versions_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", @@ -1733,7 +1715,6 @@ def test_versions_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_versions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1757,29 +1738,6 @@ def test_versions_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_versions_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.dialogflow_v2beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.VersionsTransport( - 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/dialogflow", - ), - quota_project_id="octopus", - ) - - def test_versions_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( @@ -1791,7 +1749,6 @@ def test_versions_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_versions_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1807,26 +1764,10 @@ def test_versions_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_versions_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) - VersionsClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/dialogflow", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.VersionsGrpcTransport, transports.VersionsGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_versions_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1843,26 +1784,6 @@ def test_versions_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.VersionsGrpcTransport, transports.VersionsGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_versions_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/dialogflow", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [