diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 7519fa3a2..ff5126c18 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7 + digest: sha256:dfa9b663b32de8b5b327e32c1da665a80de48876558dd58091d8160c60ad7355 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b26afefdc..62aced936 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,5 +8,5 @@ # @googleapis/yoshi-python @googleapis/cdpe-cloudai are the default owners for changes in this repo * @googleapis/yoshi-python @googleapis/cdpe-cloudai -# @googleapis/python-samples-owners @googleapis/cdpe-cloudai are the default owners for samples changes -/samples/ @googleapis/python-samples-owners @googleapis/cdpe-cloudai +# @googleapis/python-samples-reviewers @googleapis/cdpe-cloudai are the default owners for samples changes +/samples/ @googleapis/python-samples-reviewers @googleapis/cdpe-cloudai diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad059..466597e5b 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: python +handleGHRelease: true diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 000000000..d4ca94189 --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true diff --git a/.repo-metadata.json b/.repo-metadata.json index b8b9fc04a..6feb59ffc 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -2,9 +2,9 @@ "name": "dialogflow", "name_pretty": "Dialogflow", "product_documentation": "https://www.dialogflow.com/", - "client_documentation": "https://googleapis.dev/python/dialogflow/latest", + "client_documentation": "https://cloud.google.com/python/docs/reference/dialogflow/latest", "issue_tracker": "https://issuetracker.google.com/savedsearches/5300385", - "release_level": "ga", + "release_level": "stable", "language": "python", "library_type": "GAPIC_AUTO", "repo": "googleapis/python-dialogflow", @@ -12,5 +12,6 @@ "api_id": "dialogflow.googleapis.com", "requires_billing": true, "default_version": "v2", - "codeowner_team": "@googleapis/cdpe-cloudai" + "codeowner_team": "@googleapis/cdpe-cloudai", + "api_shortname": "dialogflow" } diff --git a/CHANGELOG.md b/CHANGELOG.md index dc51f8285..fcf3b4467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,22 @@ [1]: https://pypi.org/project/dialogflow/#history +## [2.11.0](https://github.com/googleapis/python-dialogflow/compare/v2.10.0...v2.11.0) (2022-01-13) + + +### Features + +* support document metadata filter in article suggestion ([#442](https://github.com/googleapis/python-dialogflow/issues/442)) ([6f615f9](https://github.com/googleapis/python-dialogflow/commit/6f615f997dfa4e8e4d3e734a94ee0c81012a5a6d)) +* **v2:** added export documentation method ([#449](https://github.com/googleapis/python-dialogflow/issues/449)) ([a43d1e9](https://github.com/googleapis/python-dialogflow/commit/a43d1e92c86c87645c73a91a5c1593412bd3018d)) +* **v2:** added filter in list documentations request ([a43d1e9](https://github.com/googleapis/python-dialogflow/commit/a43d1e92c86c87645c73a91a5c1593412bd3018d)) +* **v2:** added filter in list knowledge bases request ([a43d1e9](https://github.com/googleapis/python-dialogflow/commit/a43d1e92c86c87645c73a91a5c1593412bd3018d)) +* **v2:** added option to apply partial update to the smart messaging allowlist in reload document request ([a43d1e9](https://github.com/googleapis/python-dialogflow/commit/a43d1e92c86c87645c73a91a5c1593412bd3018d)) +* **v2:** added option to import custom metadata from Google Cloud Storage in reload document request ([a43d1e9](https://github.com/googleapis/python-dialogflow/commit/a43d1e92c86c87645c73a91a5c1593412bd3018d)) +* **v2beta1:** add support for knowledge_base in knowledge operation metadata ([0f60629](https://github.com/googleapis/python-dialogflow/commit/0f606297c75cdf601fc8ea1c1906fe6ac4939c43)) +* **v2beta1:** added option to configure the number of sentences in the suggestion context ([#453](https://github.com/googleapis/python-dialogflow/issues/453)) ([e48ea00](https://github.com/googleapis/python-dialogflow/commit/e48ea001b7c8a4a5c1fe4b162bad49ea397458e9)) +* **v2beta1:** removed OPTIONAL for speech model variant ([#448](https://github.com/googleapis/python-dialogflow/issues/448)) ([0f60629](https://github.com/googleapis/python-dialogflow/commit/0f606297c75cdf601fc8ea1c1906fe6ac4939c43)) +* **v2:** removed OPTIONAL for speech model variant ([#447](https://github.com/googleapis/python-dialogflow/issues/447)) ([56efd10](https://github.com/googleapis/python-dialogflow/commit/56efd1047f146bab52d59db29b04211326118cf3)) + ## [2.10.0](https://www.github.com/googleapis/python-dialogflow/compare/v2.9.1...v2.10.0) (2021-11-12) diff --git a/README.rst b/README.rst index a9ac122b5..2391189b0 100644 --- a/README.rst +++ b/README.rst @@ -9,7 +9,7 @@ Dialogflow: Python Client developers to design and integrate conversational user interfaces into mobile apps, web applications, devices, and bots. -* `Dialogflow ES Python Client API Reference `_ +* `Dialogflow ES Python Client API Reference `_ * `Dialogflow ES Documentation `_ Read more about the client libraries for Cloud APIs, including the older @@ -65,7 +65,7 @@ The last version of this library compatible with Python 2.7 is dialogflow==1.1.0 Usage ----- -View `usage documentation `_. +View `usage documentation `_. Versioning diff --git a/google/cloud/dialogflow/__init__.py b/google/cloud/dialogflow/__init__.py index cfb1e351a..92db3a1ca 100644 --- a/google/cloud/dialogflow/__init__.py +++ b/google/cloud/dialogflow/__init__.py @@ -159,6 +159,7 @@ from google.cloud.dialogflow_v2.types.document import CreateDocumentRequest from google.cloud.dialogflow_v2.types.document import DeleteDocumentRequest from google.cloud.dialogflow_v2.types.document import Document +from google.cloud.dialogflow_v2.types.document import ExportDocumentRequest from google.cloud.dialogflow_v2.types.document import GetDocumentRequest from google.cloud.dialogflow_v2.types.document import KnowledgeOperationMetadata from google.cloud.dialogflow_v2.types.document import ListDocumentsRequest @@ -192,6 +193,7 @@ from google.cloud.dialogflow_v2.types.fulfillment import Fulfillment from google.cloud.dialogflow_v2.types.fulfillment import GetFulfillmentRequest from google.cloud.dialogflow_v2.types.fulfillment import UpdateFulfillmentRequest +from google.cloud.dialogflow_v2.types.gcs import GcsDestination from google.cloud.dialogflow_v2.types.human_agent_assistant_event import ( HumanAgentAssistantEvent, ) @@ -376,6 +378,7 @@ "CreateDocumentRequest", "DeleteDocumentRequest", "Document", + "ExportDocumentRequest", "GetDocumentRequest", "KnowledgeOperationMetadata", "ListDocumentsRequest", @@ -409,6 +412,7 @@ "Fulfillment", "GetFulfillmentRequest", "UpdateFulfillmentRequest", + "GcsDestination", "HumanAgentAssistantEvent", "BatchDeleteIntentsRequest", "BatchUpdateIntentsRequest", diff --git a/google/cloud/dialogflow_v2/__init__.py b/google/cloud/dialogflow_v2/__init__.py index 5f07b5ef4..da9113931 100644 --- a/google/cloud/dialogflow_v2/__init__.py +++ b/google/cloud/dialogflow_v2/__init__.py @@ -109,6 +109,7 @@ from .types.document import CreateDocumentRequest from .types.document import DeleteDocumentRequest from .types.document import Document +from .types.document import ExportDocumentRequest from .types.document import GetDocumentRequest from .types.document import KnowledgeOperationMetadata from .types.document import ListDocumentsRequest @@ -142,6 +143,7 @@ from .types.fulfillment import Fulfillment from .types.fulfillment import GetFulfillmentRequest from .types.fulfillment import UpdateFulfillmentRequest +from .types.gcs import GcsDestination from .types.human_agent_assistant_event import HumanAgentAssistantEvent from .types.intent import BatchDeleteIntentsRequest from .types.intent import BatchUpdateIntentsRequest @@ -302,9 +304,11 @@ "EventInput", "ExportAgentRequest", "ExportAgentResponse", + "ExportDocumentRequest", "FaqAnswer", "Fulfillment", "FulfillmentsClient", + "GcsDestination", "GetAgentRequest", "GetContextRequest", "GetConversationProfileRequest", diff --git a/google/cloud/dialogflow_v2/gapic_metadata.json b/google/cloud/dialogflow_v2/gapic_metadata.json index b73c53792..bedcfbda7 100644 --- a/google/cloud/dialogflow_v2/gapic_metadata.json +++ b/google/cloud/dialogflow_v2/gapic_metadata.json @@ -360,6 +360,11 @@ "delete_document" ] }, + "ExportDocument": { + "methods": [ + "export_document" + ] + }, "GetDocument": { "methods": [ "get_document" @@ -395,6 +400,11 @@ "delete_document" ] }, + "ExportDocument": { + "methods": [ + "export_document" + ] + }, "GetDocument": { "methods": [ "get_document" diff --git a/google/cloud/dialogflow_v2/services/agents/transports/base.py b/google/cloud/dialogflow_v2/services/agents/transports/base.py index 3438f6fda..e7727b244 100644 --- a/google/cloud/dialogflow_v2/services/agents/transports/base.py +++ b/google/cloud/dialogflow_v2/services/agents/transports/base.py @@ -109,7 +109,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 36b297434..514a003e3 100644 --- a/google/cloud/dialogflow_v2/services/answer_records/transports/base.py +++ b/google/cloud/dialogflow_v2/services/answer_records/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/contexts/transports/base.py b/google/cloud/dialogflow_v2/services/contexts/transports/base.py index f8f6bbee6..c2f65b08e 100644 --- a/google/cloud/dialogflow_v2/services/contexts/transports/base.py +++ b/google/cloud/dialogflow_v2/services/contexts/transports/base.py @@ -106,7 +106,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 94757a92c..f4d8b24e8 100644 --- a/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py +++ b/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py @@ -108,7 +108,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/conversations/transports/base.py b/google/cloud/dialogflow_v2/services/conversations/transports/base.py index 4d72750f6..03f7bcee4 100644 --- a/google/cloud/dialogflow_v2/services/conversations/transports/base.py +++ b/google/cloud/dialogflow_v2/services/conversations/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/documents/async_client.py b/google/cloud/dialogflow_v2/services/documents/async_client.py index 64abeb23e..bea14f9be 100644 --- a/google/cloud/dialogflow_v2/services/documents/async_client.py +++ b/google/cloud/dialogflow_v2/services/documents/async_client.py @@ -766,6 +766,84 @@ async def reload_document( # Done; return the response. return response + async def export_document( + self, + request: Union[document.ExportDocumentRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Exports a smart messaging candidate document into the specified + destination. + + This method is a `long-running + operation `__. + The returned ``Operation`` type has the following + method-specific fields: + + - ``metadata``: + [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata] + - ``response``: [Document][google.cloud.dialogflow.v2.Document] + + Args: + request (Union[google.cloud.dialogflow_v2.types.ExportDocumentRequest, dict]): + The request object. Request message for + [Documents.ExportDocument][google.cloud.dialogflow.v2.Documents.ExportDocument]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.dialogflow_v2.types.Document` A + knowledge document to be used by a + [KnowledgeBase][google.cloud.dialogflow.v2.KnowledgeBase]. + + For more information, see the [knowledge base + guide](\ https://cloud.google.com/dialogflow/docs/how/knowledge-bases). + + Note: The projects.agent.knowledgeBases.documents + resource is deprecated; only use + projects.knowledgeBases.documents. + + """ + # Create or coerce a protobuf request object. + request = document.ExportDocumentRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.export_document, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + document.Document, + metadata_type=document.KnowledgeOperationMetadata, + ) + + # Done; return the response. + return response + async def __aenter__(self): return self diff --git a/google/cloud/dialogflow_v2/services/documents/client.py b/google/cloud/dialogflow_v2/services/documents/client.py index 74044633b..904e11a64 100644 --- a/google/cloud/dialogflow_v2/services/documents/client.py +++ b/google/cloud/dialogflow_v2/services/documents/client.py @@ -962,6 +962,85 @@ def reload_document( # Done; return the response. return response + def export_document( + self, + request: Union[document.ExportDocumentRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Exports a smart messaging candidate document into the specified + destination. + + This method is a `long-running + operation `__. + The returned ``Operation`` type has the following + method-specific fields: + + - ``metadata``: + [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata] + - ``response``: [Document][google.cloud.dialogflow.v2.Document] + + Args: + request (Union[google.cloud.dialogflow_v2.types.ExportDocumentRequest, dict]): + The request object. Request message for + [Documents.ExportDocument][google.cloud.dialogflow.v2.Documents.ExportDocument]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.dialogflow_v2.types.Document` A + knowledge document to be used by a + [KnowledgeBase][google.cloud.dialogflow.v2.KnowledgeBase]. + + For more information, see the [knowledge base + guide](\ https://cloud.google.com/dialogflow/docs/how/knowledge-bases). + + Note: The projects.agent.knowledgeBases.documents + resource is deprecated; only use + projects.knowledgeBases.documents. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a document.ExportDocumentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document.ExportDocumentRequest): + request = document.ExportDocumentRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.export_document] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + document.Document, + metadata_type=document.KnowledgeOperationMetadata, + ) + + # Done; return the response. + return response + def __enter__(self): return self diff --git a/google/cloud/dialogflow_v2/services/documents/transports/base.py b/google/cloud/dialogflow_v2/services/documents/transports/base.py index 1ee3d7889..3c6acf37e 100644 --- a/google/cloud/dialogflow_v2/services/documents/transports/base.py +++ b/google/cloud/dialogflow_v2/services/documents/transports/base.py @@ -107,7 +107,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id @@ -145,6 +144,9 @@ def _prep_wrapped_messages(self, client_info): self.reload_document: gapic_v1.method.wrap_method( self.reload_document, default_timeout=None, client_info=client_info, ), + self.export_document: gapic_v1.method.wrap_method( + self.export_document, default_timeout=None, client_info=client_info, + ), } def close(self): @@ -217,5 +219,14 @@ def reload_document( ]: raise NotImplementedError() + @property + def export_document( + self, + ) -> Callable[ + [document.ExportDocumentRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + __all__ = ("DocumentsTransport",) diff --git a/google/cloud/dialogflow_v2/services/documents/transports/grpc.py b/google/cloud/dialogflow_v2/services/documents/transports/grpc.py index c74e563b5..e860da053 100644 --- a/google/cloud/dialogflow_v2/services/documents/transports/grpc.py +++ b/google/cloud/dialogflow_v2/services/documents/transports/grpc.py @@ -445,6 +445,42 @@ def reload_document( ) return self._stubs["reload_document"] + @property + def export_document( + self, + ) -> Callable[[document.ExportDocumentRequest], operations_pb2.Operation]: + r"""Return a callable for the export document method over gRPC. + + Exports a smart messaging candidate document into the specified + destination. + + This method is a `long-running + operation `__. + The returned ``Operation`` type has the following + method-specific fields: + + - ``metadata``: + [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata] + - ``response``: [Document][google.cloud.dialogflow.v2.Document] + + Returns: + Callable[[~.ExportDocumentRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "export_document" not in self._stubs: + self._stubs["export_document"] = self.grpc_channel.unary_unary( + "/google.cloud.dialogflow.v2.Documents/ExportDocument", + request_serializer=document.ExportDocumentRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["export_document"] + def close(self): self.grpc_channel.close() 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 0d9de9d1e..5b8bfc662 100644 --- a/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py +++ b/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py @@ -459,6 +459,44 @@ def reload_document( ) return self._stubs["reload_document"] + @property + def export_document( + self, + ) -> Callable[ + [document.ExportDocumentRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the export document method over gRPC. + + Exports a smart messaging candidate document into the specified + destination. + + This method is a `long-running + operation `__. + The returned ``Operation`` type has the following + method-specific fields: + + - ``metadata``: + [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata] + - ``response``: [Document][google.cloud.dialogflow.v2.Document] + + Returns: + Callable[[~.ExportDocumentRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "export_document" not in self._stubs: + self._stubs["export_document"] = self.grpc_channel.unary_unary( + "/google.cloud.dialogflow.v2.Documents/ExportDocument", + request_serializer=document.ExportDocumentRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["export_document"] + def close(self): return self.grpc_channel.close() 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 6795abe9f..51de4497c 100644 --- a/google/cloud/dialogflow_v2/services/entity_types/transports/base.py +++ b/google/cloud/dialogflow_v2/services/entity_types/transports/base.py @@ -108,7 +108,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/environments/transports/base.py b/google/cloud/dialogflow_v2/services/environments/transports/base.py index cf3fd7fe4..da41534fa 100644 --- a/google/cloud/dialogflow_v2/services/environments/transports/base.py +++ b/google/cloud/dialogflow_v2/services/environments/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py b/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py index b4e627411..7ab589d60 100644 --- a/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py +++ b/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/intents/transports/base.py b/google/cloud/dialogflow_v2/services/intents/transports/base.py index b9c2be736..ef9862467 100644 --- a/google/cloud/dialogflow_v2/services/intents/transports/base.py +++ b/google/cloud/dialogflow_v2/services/intents/transports/base.py @@ -108,7 +108,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 05e811e6b..a5efd1540 100644 --- a/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py +++ b/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py @@ -106,7 +106,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/participants/async_client.py b/google/cloud/dialogflow_v2/services/participants/async_client.py index 0b1f43a3b..fd6c31e7b 100644 --- a/google/cloud/dialogflow_v2/services/participants/async_client.py +++ b/google/cloud/dialogflow_v2/services/participants/async_client.py @@ -361,7 +361,7 @@ async def list_participants( Returns: google.cloud.dialogflow_v2.services.participants.pagers.ListParticipantsAsyncPager: The response message for - [Participants.ListParticipants][google.cloud.dialogflow.v2.Participants.ListParticipants]. + [Participants.ListParticipants][google.cloud.dialogflow.v2.Participants.ListParticipants]. Iterating over this object will yield results and resolve additional pages automatically. @@ -542,7 +542,7 @@ async def analyze_content( Returns: google.cloud.dialogflow_v2.types.AnalyzeContentResponse: The response message for - [Participants.AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent]. + [Participants.AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent]. """ # Create or coerce a protobuf request object. @@ -630,7 +630,7 @@ async def suggest_articles( Returns: google.cloud.dialogflow_v2.types.SuggestArticlesResponse: The response message for - [Participants.SuggestArticles][google.cloud.dialogflow.v2.Participants.SuggestArticles]. + [Participants.SuggestArticles][google.cloud.dialogflow.v2.Participants.SuggestArticles]. """ # Create or coerce a protobuf request object. @@ -703,7 +703,7 @@ async def suggest_faq_answers( Returns: google.cloud.dialogflow_v2.types.SuggestFaqAnswersResponse: The request message for - [Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2.Participants.SuggestFaqAnswers]. + [Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2.Participants.SuggestFaqAnswers]. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/dialogflow_v2/services/participants/client.py b/google/cloud/dialogflow_v2/services/participants/client.py index cf3ab93ed..9b273011a 100644 --- a/google/cloud/dialogflow_v2/services/participants/client.py +++ b/google/cloud/dialogflow_v2/services/participants/client.py @@ -606,7 +606,7 @@ def list_participants( Returns: google.cloud.dialogflow_v2.services.participants.pagers.ListParticipantsPager: The response message for - [Participants.ListParticipants][google.cloud.dialogflow.v2.Participants.ListParticipants]. + [Participants.ListParticipants][google.cloud.dialogflow.v2.Participants.ListParticipants]. Iterating over this object will yield results and resolve additional pages automatically. @@ -787,7 +787,7 @@ def analyze_content( Returns: google.cloud.dialogflow_v2.types.AnalyzeContentResponse: The response message for - [Participants.AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent]. + [Participants.AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent]. """ # Create or coerce a protobuf request object. @@ -866,7 +866,7 @@ def suggest_articles( Returns: google.cloud.dialogflow_v2.types.SuggestArticlesResponse: The response message for - [Participants.SuggestArticles][google.cloud.dialogflow.v2.Participants.SuggestArticles]. + [Participants.SuggestArticles][google.cloud.dialogflow.v2.Participants.SuggestArticles]. """ # Create or coerce a protobuf request object. @@ -939,7 +939,7 @@ def suggest_faq_answers( Returns: google.cloud.dialogflow_v2.types.SuggestFaqAnswersResponse: The request message for - [Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2.Participants.SuggestFaqAnswers]. + [Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2.Participants.SuggestFaqAnswers]. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/dialogflow_v2/services/participants/transports/base.py b/google/cloud/dialogflow_v2/services/participants/transports/base.py index da5f6cec0..f5707b3b4 100644 --- a/google/cloud/dialogflow_v2/services/participants/transports/base.py +++ b/google/cloud/dialogflow_v2/services/participants/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 c6371b950..431634dde 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 @@ -108,7 +108,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/sessions/transports/base.py b/google/cloud/dialogflow_v2/services/sessions/transports/base.py index 51a759243..f9ac3926f 100644 --- a/google/cloud/dialogflow_v2/services/sessions/transports/base.py +++ b/google/cloud/dialogflow_v2/services/sessions/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/services/versions/transports/base.py b/google/cloud/dialogflow_v2/services/versions/transports/base.py index bb2a24d9b..032c583c2 100644 --- a/google/cloud/dialogflow_v2/services/versions/transports/base.py +++ b/google/cloud/dialogflow_v2/services/versions/transports/base.py @@ -106,7 +106,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2/types/__init__.py b/google/cloud/dialogflow_v2/types/__init__.py index b8a99fdb8..6c9f39b7d 100644 --- a/google/cloud/dialogflow_v2/types/__init__.py +++ b/google/cloud/dialogflow_v2/types/__init__.py @@ -90,6 +90,7 @@ CreateDocumentRequest, DeleteDocumentRequest, Document, + ExportDocumentRequest, GetDocumentRequest, KnowledgeOperationMetadata, ListDocumentsRequest, @@ -130,6 +131,7 @@ GetFulfillmentRequest, UpdateFulfillmentRequest, ) +from .gcs import GcsDestination from .human_agent_assistant_event import HumanAgentAssistantEvent from .intent import ( BatchDeleteIntentsRequest, @@ -286,6 +288,7 @@ "CreateDocumentRequest", "DeleteDocumentRequest", "Document", + "ExportDocumentRequest", "GetDocumentRequest", "KnowledgeOperationMetadata", "ListDocumentsRequest", @@ -319,6 +322,7 @@ "Fulfillment", "GetFulfillmentRequest", "UpdateFulfillmentRequest", + "GcsDestination", "HumanAgentAssistantEvent", "BatchDeleteIntentsRequest", "BatchUpdateIntentsRequest", diff --git a/google/cloud/dialogflow_v2/types/audio_config.py b/google/cloud/dialogflow_v2/types/audio_config.py index d3204c5ef..410a95640 100644 --- a/google/cloud/dialogflow_v2/types/audio_config.py +++ b/google/cloud/dialogflow_v2/types/audio_config.py @@ -364,13 +364,15 @@ class SpeechToTextConfig(proto.Message): Attributes: speech_model_variant (google.cloud.dialogflow_v2.types.SpeechModelVariant): - Optional. The speech model used in speech to text. + The speech model used in speech to text. ``SPEECH_MODEL_VARIANT_UNSPECIFIED``, ``USE_BEST_AVAILABLE`` will be treated as ``USE_ENHANCED``. It can be overridden in [AnalyzeContentRequest][google.cloud.dialogflow.v2.AnalyzeContentRequest] and [StreamingAnalyzeContentRequest][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest] - request. + request. If enhanced model variant is specified and an + enhanced version of the specified model for the language + does not exist, then it would emit an error. """ speech_model_variant = proto.Field(proto.ENUM, number=1, enum="SpeechModelVariant",) diff --git a/google/cloud/dialogflow_v2/types/document.py b/google/cloud/dialogflow_v2/types/document.py index 7c82e11b3..c36fed090 100644 --- a/google/cloud/dialogflow_v2/types/document.py +++ b/google/cloud/dialogflow_v2/types/document.py @@ -15,6 +15,7 @@ # import proto # type: ignore +from google.cloud.dialogflow_v2.types import gcs from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore @@ -31,6 +32,7 @@ "DeleteDocumentRequest", "UpdateDocumentRequest", "ReloadDocumentRequest", + "ExportDocumentRequest", "KnowledgeOperationMetadata", }, ) @@ -180,11 +182,36 @@ class ListDocumentsRequest(proto.Message): page_token (str): The next_page_token value returned from a previous list request. + filter (str): + The filter expression used to filter documents returned by + the list method. The expression has the following syntax: + + [AND ] ... + + The following fields and operators are supported: + + - knowledge_types with has(:) operator + - display_name with has(:) operator + - state with equals(=) operator + + Examples: + + - "knowledge_types:FAQ" matches documents with FAQ + knowledge type. + - "display_name:customer" matches documents whose display + name contains "customer". + - "state=ACTIVE" matches documents with ACTIVE state. + - "knowledge_types:FAQ AND state=ACTIVE" matches all active + FAQ documents. + + For more information about filtering, see `API + Filtering `__. """ parent = proto.Field(proto.STRING, number=1,) page_size = proto.Field(proto.INT32, number=2,) page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) class ListDocumentsResponse(proto.Message): @@ -276,10 +303,52 @@ class ReloadDocumentRequest(proto.Message): must have the form ``gs:///``. This field is a member of `oneof`_ ``source``. + import_gcs_custom_metadata (bool): + Optional. Whether to import custom metadata + from Google Cloud Storage. Only valid when the + document source is Google Cloud Storage URI. + smart_messaging_partial_update (bool): + Optional. When enabled, the reload request is + to apply partial update to the smart messaging + allowlist. """ name = proto.Field(proto.STRING, number=1,) content_uri = proto.Field(proto.STRING, number=3, oneof="source",) + import_gcs_custom_metadata = proto.Field(proto.BOOL, number=4,) + smart_messaging_partial_update = proto.Field(proto.BOOL, number=5,) + + +class ExportDocumentRequest(proto.Message): + r"""Request message for + [Documents.ExportDocument][google.cloud.dialogflow.v2.Documents.ExportDocument]. + + + .. _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 export. Format: + ``projects//locations//knowledgeBases//documents/``. + gcs_destination (google.cloud.dialogflow_v2.types.GcsDestination): + Cloud Storage file path to export the + document. + + This field is a member of `oneof`_ ``destination``. + export_full_content (bool): + When enabled, export the full content of the + document including empirical probability. + smart_messaging_partial_update (bool): + When enabled, export the smart messaging + allowlist document for partial update. + """ + + name = proto.Field(proto.STRING, number=1,) + gcs_destination = proto.Field( + proto.MESSAGE, number=2, oneof="destination", message=gcs.GcsDestination, + ) + export_full_content = proto.Field(proto.BOOL, number=3,) + smart_messaging_partial_update = proto.Field(proto.BOOL, number=5,) class KnowledgeOperationMetadata(proto.Message): diff --git a/google/cloud/dialogflow_v2/types/gcs.py b/google/cloud/dialogflow_v2/types/gcs.py index 8076c8a39..5e4f7c00f 100644 --- a/google/cloud/dialogflow_v2/types/gcs.py +++ b/google/cloud/dialogflow_v2/types/gcs.py @@ -13,9 +13,28 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import proto # type: ignore -__protobuf__ = proto.module(package="google.cloud.dialogflow.v2", manifest={},) +__protobuf__ = proto.module( + package="google.cloud.dialogflow.v2", manifest={"GcsDestination",}, +) + + +class GcsDestination(proto.Message): + r"""Google Cloud Storage location for the output. + + Attributes: + uri (str): + The Google Cloud Storage URIs for the output. + A URI is of the form: + gs://bucket/object-prefix-or-name + Whether a prefix or name is used depends on the + use case. The requesting user must have "write- + permission" to the bucket. + """ + + uri = proto.Field(proto.STRING, number=1,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/dialogflow_v2/types/knowledge_base.py b/google/cloud/dialogflow_v2/types/knowledge_base.py index c26345d64..df6af1645 100644 --- a/google/cloud/dialogflow_v2/types/knowledge_base.py +++ b/google/cloud/dialogflow_v2/types/knowledge_base.py @@ -81,11 +81,41 @@ class ListKnowledgeBasesRequest(proto.Message): page_token (str): The next_page_token value returned from a previous list request. + filter (str): + The filter expression used to filter knowledge bases + returned by the list method. The expression has the + following syntax: + + [AND ] ... + + The following fields and operators are supported: + + - display_name with has(:) operator + - language_code with equals(=) operator + + Examples: + + - 'language_code=en-us' matches knowledge bases with en-us + language code. + - 'display_name:articles' matches knowledge bases whose + display name contains "articles". + - 'display_name:"Best Articles"' matches knowledge bases + whose display name contains "Best Articles". + - 'language_code=en-gb AND display_name=articles' matches + all knowledge bases whose display name contains + "articles" and whose language code is "en-gb". + + Note: An empty filter string (i.e. "") is a no-op and will + result in no filtering. + + For more information about filtering, see `API + Filtering `__. """ parent = proto.Field(proto.STRING, number=1,) page_size = proto.Field(proto.INT32, number=2,) page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) class ListKnowledgeBasesResponse(proto.Message): diff --git a/google/cloud/dialogflow_v2/types/participant.py b/google/cloud/dialogflow_v2/types/participant.py index 5b29ba6b2..dcb45a340 100644 --- a/google/cloud/dialogflow_v2/types/participant.py +++ b/google/cloud/dialogflow_v2/types/participant.py @@ -729,8 +729,17 @@ class AssistQueryParameters(proto.Message): comma. For example, filters to match all documents that have 'US' or 'CA' in their market metadata values and 'agent' in their user metadata values will be - documents_metadata_filters { key: "market" value: "US,CA" } - documents_metadata_filters { key: "user" value: "agent" } + + :: + + documents_metadata_filters { + key: "market" + value: "US,CA" + } + documents_metadata_filters { + key: "user" + value: "agent" + } """ documents_metadata_filters = proto.MapField(proto.STRING, proto.STRING, number=1,) diff --git a/google/cloud/dialogflow_v2beta1/__init__.py b/google/cloud/dialogflow_v2beta1/__init__.py index a31bffd6d..5c390d8e9 100644 --- a/google/cloud/dialogflow_v2beta1/__init__.py +++ b/google/cloud/dialogflow_v2beta1/__init__.py @@ -177,6 +177,7 @@ from .types.participant import AnalyzeContentResponse from .types.participant import AnnotatedMessagePart from .types.participant import ArticleAnswer +from .types.participant import AssistQueryParameters from .types.participant import AutomatedAgentReply from .types.participant import CompileSuggestionRequest from .types.participant import CompileSuggestionResponse @@ -265,6 +266,7 @@ "AnswerRecord", "AnswerRecordsClient", "ArticleAnswer", + "AssistQueryParameters", "AudioEncoding", "AutomatedAgentConfig", "AutomatedAgentReply", diff --git a/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py b/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py index 0435903ca..5239c1050 100644 --- a/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py @@ -109,7 +109,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 1f05716c4..e6d672be3 100644 --- a/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py b/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py index 6e231f595..000467d5a 100644 --- a/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py @@ -106,7 +106,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 8beb05077..2baa96bb6 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py @@ -108,7 +108,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py b/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py index 608489252..772f62656 100644 --- a/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py b/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py index 8ed597481..9081ec786 100644 --- a/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py @@ -107,7 +107,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 5aef232aa..49fff8629 100644 --- a/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py @@ -108,7 +108,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py b/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py index 8fcbd2e06..c70b2fb6e 100644 --- a/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py b/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py index 1a44230bc..40d6c6f17 100644 --- a/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py b/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py index eb785d2c1..7e8a22366 100644 --- a/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py @@ -108,7 +108,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 bfae48e8f..c714b03dc 100644 --- a/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py @@ -106,7 +106,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/participants/async_client.py b/google/cloud/dialogflow_v2beta1/services/participants/async_client.py index 8f175cf5e..0d1827a0d 100644 --- a/google/cloud/dialogflow_v2beta1/services/participants/async_client.py +++ b/google/cloud/dialogflow_v2beta1/services/participants/async_client.py @@ -52,6 +52,8 @@ class ParticipantsAsyncClient: DEFAULT_ENDPOINT = ParticipantsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ParticipantsClient.DEFAULT_MTLS_ENDPOINT + answer_record_path = staticmethod(ParticipantsClient.answer_record_path) + parse_answer_record_path = staticmethod(ParticipantsClient.parse_answer_record_path) context_path = staticmethod(ParticipantsClient.context_path) parse_context_path = staticmethod(ParticipantsClient.parse_context_path) document_path = staticmethod(ParticipantsClient.document_path) diff --git a/google/cloud/dialogflow_v2beta1/services/participants/client.py b/google/cloud/dialogflow_v2beta1/services/participants/client.py index ba6083695..dae1cd9a6 100644 --- a/google/cloud/dialogflow_v2beta1/services/participants/client.py +++ b/google/cloud/dialogflow_v2beta1/services/participants/client.py @@ -163,6 +163,21 @@ def transport(self) -> ParticipantsTransport: """ return self._transport + @staticmethod + def answer_record_path(project: str, answer_record: str,) -> str: + """Returns a fully-qualified answer_record string.""" + return "projects/{project}/answerRecords/{answer_record}".format( + project=project, answer_record=answer_record, + ) + + @staticmethod + def parse_answer_record_path(path: str) -> Dict[str, str]: + """Parses a answer_record path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/answerRecords/(?P.+?)$", path + ) + return m.groupdict() if m else {} + @staticmethod def context_path(project: str, session: str, context: str,) -> str: """Returns a fully-qualified context string.""" diff --git a/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py b/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py index 3ad6eccbd..dc19b588a 100644 --- a/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id 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 d2afdb66c..132f54ba1 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 @@ -108,7 +108,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py b/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py index 110df02f0..44b487807 100644 --- a/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py b/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py index 97b2c1c0c..a43820974 100644 --- a/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py +++ b/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py @@ -106,7 +106,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/dialogflow_v2beta1/types/__init__.py b/google/cloud/dialogflow_v2beta1/types/__init__.py index efe17b293..c09d039ae 100644 --- a/google/cloud/dialogflow_v2beta1/types/__init__.py +++ b/google/cloud/dialogflow_v2beta1/types/__init__.py @@ -172,6 +172,7 @@ AnalyzeContentResponse, AnnotatedMessagePart, ArticleAnswer, + AssistQueryParameters, AutomatedAgentReply, CompileSuggestionRequest, CompileSuggestionResponse, @@ -377,6 +378,7 @@ "AnalyzeContentResponse", "AnnotatedMessagePart", "ArticleAnswer", + "AssistQueryParameters", "AutomatedAgentReply", "CompileSuggestionRequest", "CompileSuggestionResponse", diff --git a/google/cloud/dialogflow_v2beta1/types/audio_config.py b/google/cloud/dialogflow_v2beta1/types/audio_config.py index e0d0e772e..32e1fd710 100644 --- a/google/cloud/dialogflow_v2beta1/types/audio_config.py +++ b/google/cloud/dialogflow_v2beta1/types/audio_config.py @@ -405,13 +405,15 @@ class SpeechToTextConfig(proto.Message): Attributes: speech_model_variant (google.cloud.dialogflow_v2beta1.types.SpeechModelVariant): - Optional. The speech model used in speech to text. + The speech model used in speech to text. ``SPEECH_MODEL_VARIANT_UNSPECIFIED``, ``USE_BEST_AVAILABLE`` will be treated as ``USE_ENHANCED``. It can be overridden in [AnalyzeContentRequest][google.cloud.dialogflow.v2beta1.AnalyzeContentRequest] and [StreamingAnalyzeContentRequest][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest] - request. + request. If enhanced model variant is specified and an + enhanced version of the specified model for the language + does not exist, then it would emit an error. """ speech_model_variant = proto.Field(proto.ENUM, number=1, enum="SpeechModelVariant",) diff --git a/google/cloud/dialogflow_v2beta1/types/conversation_profile.py b/google/cloud/dialogflow_v2beta1/types/conversation_profile.py index ed80a0635..a77470e5a 100644 --- a/google/cloud/dialogflow_v2beta1/types/conversation_profile.py +++ b/google/cloud/dialogflow_v2beta1/types/conversation_profile.py @@ -213,6 +213,8 @@ class SuggestionFeatureConfig(proto.Message): Configs of query. conversation_model_config (google.cloud.dialogflow_v2beta1.types.HumanAgentAssistantConfig.ConversationModelConfig): Configs of custom conversation model. + conversation_process_config (google.cloud.dialogflow_v2beta1.types.HumanAgentAssistantConfig.ConversationProcessConfig): + Configs for processing conversation. """ suggestion_feature = proto.Field( @@ -234,6 +236,11 @@ class SuggestionFeatureConfig(proto.Message): number=7, message="HumanAgentAssistantConfig.ConversationModelConfig", ) + conversation_process_config = proto.Field( + proto.MESSAGE, + number=8, + message="HumanAgentAssistantConfig.ConversationProcessConfig", + ) class SuggestionConfig(proto.Message): r"""Detail human agent assistant config. @@ -426,6 +433,17 @@ class ConversationModelConfig(proto.Message): model = proto.Field(proto.STRING, number=1,) + class ConversationProcessConfig(proto.Message): + r"""Config to process conversation. + + Attributes: + recent_sentences_count (int): + Number of recent non-small-talk sentences to + use as context for article and FAQ suggestion + """ + + recent_sentences_count = proto.Field(proto.INT32, number=2,) + class MessageAnalysisConfig(proto.Message): r"""Configuration for analyses to run on each conversation message. diff --git a/google/cloud/dialogflow_v2beta1/types/document.py b/google/cloud/dialogflow_v2beta1/types/document.py index e4edae621..89aae8027 100644 --- a/google/cloud/dialogflow_v2beta1/types/document.py +++ b/google/cloud/dialogflow_v2beta1/types/document.py @@ -385,6 +385,9 @@ class KnowledgeOperationMetadata(proto.Message): state (google.cloud.dialogflow_v2beta1.types.KnowledgeOperationMetadata.State): Required. Output only. The current state of this operation. + knowledge_base (str): + The name of the knowledge base interacted + with during the operation. """ class State(proto.Enum): @@ -395,6 +398,7 @@ class State(proto.Enum): DONE = 3 state = proto.Field(proto.ENUM, number=1, enum=State,) + knowledge_base = proto.Field(proto.STRING, number=3,) class ReloadDocumentRequest(proto.Message): diff --git a/google/cloud/dialogflow_v2beta1/types/participant.py b/google/cloud/dialogflow_v2beta1/types/participant.py index b2185dfb9..dfb147c9d 100644 --- a/google/cloud/dialogflow_v2beta1/types/participant.py +++ b/google/cloud/dialogflow_v2beta1/types/participant.py @@ -36,6 +36,7 @@ "OutputAudio", "AutomatedAgentReply", "SuggestionFeature", + "AssistQueryParameters", "AnalyzeContentRequest", "DtmfParameters", "AnalyzeContentResponse", @@ -109,6 +110,27 @@ class Participant(proto.Message): - Dialogflow only accepts a UTF-8 encoded string, e.g., a hex digest of a hash function like SHA-512. - The length of the user id must be <= 256 characters. + documents_metadata_filters (Sequence[google.cloud.dialogflow_v2beta1.types.Participant.DocumentsMetadataFiltersEntry]): + Optional. Key-value filters on the metadata of documents + returned by article suggestion. If specified, article + suggestion only returns suggested documents that match all + filters in their + [Document.metadata][google.cloud.dialogflow.v2beta1.Document.metadata]. + Multiple values for a metadata key should be concatenated by + comma. For example, filters to match all documents that have + 'US' or 'CA' in their market metadata values and 'agent' in + their user metadata values will be + + :: + + documents_metadata_filters { + key: "market" + value: "US,CA" + } + documents_metadata_filters { + key: "user" + value: "agent" + } """ class Role(proto.Enum): @@ -123,6 +145,7 @@ class Role(proto.Enum): name = proto.Field(proto.STRING, number=1,) role = proto.Field(proto.ENUM, number=2, enum=Role,) obfuscated_external_user_id = proto.Field(proto.STRING, number=7,) + documents_metadata_filters = proto.MapField(proto.STRING, proto.STRING, number=8,) class Message(proto.Message): @@ -385,6 +408,35 @@ class Type(proto.Enum): type_ = proto.Field(proto.ENUM, number=1, enum=Type,) +class AssistQueryParameters(proto.Message): + r"""Represents the parameters of human assist query. + + Attributes: + documents_metadata_filters (Sequence[google.cloud.dialogflow_v2beta1.types.AssistQueryParameters.DocumentsMetadataFiltersEntry]): + Key-value filters on the metadata of documents returned by + article suggestion. If specified, article suggestion only + returns suggested documents that match all filters in their + [Document.metadata][google.cloud.dialogflow.v2beta1.Document.metadata]. + Multiple values for a metadata key should be concatenated by + comma. For example, filters to match all documents that have + 'US' or 'CA' in their market metadata values and 'agent' in + their user metadata values will be + + :: + + documents_metadata_filters { + key: "market" + value: "US,CA" + } + documents_metadata_filters { + key: "user" + value: "agent" + } + """ + + documents_metadata_filters = proto.MapField(proto.STRING, proto.STRING, number=1,) + + class AnalyzeContentRequest(proto.Message): r"""The request message for [Participants.AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent]. @@ -419,6 +471,8 @@ class AnalyzeContentRequest(proto.Message): query_params (google.cloud.dialogflow_v2beta1.types.QueryParameters): Parameters for a Dialogflow virtual-agent query. + assist_query_params (google.cloud.dialogflow_v2beta1.types.AssistQueryParameters): + Parameters for a human assist query. message_send_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The send time of the message from end user or human agent's perspective. It is @@ -456,6 +510,9 @@ class AnalyzeContentRequest(proto.Message): query_params = proto.Field( proto.MESSAGE, number=9, message=session.QueryParameters, ) + assist_query_params = proto.Field( + proto.MESSAGE, number=14, message="AssistQueryParameters", + ) message_send_time = proto.Field( proto.MESSAGE, number=10, message=timestamp_pb2.Timestamp, ) @@ -756,11 +813,17 @@ class SuggestArticlesRequest(proto.Message): [latest_message][google.cloud.dialogflow.v2beta1.SuggestArticlesRequest.latest_message] to use as context when compiling the suggestion. By default 20 and at most 50. + assist_query_params (google.cloud.dialogflow_v2beta1.types.AssistQueryParameters): + Optional. Parameters for a human assist + query. """ parent = proto.Field(proto.STRING, number=1,) latest_message = proto.Field(proto.STRING, number=2,) context_size = proto.Field(proto.INT32, number=3,) + assist_query_params = proto.Field( + proto.MESSAGE, number=4, message="AssistQueryParameters", + ) class SuggestArticlesResponse(proto.Message): @@ -813,11 +876,17 @@ class SuggestFaqAnswersRequest(proto.Message): Optional. Max number of messages prior to and including [latest_message] to use as context when compiling the suggestion. By default 20 and at most 50. + assist_query_params (google.cloud.dialogflow_v2beta1.types.AssistQueryParameters): + Optional. Parameters for a human assist + query. """ parent = proto.Field(proto.STRING, number=1,) latest_message = proto.Field(proto.STRING, number=2,) context_size = proto.Field(proto.INT32, number=3,) + assist_query_params = proto.Field( + proto.MESSAGE, number=4, message="AssistQueryParameters", + ) class SuggestFaqAnswersResponse(proto.Message): diff --git a/samples/AUTHORING_GUIDE.md b/samples/AUTHORING_GUIDE.md index 55c97b32f..8249522ff 100644 --- a/samples/AUTHORING_GUIDE.md +++ b/samples/AUTHORING_GUIDE.md @@ -1 +1 @@ -See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md \ No newline at end of file +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md \ No newline at end of file diff --git a/samples/CONTRIBUTING.md b/samples/CONTRIBUTING.md index 34c882b6f..f5fe2e6ba 100644 --- a/samples/CONTRIBUTING.md +++ b/samples/CONTRIBUTING.md @@ -1 +1 @@ -See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md \ No newline at end of file +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md \ No newline at end of file diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 93a9122cc..3bbef5d54 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,44 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/noxfile_config.py b/samples/snippets/noxfile_config.py new file mode 100644 index 000000000..4a4db8c2d --- /dev/null +++ b/samples/snippets/noxfile_config.py @@ -0,0 +1,38 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + "ignored_versions": ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": False, + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + # "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + "gcloud_project_env": "BUILD_SPECIFIC_GCLOUD_PROJECT", + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + "envs": {}, +} diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 97568eeb3..9514920ff 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-dialogflow==2.9.1 +google-cloud-dialogflow==2.10.0 Flask==2.0.2 diff --git a/scripts/fixup_dialogflow_v2_keywords.py b/scripts/fixup_dialogflow_v2_keywords.py index 6af3adf69..d3931a43b 100644 --- a/scripts/fixup_dialogflow_v2_keywords.py +++ b/scripts/fixup_dialogflow_v2_keywords.py @@ -72,6 +72,7 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'delete_version': ('name', ), 'detect_intent': ('session', 'query_input', 'query_params', 'output_audio_config', 'output_audio_config_mask', 'input_audio', ), 'export_agent': ('parent', 'agent_uri', ), + 'export_document': ('name', 'gcs_destination', 'export_full_content', 'smart_messaging_partial_update', ), 'get_agent': ('parent', ), 'get_context': ('name', ), 'get_conversation': ('name', ), @@ -92,16 +93,16 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'list_contexts': ('parent', 'page_size', 'page_token', ), 'list_conversation_profiles': ('parent', 'page_size', 'page_token', ), 'list_conversations': ('parent', 'page_size', 'page_token', 'filter', ), - 'list_documents': ('parent', 'page_size', 'page_token', ), + 'list_documents': ('parent', 'page_size', 'page_token', 'filter', ), 'list_entity_types': ('parent', 'language_code', 'page_size', 'page_token', ), 'list_environments': ('parent', 'page_size', 'page_token', ), 'list_intents': ('parent', 'language_code', 'intent_view', 'page_size', 'page_token', ), - 'list_knowledge_bases': ('parent', 'page_size', 'page_token', ), + 'list_knowledge_bases': ('parent', 'page_size', 'page_token', 'filter', ), 'list_messages': ('parent', 'filter', 'page_size', 'page_token', ), 'list_participants': ('parent', 'page_size', 'page_token', ), 'list_session_entity_types': ('parent', 'page_size', 'page_token', ), 'list_versions': ('parent', 'page_size', 'page_token', ), - 'reload_document': ('name', 'content_uri', ), + 'reload_document': ('name', 'content_uri', 'import_gcs_custom_metadata', 'smart_messaging_partial_update', ), 'restore_agent': ('parent', 'agent_uri', 'agent_content', ), 'search_agents': ('parent', 'page_size', 'page_token', ), 'set_agent': ('agent', 'update_mask', ), diff --git a/scripts/fixup_dialogflow_v2beta1_keywords.py b/scripts/fixup_dialogflow_v2beta1_keywords.py index dc332e8f5..a921e3c51 100644 --- a/scripts/fixup_dialogflow_v2beta1_keywords.py +++ b/scripts/fixup_dialogflow_v2beta1_keywords.py @@ -39,7 +39,7 @@ def partition( class dialogflowCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'analyze_content': ('participant', 'text_input', 'event_input', 'reply_audio_config', 'query_params', 'message_send_time', 'request_id', ), + 'analyze_content': ('participant', 'text_input', 'event_input', 'reply_audio_config', 'query_params', 'assist_query_params', 'message_send_time', 'request_id', ), 'batch_create_entities': ('parent', 'entities', 'language_code', ), 'batch_create_messages': ('parent', 'requests', ), 'batch_delete_entities': ('parent', 'entity_values', 'language_code', ), @@ -111,8 +111,8 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'search_agents': ('parent', 'page_size', 'page_token', ), 'set_agent': ('agent', 'update_mask', ), 'streaming_detect_intent': ('session', 'query_input', 'query_params', 'single_utterance', 'output_audio_config', 'output_audio_config_mask', 'input_audio', ), - 'suggest_articles': ('parent', 'latest_message', 'context_size', ), - 'suggest_faq_answers': ('parent', 'latest_message', 'context_size', ), + 'suggest_articles': ('parent', 'latest_message', 'context_size', 'assist_query_params', ), + 'suggest_faq_answers': ('parent', 'latest_message', 'context_size', 'assist_query_params', ), 'suggest_smart_replies': ('parent', 'current_text_input', 'latest_message', 'context_size', ), 'train_agent': ('parent', ), 'update_answer_record': ('answer_record', 'update_mask', ), diff --git a/setup.py b/setup.py index 5666b53c0..4c0538e66 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ name = "dialogflow" description = "Client library for the Dialogflow API" -version = "2.10.0" +version = "2.11.0" release_status = "Development Status :: 5 - Production/Stable" dependencies = [ # NOTE: Maintainers, please do not require google-api-core>=2.x.x diff --git a/tests/unit/gapic/dialogflow_v2/test_agents.py b/tests/unit/gapic/dialogflow_v2/test_agents.py index 4c262a183..1d6cc9c16 100644 --- a/tests/unit/gapic/dialogflow_v2/test_agents.py +++ b/tests/unit/gapic/dialogflow_v2/test_agents.py @@ -232,20 +232,20 @@ def test_agents_client_client_options(client_class, transport_class, transport_n # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -300,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -391,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -449,7 +449,8 @@ def test_agents_client_client_options_from_dict(): ) -def test_get_agent(transport: str = "grpc", request_type=agent.GetAgentRequest): +@pytest.mark.parametrize("request_type", [agent.GetAgentRequest, dict,]) +def test_get_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -500,10 +501,6 @@ def test_get_agent(transport: str = "grpc", request_type=agent.GetAgentRequest): assert response.tier == agent.Agent.Tier.TIER_STANDARD -def test_get_agent_from_dict(): - test_get_agent(request_type=dict) - - def test_get_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -695,7 +692,8 @@ async def test_get_agent_flattened_error_async(): ) -def test_set_agent(transport: str = "grpc", request_type=gcd_agent.SetAgentRequest): +@pytest.mark.parametrize("request_type", [gcd_agent.SetAgentRequest, dict,]) +def test_set_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -746,10 +744,6 @@ def test_set_agent(transport: str = "grpc", request_type=gcd_agent.SetAgentReque assert response.tier == gcd_agent.Agent.Tier.TIER_STANDARD -def test_set_agent_from_dict(): - test_set_agent(request_type=dict) - - def test_set_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -945,7 +939,8 @@ async def test_set_agent_flattened_error_async(): ) -def test_delete_agent(transport: str = "grpc", request_type=agent.DeleteAgentRequest): +@pytest.mark.parametrize("request_type", [agent.DeleteAgentRequest, dict,]) +def test_delete_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -969,10 +964,6 @@ def test_delete_agent(transport: str = "grpc", request_type=agent.DeleteAgentReq assert response is None -def test_delete_agent_from_dict(): - test_delete_agent(request_type=dict) - - def test_delete_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1135,7 +1126,8 @@ async def test_delete_agent_flattened_error_async(): ) -def test_search_agents(transport: str = "grpc", request_type=agent.SearchAgentsRequest): +@pytest.mark.parametrize("request_type", [agent.SearchAgentsRequest, dict,]) +def test_search_agents(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1162,10 +1154,6 @@ def test_search_agents(transport: str = "grpc", request_type=agent.SearchAgentsR assert response.next_page_token == "next_page_token_value" -def test_search_agents_from_dict(): - test_search_agents(request_type=dict) - - def test_search_agents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1335,8 +1323,10 @@ async def test_search_agents_flattened_error_async(): ) -def test_search_agents_pager(): - client = AgentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_agents_pager(transport_name: str = "grpc"): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.search_agents), "__call__") as call: @@ -1365,8 +1355,10 @@ def test_search_agents_pager(): assert all(isinstance(i, agent.Agent) for i in results) -def test_search_agents_pages(): - client = AgentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_agents_pages(transport_name: str = "grpc"): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.search_agents), "__call__") as call: @@ -1441,7 +1433,8 @@ async def test_search_agents_async_pages(): assert page_.raw_page.next_page_token == token -def test_train_agent(transport: str = "grpc", request_type=agent.TrainAgentRequest): +@pytest.mark.parametrize("request_type", [agent.TrainAgentRequest, dict,]) +def test_train_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1465,10 +1458,6 @@ def test_train_agent(transport: str = "grpc", request_type=agent.TrainAgentReque assert isinstance(response, future.Future) -def test_train_agent_from_dict(): - test_train_agent(request_type=dict) - - def test_train_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1637,7 +1626,8 @@ async def test_train_agent_flattened_error_async(): ) -def test_export_agent(transport: str = "grpc", request_type=agent.ExportAgentRequest): +@pytest.mark.parametrize("request_type", [agent.ExportAgentRequest, dict,]) +def test_export_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1661,10 +1651,6 @@ def test_export_agent(transport: str = "grpc", request_type=agent.ExportAgentReq assert isinstance(response, future.Future) -def test_export_agent_from_dict(): - test_export_agent(request_type=dict) - - def test_export_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1833,7 +1819,8 @@ async def test_export_agent_flattened_error_async(): ) -def test_import_agent(transport: str = "grpc", request_type=agent.ImportAgentRequest): +@pytest.mark.parametrize("request_type", [agent.ImportAgentRequest, dict,]) +def test_import_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1857,10 +1844,6 @@ def test_import_agent(transport: str = "grpc", request_type=agent.ImportAgentReq assert isinstance(response, future.Future) -def test_import_agent_from_dict(): - test_import_agent(request_type=dict) - - def test_import_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1961,7 +1944,8 @@ async def test_import_agent_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_restore_agent(transport: str = "grpc", request_type=agent.RestoreAgentRequest): +@pytest.mark.parametrize("request_type", [agent.RestoreAgentRequest, dict,]) +def test_restore_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1985,10 +1969,6 @@ def test_restore_agent(transport: str = "grpc", request_type=agent.RestoreAgentR assert isinstance(response, future.Future) -def test_restore_agent_from_dict(): - test_restore_agent(request_type=dict) - - def test_restore_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2089,9 +2069,8 @@ async def test_restore_agent_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_get_validation_result( - transport: str = "grpc", request_type=agent.GetValidationResultRequest -): +@pytest.mark.parametrize("request_type", [agent.GetValidationResultRequest, dict,]) +def test_get_validation_result(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2117,10 +2096,6 @@ def test_get_validation_result( assert isinstance(response, validation_result.ValidationResult) -def test_get_validation_result_from_dict(): - test_get_validation_result(request_type=dict) - - def test_get_validation_result_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2771,7 +2746,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_answer_records.py b/tests/unit/gapic/dialogflow_v2/test_answer_records.py index 1f9a031f2..ff309cea1 100644 --- a/tests/unit/gapic/dialogflow_v2/test_answer_records.py +++ b/tests/unit/gapic/dialogflow_v2/test_answer_records.py @@ -250,20 +250,20 @@ def test_answer_records_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -322,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -417,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -448,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -481,9 +481,10 @@ def test_answer_records_client_client_options_from_dict(): ) -def test_list_answer_records( - transport: str = "grpc", request_type=answer_record.ListAnswerRecordsRequest -): +@pytest.mark.parametrize( + "request_type", [answer_record.ListAnswerRecordsRequest, dict,] +) +def test_list_answer_records(request_type, transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -512,10 +513,6 @@ def test_list_answer_records( assert response.next_page_token == "next_page_token_value" -def test_list_answer_records_from_dict(): - test_list_answer_records(request_type=dict) - - def test_list_answer_records_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -705,8 +702,10 @@ async def test_list_answer_records_flattened_error_async(): ) -def test_list_answer_records_pager(): - client = AnswerRecordsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_answer_records_pager(transport_name: str = "grpc"): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -750,8 +749,10 @@ def test_list_answer_records_pager(): assert all(isinstance(i, answer_record.AnswerRecord) for i in results) -def test_list_answer_records_pages(): - client = AnswerRecordsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_answer_records_pages(transport_name: str = "grpc"): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -871,9 +872,10 @@ async def test_list_answer_records_async_pages(): assert page_.raw_page.next_page_token == token -def test_update_answer_record( - transport: str = "grpc", request_type=gcd_answer_record.UpdateAnswerRecordRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_answer_record.UpdateAnswerRecordRequest, dict,] +) +def test_update_answer_record(request_type, transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -905,10 +907,6 @@ def test_update_answer_record( assert response.name == "name_value" -def test_update_answer_record_from_dict(): - test_update_answer_record(request_type=dict) - - def test_update_answer_record_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1642,7 +1640,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_contexts.py b/tests/unit/gapic/dialogflow_v2/test_contexts.py index f2a087a9c..6a05225f6 100644 --- a/tests/unit/gapic/dialogflow_v2/test_contexts.py +++ b/tests/unit/gapic/dialogflow_v2/test_contexts.py @@ -232,20 +232,20 @@ def test_contexts_client_client_options(client_class, transport_class, transport # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -302,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -393,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -420,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -451,9 +451,8 @@ def test_contexts_client_client_options_from_dict(): ) -def test_list_contexts( - transport: str = "grpc", request_type=context.ListContextsRequest -): +@pytest.mark.parametrize("request_type", [context.ListContextsRequest, dict,]) +def test_list_contexts(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -480,10 +479,6 @@ def test_list_contexts( assert response.next_page_token == "next_page_token_value" -def test_list_contexts_from_dict(): - test_list_contexts(request_type=dict) - - def test_list_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -653,8 +648,10 @@ async def test_list_contexts_flattened_error_async(): ) -def test_list_contexts_pager(): - client = ContextsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_contexts_pager(transport_name: str = "grpc"): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: @@ -687,8 +684,10 @@ def test_list_contexts_pager(): assert all(isinstance(i, context.Context) for i in results) -def test_list_contexts_pages(): - client = ContextsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_contexts_pages(transport_name: str = "grpc"): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: @@ -775,7 +774,8 @@ async def test_list_contexts_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_context(transport: str = "grpc", request_type=context.GetContextRequest): +@pytest.mark.parametrize("request_type", [context.GetContextRequest, dict,]) +def test_get_context(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -801,10 +801,6 @@ def test_get_context(transport: str = "grpc", request_type=context.GetContextReq assert response.lifespan_count == 1498 -def test_get_context_from_dict(): - test_get_context(request_type=dict) - - def test_get_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -971,9 +967,8 @@ async def test_get_context_flattened_error_async(): ) -def test_create_context( - transport: str = "grpc", request_type=gcd_context.CreateContextRequest -): +@pytest.mark.parametrize("request_type", [gcd_context.CreateContextRequest, dict,]) +def test_create_context(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -999,10 +994,6 @@ def test_create_context( assert response.lifespan_count == 1498 -def test_create_context_from_dict(): - test_create_context(request_type=dict) - - def test_create_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1183,9 +1174,8 @@ async def test_create_context_flattened_error_async(): ) -def test_update_context( - transport: str = "grpc", request_type=gcd_context.UpdateContextRequest -): +@pytest.mark.parametrize("request_type", [gcd_context.UpdateContextRequest, dict,]) +def test_update_context(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1211,10 +1201,6 @@ def test_update_context( assert response.lifespan_count == 1498 -def test_update_context_from_dict(): - test_update_context(request_type=dict) - - def test_update_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1401,9 +1387,8 @@ async def test_update_context_flattened_error_async(): ) -def test_delete_context( - transport: str = "grpc", request_type=context.DeleteContextRequest -): +@pytest.mark.parametrize("request_type", [context.DeleteContextRequest, dict,]) +def test_delete_context(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1427,10 +1412,6 @@ def test_delete_context( assert response is None -def test_delete_context_from_dict(): - test_delete_context(request_type=dict) - - def test_delete_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1593,9 +1574,8 @@ async def test_delete_context_flattened_error_async(): ) -def test_delete_all_contexts( - transport: str = "grpc", request_type=context.DeleteAllContextsRequest -): +@pytest.mark.parametrize("request_type", [context.DeleteAllContextsRequest, dict,]) +def test_delete_all_contexts(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1621,10 +1601,6 @@ def test_delete_all_contexts( assert response is None -def test_delete_all_contexts_from_dict(): - test_delete_all_contexts(request_type=dict) - - def test_delete_all_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2313,7 +2289,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py b/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py index a7f488276..4960e5a30 100644 --- a/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py +++ b/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py @@ -261,20 +261,20 @@ def test_conversation_profiles_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -343,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -442,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -477,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -510,10 +510,10 @@ def test_conversation_profiles_client_client_options_from_dict(): ) -def test_list_conversation_profiles( - transport: str = "grpc", - request_type=conversation_profile.ListConversationProfilesRequest, -): +@pytest.mark.parametrize( + "request_type", [conversation_profile.ListConversationProfilesRequest, dict,] +) +def test_list_conversation_profiles(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -542,10 +542,6 @@ def test_list_conversation_profiles( assert response.next_page_token == "next_page_token_value" -def test_list_conversation_profiles_from_dict(): - test_list_conversation_profiles(request_type=dict) - - def test_list_conversation_profiles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -744,9 +740,9 @@ async def test_list_conversation_profiles_flattened_error_async(): ) -def test_list_conversation_profiles_pager(): +def test_list_conversation_profiles_pager(transport_name: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -794,9 +790,9 @@ def test_list_conversation_profiles_pager(): ) -def test_list_conversation_profiles_pages(): +def test_list_conversation_profiles_pages(transport_name: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -926,10 +922,10 @@ async def test_list_conversation_profiles_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_conversation_profile( - transport: str = "grpc", - request_type=conversation_profile.GetConversationProfileRequest, -): +@pytest.mark.parametrize( + "request_type", [conversation_profile.GetConversationProfileRequest, dict,] +) +def test_get_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -966,10 +962,6 @@ def test_get_conversation_profile( assert response.security_settings == "security_settings_value" -def test_get_conversation_profile_from_dict(): - test_get_conversation_profile(request_type=dict) - - def test_get_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1174,10 +1166,10 @@ async def test_get_conversation_profile_flattened_error_async(): ) -def test_create_conversation_profile( - transport: str = "grpc", - request_type=gcd_conversation_profile.CreateConversationProfileRequest, -): +@pytest.mark.parametrize( + "request_type", [gcd_conversation_profile.CreateConversationProfileRequest, dict,] +) +def test_create_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1214,10 +1206,6 @@ def test_create_conversation_profile( assert response.security_settings == "security_settings_value" -def test_create_conversation_profile_from_dict(): - test_create_conversation_profile(request_type=dict) - - def test_create_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1446,10 +1434,10 @@ async def test_create_conversation_profile_flattened_error_async(): ) -def test_update_conversation_profile( - transport: str = "grpc", - request_type=gcd_conversation_profile.UpdateConversationProfileRequest, -): +@pytest.mark.parametrize( + "request_type", [gcd_conversation_profile.UpdateConversationProfileRequest, dict,] +) +def test_update_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1486,10 +1474,6 @@ def test_update_conversation_profile( assert response.security_settings == "security_settings_value" -def test_update_conversation_profile_from_dict(): - test_update_conversation_profile(request_type=dict) - - def test_update_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1724,10 +1708,10 @@ async def test_update_conversation_profile_flattened_error_async(): ) -def test_delete_conversation_profile( - transport: str = "grpc", - request_type=conversation_profile.DeleteConversationProfileRequest, -): +@pytest.mark.parametrize( + "request_type", [conversation_profile.DeleteConversationProfileRequest, dict,] +) +def test_delete_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1753,10 +1737,6 @@ def test_delete_conversation_profile( assert response is None -def test_delete_conversation_profile_from_dict(): - test_delete_conversation_profile(request_type=dict) - - def test_delete_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2594,7 +2574,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_conversations.py b/tests/unit/gapic/dialogflow_v2/test_conversations.py index d8aaef6df..48d6ee963 100644 --- a/tests/unit/gapic/dialogflow_v2/test_conversations.py +++ b/tests/unit/gapic/dialogflow_v2/test_conversations.py @@ -249,20 +249,20 @@ def test_conversations_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -321,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -416,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -447,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -480,9 +480,10 @@ def test_conversations_client_client_options_from_dict(): ) -def test_create_conversation( - transport: str = "grpc", request_type=gcd_conversation.CreateConversationRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_conversation.CreateConversationRequest, dict,] +) +def test_create_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -523,10 +524,6 @@ def test_create_conversation( ) -def test_create_conversation_from_dict(): - test_create_conversation(request_type=dict) - - def test_create_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -745,9 +742,8 @@ async def test_create_conversation_flattened_error_async(): ) -def test_list_conversations( - transport: str = "grpc", request_type=conversation.ListConversationsRequest -): +@pytest.mark.parametrize("request_type", [conversation.ListConversationsRequest, dict,]) +def test_list_conversations(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -776,10 +772,6 @@ def test_list_conversations( assert response.next_page_token == "next_page_token_value" -def test_list_conversations_from_dict(): - test_list_conversations(request_type=dict) - - def test_list_conversations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -969,8 +961,10 @@ async def test_list_conversations_flattened_error_async(): ) -def test_list_conversations_pager(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_conversations_pager(transport_name: str = "grpc"): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1014,8 +1008,10 @@ def test_list_conversations_pager(): assert all(isinstance(i, conversation.Conversation) for i in results) -def test_list_conversations_pages(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_conversations_pages(transport_name: str = "grpc"): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1135,9 +1131,8 @@ async def test_list_conversations_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_conversation( - transport: str = "grpc", request_type=conversation.GetConversationRequest -): +@pytest.mark.parametrize("request_type", [conversation.GetConversationRequest, dict,]) +def test_get_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1175,10 +1170,6 @@ def test_get_conversation( ) -def test_get_conversation_from_dict(): - test_get_conversation(request_type=dict) - - def test_get_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1367,9 +1358,10 @@ async def test_get_conversation_flattened_error_async(): ) -def test_complete_conversation( - transport: str = "grpc", request_type=conversation.CompleteConversationRequest -): +@pytest.mark.parametrize( + "request_type", [conversation.CompleteConversationRequest, dict,] +) +def test_complete_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1409,10 +1401,6 @@ def test_complete_conversation( ) -def test_complete_conversation_from_dict(): - test_complete_conversation(request_type=dict) - - def test_complete_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1614,9 +1602,8 @@ async def test_complete_conversation_flattened_error_async(): ) -def test_list_messages( - transport: str = "grpc", request_type=conversation.ListMessagesRequest -): +@pytest.mark.parametrize("request_type", [conversation.ListMessagesRequest, dict,]) +def test_list_messages(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1643,10 +1630,6 @@ def test_list_messages( assert response.next_page_token == "next_page_token_value" -def test_list_messages_from_dict(): - test_list_messages(request_type=dict) - - def test_list_messages_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1822,8 +1805,10 @@ async def test_list_messages_flattened_error_async(): ) -def test_list_messages_pager(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_messages_pager(transport_name: str = "grpc"): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_messages), "__call__") as call: @@ -1860,8 +1845,10 @@ def test_list_messages_pager(): assert all(isinstance(i, participant.Message) for i in results) -def test_list_messages_pages(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_messages_pages(transport_name: str = "grpc"): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_messages), "__call__") as call: @@ -2534,7 +2521,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_documents.py b/tests/unit/gapic/dialogflow_v2/test_documents.py index 842f8581d..a29db8f78 100644 --- a/tests/unit/gapic/dialogflow_v2/test_documents.py +++ b/tests/unit/gapic/dialogflow_v2/test_documents.py @@ -40,6 +40,7 @@ from google.cloud.dialogflow_v2.services.documents import transports from google.cloud.dialogflow_v2.types import document from google.cloud.dialogflow_v2.types import document as gcd_document +from google.cloud.dialogflow_v2.types import gcs from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore @@ -242,20 +243,20 @@ def test_documents_client_client_options(client_class, transport_class, transpor # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -312,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -407,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -438,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -469,9 +470,8 @@ def test_documents_client_client_options_from_dict(): ) -def test_list_documents( - transport: str = "grpc", request_type=document.ListDocumentsRequest -): +@pytest.mark.parametrize("request_type", [document.ListDocumentsRequest, dict,]) +def test_list_documents(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -498,10 +498,6 @@ def test_list_documents( assert response.next_page_token == "next_page_token_value" -def test_list_documents_from_dict(): - test_list_documents(request_type=dict) - - def test_list_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -671,8 +667,10 @@ async def test_list_documents_flattened_error_async(): ) -def test_list_documents_pager(): - client = DocumentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_documents_pager(transport_name: str = "grpc"): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_documents), "__call__") as call: @@ -709,8 +707,10 @@ def test_list_documents_pager(): assert all(isinstance(i, document.Document) for i in results) -def test_list_documents_pages(): - client = DocumentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_documents_pages(transport_name: str = "grpc"): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_documents), "__call__") as call: @@ -809,9 +809,8 @@ async def test_list_documents_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_document( - transport: str = "grpc", request_type=document.GetDocumentRequest -): +@pytest.mark.parametrize("request_type", [document.GetDocumentRequest, dict,]) +def test_get_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -847,10 +846,6 @@ def test_get_document( assert response.enable_auto_reload is True -def test_get_document_from_dict(): - test_get_document(request_type=dict) - - def test_get_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1026,9 +1021,8 @@ async def test_get_document_flattened_error_async(): ) -def test_create_document( - transport: str = "grpc", request_type=gcd_document.CreateDocumentRequest -): +@pytest.mark.parametrize("request_type", [gcd_document.CreateDocumentRequest, dict,]) +def test_create_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1052,10 +1046,6 @@ def test_create_document( assert isinstance(response, future.Future) -def test_create_document_from_dict(): - test_create_document(request_type=dict) - - def test_create_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1238,9 +1228,8 @@ async def test_create_document_flattened_error_async(): ) -def test_delete_document( - transport: str = "grpc", request_type=document.DeleteDocumentRequest -): +@pytest.mark.parametrize("request_type", [document.DeleteDocumentRequest, dict,]) +def test_delete_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1264,10 +1253,6 @@ def test_delete_document( assert isinstance(response, future.Future) -def test_delete_document_from_dict(): - test_delete_document(request_type=dict) - - def test_delete_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1436,9 +1421,8 @@ async def test_delete_document_flattened_error_async(): ) -def test_update_document( - transport: str = "grpc", request_type=gcd_document.UpdateDocumentRequest -): +@pytest.mark.parametrize("request_type", [gcd_document.UpdateDocumentRequest, dict,]) +def test_update_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1462,10 +1446,6 @@ def test_update_document( assert isinstance(response, future.Future) -def test_update_document_from_dict(): - test_update_document(request_type=dict) - - def test_update_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1654,9 +1634,8 @@ async def test_update_document_flattened_error_async(): ) -def test_reload_document( - transport: str = "grpc", request_type=document.ReloadDocumentRequest -): +@pytest.mark.parametrize("request_type", [document.ReloadDocumentRequest, dict,]) +def test_reload_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1680,10 +1659,6 @@ def test_reload_document( assert isinstance(response, future.Future) -def test_reload_document_from_dict(): - test_reload_document(request_type=dict) - - def test_reload_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1862,6 +1837,131 @@ async def test_reload_document_flattened_error_async(): ) +@pytest.mark.parametrize("request_type", [document.ExportDocumentRequest, dict,]) +def test_export_document(request_type, transport: str = "grpc"): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_document), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.export_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document.ExportDocumentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_export_document_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_document), "__call__") as call: + client.export_document() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document.ExportDocumentRequest() + + +@pytest.mark.asyncio +async def test_export_document_async( + transport: str = "grpc_asyncio", request_type=document.ExportDocumentRequest +): + client = DocumentsAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_document), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.export_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document.ExportDocumentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_export_document_async_from_dict(): + await test_export_document_async(request_type=dict) + + +def test_export_document_field_headers(): + client = DocumentsClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document.ExportDocumentRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_document), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.export_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_export_document_field_headers_async(): + client = DocumentsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document.ExportDocumentRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_document), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.export_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentsGrpcTransport( @@ -1962,6 +2062,7 @@ def test_documents_base_transport(): "delete_document", "update_document", "reload_document", + "export_document", ) for method in methods: with pytest.raises(NotImplementedError): @@ -2407,7 +2508,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_entity_types.py b/tests/unit/gapic/dialogflow_v2/test_entity_types.py index 7c6ce3960..e98525731 100644 --- a/tests/unit/gapic/dialogflow_v2/test_entity_types.py +++ b/tests/unit/gapic/dialogflow_v2/test_entity_types.py @@ -244,20 +244,20 @@ def test_entity_types_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -314,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -409,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -440,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -471,9 +471,8 @@ def test_entity_types_client_client_options_from_dict(): ) -def test_list_entity_types( - transport: str = "grpc", request_type=entity_type.ListEntityTypesRequest -): +@pytest.mark.parametrize("request_type", [entity_type.ListEntityTypesRequest, dict,]) +def test_list_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -502,10 +501,6 @@ def test_list_entity_types( assert response.next_page_token == "next_page_token_value" -def test_list_entity_types_from_dict(): - test_list_entity_types(request_type=dict) - - def test_list_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -703,8 +698,10 @@ async def test_list_entity_types_flattened_error_async(): ) -def test_list_entity_types_pager(): - client = EntityTypesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_entity_types_pager(transport_name: str = "grpc"): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -745,8 +742,10 @@ def test_list_entity_types_pager(): assert all(isinstance(i, entity_type.EntityType) for i in results) -def test_list_entity_types_pages(): - client = EntityTypesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_entity_types_pages(transport_name: str = "grpc"): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -857,9 +856,8 @@ async def test_list_entity_types_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_entity_type( - transport: str = "grpc", request_type=entity_type.GetEntityTypeRequest -): +@pytest.mark.parametrize("request_type", [entity_type.GetEntityTypeRequest, dict,]) +def test_get_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -897,10 +895,6 @@ def test_get_entity_type( assert response.enable_fuzzy_extraction is True -def test_get_entity_type_from_dict(): - test_get_entity_type(request_type=dict) - - def test_get_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1097,9 +1091,10 @@ async def test_get_entity_type_flattened_error_async(): ) -def test_create_entity_type( - transport: str = "grpc", request_type=gcd_entity_type.CreateEntityTypeRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_entity_type.CreateEntityTypeRequest, dict,] +) +def test_create_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1139,10 +1134,6 @@ def test_create_entity_type( assert response.enable_fuzzy_extraction is True -def test_create_entity_type_from_dict(): - test_create_entity_type(request_type=dict) - - def test_create_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1364,9 +1355,10 @@ async def test_create_entity_type_flattened_error_async(): ) -def test_update_entity_type( - transport: str = "grpc", request_type=gcd_entity_type.UpdateEntityTypeRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_entity_type.UpdateEntityTypeRequest, dict,] +) +def test_update_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1406,10 +1398,6 @@ def test_update_entity_type( assert response.enable_fuzzy_extraction is True -def test_update_entity_type_from_dict(): - test_update_entity_type(request_type=dict) - - def test_update_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1625,9 +1613,8 @@ async def test_update_entity_type_flattened_error_async(): ) -def test_delete_entity_type( - transport: str = "grpc", request_type=entity_type.DeleteEntityTypeRequest -): +@pytest.mark.parametrize("request_type", [entity_type.DeleteEntityTypeRequest, dict,]) +def test_delete_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1653,10 +1640,6 @@ def test_delete_entity_type( assert response is None -def test_delete_entity_type_from_dict(): - test_delete_entity_type(request_type=dict) - - def test_delete_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1831,9 +1814,10 @@ async def test_delete_entity_type_flattened_error_async(): ) -def test_batch_update_entity_types( - transport: str = "grpc", request_type=entity_type.BatchUpdateEntityTypesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchUpdateEntityTypesRequest, dict,] +) +def test_batch_update_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1859,10 +1843,6 @@ def test_batch_update_entity_types( assert isinstance(response, future.Future) -def test_batch_update_entity_types_from_dict(): - test_batch_update_entity_types(request_type=dict) - - def test_batch_update_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1972,9 +1952,10 @@ async def test_batch_update_entity_types_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_batch_delete_entity_types( - transport: str = "grpc", request_type=entity_type.BatchDeleteEntityTypesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchDeleteEntityTypesRequest, dict,] +) +def test_batch_delete_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2000,10 +1981,6 @@ def test_batch_delete_entity_types( assert isinstance(response, future.Future) -def test_batch_delete_entity_types_from_dict(): - test_batch_delete_entity_types(request_type=dict) - - def test_batch_delete_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2199,9 +2176,10 @@ async def test_batch_delete_entity_types_flattened_error_async(): ) -def test_batch_create_entities( - transport: str = "grpc", request_type=entity_type.BatchCreateEntitiesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchCreateEntitiesRequest, dict,] +) +def test_batch_create_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2227,10 +2205,6 @@ def test_batch_create_entities( assert isinstance(response, future.Future) -def test_batch_create_entities_from_dict(): - test_batch_create_entities(request_type=dict) - - def test_batch_create_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2437,9 +2411,10 @@ async def test_batch_create_entities_flattened_error_async(): ) -def test_batch_update_entities( - transport: str = "grpc", request_type=entity_type.BatchUpdateEntitiesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchUpdateEntitiesRequest, dict,] +) +def test_batch_update_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2465,10 +2440,6 @@ def test_batch_update_entities( assert isinstance(response, future.Future) -def test_batch_update_entities_from_dict(): - test_batch_update_entities(request_type=dict) - - def test_batch_update_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2675,9 +2646,10 @@ async def test_batch_update_entities_flattened_error_async(): ) -def test_batch_delete_entities( - transport: str = "grpc", request_type=entity_type.BatchDeleteEntitiesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchDeleteEntitiesRequest, dict,] +) +def test_batch_delete_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2703,10 +2675,6 @@ def test_batch_delete_entities( assert isinstance(response, future.Future) -def test_batch_delete_entities_from_dict(): - test_batch_delete_entities(request_type=dict) - - def test_batch_delete_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3460,7 +3428,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_environments.py b/tests/unit/gapic/dialogflow_v2/test_environments.py index 00ceb70bc..f9f2c71a7 100644 --- a/tests/unit/gapic/dialogflow_v2/test_environments.py +++ b/tests/unit/gapic/dialogflow_v2/test_environments.py @@ -241,20 +241,20 @@ def test_environments_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -311,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -406,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -437,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -468,9 +468,8 @@ def test_environments_client_client_options_from_dict(): ) -def test_list_environments( - transport: str = "grpc", request_type=environment.ListEnvironmentsRequest -): +@pytest.mark.parametrize("request_type", [environment.ListEnvironmentsRequest, dict,]) +def test_list_environments(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -499,10 +498,6 @@ def test_list_environments( assert response.next_page_token == "next_page_token_value" -def test_list_environments_from_dict(): - test_list_environments(request_type=dict) - - def test_list_environments_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -686,8 +681,10 @@ async def test_list_environments_flattened_error_async(): ) -def test_list_environments_pager(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_environments_pager(transport_name: str = "grpc"): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -728,8 +725,10 @@ def test_list_environments_pager(): assert all(isinstance(i, environment.Environment) for i in results) -def test_list_environments_pages(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_environments_pages(transport_name: str = "grpc"): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -840,9 +839,8 @@ async def test_list_environments_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_environment( - transport: str = "grpc", request_type=environment.GetEnvironmentRequest -): +@pytest.mark.parametrize("request_type", [environment.GetEnvironmentRequest, dict,]) +def test_get_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -875,10 +873,6 @@ def test_get_environment( assert response.state == environment.Environment.State.STOPPED -def test_get_environment_from_dict(): - test_get_environment(request_type=dict) - - def test_get_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -988,9 +982,8 @@ async def test_get_environment_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_create_environment( - transport: str = "grpc", request_type=environment.CreateEnvironmentRequest -): +@pytest.mark.parametrize("request_type", [environment.CreateEnvironmentRequest, dict,]) +def test_create_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1025,10 +1018,6 @@ def test_create_environment( assert response.state == environment.Environment.State.STOPPED -def test_create_environment_from_dict(): - test_create_environment(request_type=dict) - - def test_create_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1146,9 +1135,8 @@ async def test_create_environment_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_update_environment( - transport: str = "grpc", request_type=environment.UpdateEnvironmentRequest -): +@pytest.mark.parametrize("request_type", [environment.UpdateEnvironmentRequest, dict,]) +def test_update_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1183,10 +1171,6 @@ def test_update_environment( assert response.state == environment.Environment.State.STOPPED -def test_update_environment_from_dict(): - test_update_environment(request_type=dict) - - def test_update_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1308,9 +1292,8 @@ async def test_update_environment_field_headers_async(): ] -def test_delete_environment( - transport: str = "grpc", request_type=environment.DeleteEnvironmentRequest -): +@pytest.mark.parametrize("request_type", [environment.DeleteEnvironmentRequest, dict,]) +def test_delete_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1336,10 +1319,6 @@ def test_delete_environment( assert response is None -def test_delete_environment_from_dict(): - test_delete_environment(request_type=dict) - - def test_delete_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1444,9 +1423,10 @@ async def test_delete_environment_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_get_environment_history( - transport: str = "grpc", request_type=environment.GetEnvironmentHistoryRequest -): +@pytest.mark.parametrize( + "request_type", [environment.GetEnvironmentHistoryRequest, dict,] +) +def test_get_environment_history(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1476,10 +1456,6 @@ def test_get_environment_history( assert response.next_page_token == "next_page_token_value" -def test_get_environment_history_from_dict(): - test_get_environment_history(request_type=dict) - - def test_get_environment_history_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1593,8 +1569,10 @@ async def test_get_environment_history_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_get_environment_history_pager(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_get_environment_history_pager(transport_name: str = "grpc"): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1637,8 +1615,10 @@ def test_get_environment_history_pager(): assert all(isinstance(i, environment.EnvironmentHistory.Entry) for i in results) -def test_get_environment_history_pages(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_get_environment_history_pages(transport_name: str = "grpc"): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2315,7 +2295,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_fulfillments.py b/tests/unit/gapic/dialogflow_v2/test_fulfillments.py index 6a2360877..d8854e1a1 100644 --- a/tests/unit/gapic/dialogflow_v2/test_fulfillments.py +++ b/tests/unit/gapic/dialogflow_v2/test_fulfillments.py @@ -238,20 +238,20 @@ def test_fulfillments_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -308,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -403,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -434,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -465,9 +465,8 @@ def test_fulfillments_client_client_options_from_dict(): ) -def test_get_fulfillment( - transport: str = "grpc", request_type=fulfillment.GetFulfillmentRequest -): +@pytest.mark.parametrize("request_type", [fulfillment.GetFulfillmentRequest, dict,]) +def test_get_fulfillment(request_type, transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -501,10 +500,6 @@ def test_get_fulfillment( assert response.enabled is True -def test_get_fulfillment_from_dict(): - test_get_fulfillment(request_type=dict) - - def test_get_fulfillment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -678,9 +673,10 @@ async def test_get_fulfillment_flattened_error_async(): ) -def test_update_fulfillment( - transport: str = "grpc", request_type=gcd_fulfillment.UpdateFulfillmentRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_fulfillment.UpdateFulfillmentRequest, dict,] +) +def test_update_fulfillment(request_type, transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -716,10 +712,6 @@ def test_update_fulfillment( assert response.enabled is True -def test_update_fulfillment_from_dict(): - test_update_fulfillment(request_type=dict) - - def test_update_fulfillment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1436,7 +1428,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_intents.py b/tests/unit/gapic/dialogflow_v2/test_intents.py index d5c2ac54a..61ce43c4a 100644 --- a/tests/unit/gapic/dialogflow_v2/test_intents.py +++ b/tests/unit/gapic/dialogflow_v2/test_intents.py @@ -232,20 +232,20 @@ def test_intents_client_client_options(client_class, transport_class, transport_ # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -300,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -391,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -449,7 +449,8 @@ def test_intents_client_client_options_from_dict(): ) -def test_list_intents(transport: str = "grpc", request_type=intent.ListIntentsRequest): +@pytest.mark.parametrize("request_type", [intent.ListIntentsRequest, dict,]) +def test_list_intents(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -476,10 +477,6 @@ def test_list_intents(transport: str = "grpc", request_type=intent.ListIntentsRe assert response.next_page_token == "next_page_token_value" -def test_list_intents_from_dict(): - test_list_intents(request_type=dict) - - def test_list_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -663,8 +660,10 @@ async def test_list_intents_flattened_error_async(): ) -def test_list_intents_pager(): - client = IntentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_intents_pager(transport_name: str = "grpc"): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_intents), "__call__") as call: @@ -695,8 +694,10 @@ def test_list_intents_pager(): assert all(isinstance(i, intent.Intent) for i in results) -def test_list_intents_pages(): - client = IntentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_intents_pages(transport_name: str = "grpc"): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_intents), "__call__") as call: @@ -777,7 +778,8 @@ async def test_list_intents_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_intent(transport: str = "grpc", request_type=intent.GetIntentRequest): +@pytest.mark.parametrize("request_type", [intent.GetIntentRequest, dict,]) +def test_get_intent(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -834,10 +836,6 @@ def test_get_intent(transport: str = "grpc", request_type=intent.GetIntentReques assert response.parent_followup_intent_name == "parent_followup_intent_name_value" -def test_get_intent_from_dict(): - test_get_intent(request_type=dict) - - def test_get_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1049,9 +1047,8 @@ async def test_get_intent_flattened_error_async(): ) -def test_create_intent( - transport: str = "grpc", request_type=gcd_intent.CreateIntentRequest -): +@pytest.mark.parametrize("request_type", [gcd_intent.CreateIntentRequest, dict,]) +def test_create_intent(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1110,10 +1107,6 @@ def test_create_intent( assert response.parent_followup_intent_name == "parent_followup_intent_name_value" -def test_create_intent_from_dict(): - test_create_intent(request_type=dict) - - def test_create_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1341,9 +1334,8 @@ async def test_create_intent_flattened_error_async(): ) -def test_update_intent( - transport: str = "grpc", request_type=gcd_intent.UpdateIntentRequest -): +@pytest.mark.parametrize("request_type", [gcd_intent.UpdateIntentRequest, dict,]) +def test_update_intent(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1402,10 +1394,6 @@ def test_update_intent( assert response.parent_followup_intent_name == "parent_followup_intent_name_value" -def test_update_intent_from_dict(): - test_update_intent(request_type=dict) - - def test_update_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1633,9 +1621,8 @@ async def test_update_intent_flattened_error_async(): ) -def test_delete_intent( - transport: str = "grpc", request_type=intent.DeleteIntentRequest -): +@pytest.mark.parametrize("request_type", [intent.DeleteIntentRequest, dict,]) +def test_delete_intent(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1659,10 +1646,6 @@ def test_delete_intent( assert response is None -def test_delete_intent_from_dict(): - test_delete_intent(request_type=dict) - - def test_delete_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1825,9 +1808,8 @@ async def test_delete_intent_flattened_error_async(): ) -def test_batch_update_intents( - transport: str = "grpc", request_type=intent.BatchUpdateIntentsRequest -): +@pytest.mark.parametrize("request_type", [intent.BatchUpdateIntentsRequest, dict,]) +def test_batch_update_intents(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1853,10 +1835,6 @@ def test_batch_update_intents( assert isinstance(response, future.Future) -def test_batch_update_intents_from_dict(): - test_batch_update_intents(request_type=dict) - - def test_batch_update_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2065,9 +2043,8 @@ async def test_batch_update_intents_flattened_error_async(): ) -def test_batch_delete_intents( - transport: str = "grpc", request_type=intent.BatchDeleteIntentsRequest -): +@pytest.mark.parametrize("request_type", [intent.BatchDeleteIntentsRequest, dict,]) +def test_batch_delete_intents(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2093,10 +2070,6 @@ def test_batch_delete_intents( assert isinstance(response, future.Future) -def test_batch_delete_intents_from_dict(): - test_batch_delete_intents(request_type=dict) - - def test_batch_delete_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2859,7 +2832,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py b/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py index d49c11ebe..8e15df623 100644 --- a/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py +++ b/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py @@ -250,20 +250,20 @@ def test_knowledge_bases_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -322,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -417,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -448,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -481,9 +481,10 @@ def test_knowledge_bases_client_client_options_from_dict(): ) -def test_list_knowledge_bases( - transport: str = "grpc", request_type=knowledge_base.ListKnowledgeBasesRequest -): +@pytest.mark.parametrize( + "request_type", [knowledge_base.ListKnowledgeBasesRequest, dict,] +) +def test_list_knowledge_bases(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -512,10 +513,6 @@ def test_list_knowledge_bases( assert response.next_page_token == "next_page_token_value" -def test_list_knowledge_bases_from_dict(): - test_list_knowledge_bases(request_type=dict) - - def test_list_knowledge_bases_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -706,8 +703,10 @@ async def test_list_knowledge_bases_flattened_error_async(): ) -def test_list_knowledge_bases_pager(): - client = KnowledgeBasesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_knowledge_bases_pager(transport_name: str = "grpc"): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -752,8 +751,10 @@ def test_list_knowledge_bases_pager(): assert all(isinstance(i, knowledge_base.KnowledgeBase) for i in results) -def test_list_knowledge_bases_pages(): - client = KnowledgeBasesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_knowledge_bases_pages(transport_name: str = "grpc"): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -876,9 +877,10 @@ async def test_list_knowledge_bases_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_knowledge_base( - transport: str = "grpc", request_type=knowledge_base.GetKnowledgeBaseRequest -): +@pytest.mark.parametrize( + "request_type", [knowledge_base.GetKnowledgeBaseRequest, dict,] +) +def test_get_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -911,10 +913,6 @@ def test_get_knowledge_base( assert response.language_code == "language_code_value" -def test_get_knowledge_base_from_dict(): - test_get_knowledge_base(request_type=dict) - - def test_get_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1108,9 +1106,10 @@ async def test_get_knowledge_base_flattened_error_async(): ) -def test_create_knowledge_base( - transport: str = "grpc", request_type=gcd_knowledge_base.CreateKnowledgeBaseRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_knowledge_base.CreateKnowledgeBaseRequest, dict,] +) +def test_create_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1143,10 +1142,6 @@ def test_create_knowledge_base( assert response.language_code == "language_code_value" -def test_create_knowledge_base_from_dict(): - test_create_knowledge_base(request_type=dict) - - def test_create_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1357,9 +1352,10 @@ async def test_create_knowledge_base_flattened_error_async(): ) -def test_delete_knowledge_base( - transport: str = "grpc", request_type=knowledge_base.DeleteKnowledgeBaseRequest -): +@pytest.mark.parametrize( + "request_type", [knowledge_base.DeleteKnowledgeBaseRequest, dict,] +) +def test_delete_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1385,10 +1381,6 @@ def test_delete_knowledge_base( assert response is None -def test_delete_knowledge_base_from_dict(): - test_delete_knowledge_base(request_type=dict) - - def test_delete_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1570,9 +1562,10 @@ async def test_delete_knowledge_base_flattened_error_async(): ) -def test_update_knowledge_base( - transport: str = "grpc", request_type=gcd_knowledge_base.UpdateKnowledgeBaseRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_knowledge_base.UpdateKnowledgeBaseRequest, dict,] +) +def test_update_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1605,10 +1598,6 @@ def test_update_knowledge_base( assert response.language_code == "language_code_value" -def test_update_knowledge_base_from_dict(): - test_update_knowledge_base(request_type=dict) - - def test_update_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2353,7 +2342,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_participants.py b/tests/unit/gapic/dialogflow_v2/test_participants.py index 84c4d9683..2dd15c961 100644 --- a/tests/unit/gapic/dialogflow_v2/test_participants.py +++ b/tests/unit/gapic/dialogflow_v2/test_participants.py @@ -246,20 +246,20 @@ def test_participants_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -316,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -411,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -442,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -473,9 +473,10 @@ def test_participants_client_client_options_from_dict(): ) -def test_create_participant( - transport: str = "grpc", request_type=gcd_participant.CreateParticipantRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_participant.CreateParticipantRequest, dict,] +) +def test_create_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -508,10 +509,6 @@ def test_create_participant( assert response.sip_recording_media_label == "sip_recording_media_label_value" -def test_create_participant_from_dict(): - test_create_participant(request_type=dict) - - def test_create_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -716,9 +713,8 @@ async def test_create_participant_flattened_error_async(): ) -def test_get_participant( - transport: str = "grpc", request_type=participant.GetParticipantRequest -): +@pytest.mark.parametrize("request_type", [participant.GetParticipantRequest, dict,]) +def test_get_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -749,10 +745,6 @@ def test_get_participant( assert response.sip_recording_media_label == "sip_recording_media_label_value" -def test_get_participant_from_dict(): - test_get_participant(request_type=dict) - - def test_get_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -928,9 +920,8 @@ async def test_get_participant_flattened_error_async(): ) -def test_list_participants( - transport: str = "grpc", request_type=participant.ListParticipantsRequest -): +@pytest.mark.parametrize("request_type", [participant.ListParticipantsRequest, dict,]) +def test_list_participants(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -959,10 +950,6 @@ def test_list_participants( assert response.next_page_token == "next_page_token_value" -def test_list_participants_from_dict(): - test_list_participants(request_type=dict) - - def test_list_participants_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1146,8 +1133,10 @@ async def test_list_participants_flattened_error_async(): ) -def test_list_participants_pager(): - client = ParticipantsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_participants_pager(transport_name: str = "grpc"): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1188,8 +1177,10 @@ def test_list_participants_pager(): assert all(isinstance(i, participant.Participant) for i in results) -def test_list_participants_pages(): - client = ParticipantsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_participants_pages(transport_name: str = "grpc"): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1300,9 +1291,10 @@ async def test_list_participants_async_pages(): assert page_.raw_page.next_page_token == token -def test_update_participant( - transport: str = "grpc", request_type=gcd_participant.UpdateParticipantRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_participant.UpdateParticipantRequest, dict,] +) +def test_update_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1335,10 +1327,6 @@ def test_update_participant( assert response.sip_recording_media_label == "sip_recording_media_label_value" -def test_update_participant_from_dict(): - test_update_participant(request_type=dict) - - def test_update_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1547,9 +1535,8 @@ async def test_update_participant_flattened_error_async(): ) -def test_analyze_content( - transport: str = "grpc", request_type=gcd_participant.AnalyzeContentRequest -): +@pytest.mark.parametrize("request_type", [gcd_participant.AnalyzeContentRequest, dict,]) +def test_analyze_content(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1576,10 +1563,6 @@ def test_analyze_content( assert response.reply_text == "reply_text_value" -def test_analyze_content_from_dict(): - test_analyze_content(request_type=dict) - - def test_analyze_content_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1765,9 +1748,8 @@ async def test_analyze_content_flattened_error_async(): ) -def test_suggest_articles( - transport: str = "grpc", request_type=participant.SuggestArticlesRequest -): +@pytest.mark.parametrize("request_type", [participant.SuggestArticlesRequest, dict,]) +def test_suggest_articles(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1795,10 +1777,6 @@ def test_suggest_articles( assert response.context_size == 1311 -def test_suggest_articles_from_dict(): - test_suggest_articles(request_type=dict) - - def test_suggest_articles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1971,9 +1949,8 @@ async def test_suggest_articles_flattened_error_async(): ) -def test_suggest_faq_answers( - transport: str = "grpc", request_type=participant.SuggestFaqAnswersRequest -): +@pytest.mark.parametrize("request_type", [participant.SuggestFaqAnswersRequest, dict,]) +def test_suggest_faq_answers(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2003,10 +1980,6 @@ def test_suggest_faq_answers( assert response.context_size == 1311 -def test_suggest_faq_answers_from_dict(): - test_suggest_faq_answers(request_type=dict) - - def test_suggest_faq_answers_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2806,7 +2779,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( 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 f6a4d4877..5d51ebf34 100644 --- a/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py +++ b/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py @@ -256,20 +256,20 @@ def test_session_entity_types_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -338,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -433,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -464,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -497,10 +497,10 @@ def test_session_entity_types_client_client_options_from_dict(): ) -def test_list_session_entity_types( - transport: str = "grpc", - request_type=session_entity_type.ListSessionEntityTypesRequest, -): +@pytest.mark.parametrize( + "request_type", [session_entity_type.ListSessionEntityTypesRequest, dict,] +) +def test_list_session_entity_types(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -529,10 +529,6 @@ def test_list_session_entity_types( assert response.next_page_token == "next_page_token_value" -def test_list_session_entity_types_from_dict(): - test_list_session_entity_types(request_type=dict) - - def test_list_session_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -729,8 +725,10 @@ async def test_list_session_entity_types_flattened_error_async(): ) -def test_list_session_entity_types_pager(): - client = SessionEntityTypesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_session_entity_types_pager(transport_name: str = "grpc"): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -777,8 +775,10 @@ def test_list_session_entity_types_pager(): ) -def test_list_session_entity_types_pages(): - client = SessionEntityTypesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_session_entity_types_pages(transport_name: str = "grpc"): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -907,10 +907,10 @@ async def test_list_session_entity_types_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_session_entity_type( - transport: str = "grpc", - request_type=session_entity_type.GetSessionEntityTypeRequest, -): +@pytest.mark.parametrize( + "request_type", [session_entity_type.GetSessionEntityTypeRequest, dict,] +) +def test_get_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -944,10 +944,6 @@ def test_get_session_entity_type( ) -def test_get_session_entity_type_from_dict(): - test_get_session_entity_type(request_type=dict) - - def test_get_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1149,10 +1145,10 @@ async def test_get_session_entity_type_flattened_error_async(): ) -def test_create_session_entity_type( - transport: str = "grpc", - request_type=gcd_session_entity_type.CreateSessionEntityTypeRequest, -): +@pytest.mark.parametrize( + "request_type", [gcd_session_entity_type.CreateSessionEntityTypeRequest, dict,] +) +def test_create_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1186,10 +1182,6 @@ def test_create_session_entity_type( ) -def test_create_session_entity_type_from_dict(): - test_create_session_entity_type(request_type=dict) - - def test_create_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1415,10 +1407,10 @@ async def test_create_session_entity_type_flattened_error_async(): ) -def test_update_session_entity_type( - transport: str = "grpc", - request_type=gcd_session_entity_type.UpdateSessionEntityTypeRequest, -): +@pytest.mark.parametrize( + "request_type", [gcd_session_entity_type.UpdateSessionEntityTypeRequest, dict,] +) +def test_update_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1452,10 +1444,6 @@ def test_update_session_entity_type( ) -def test_update_session_entity_type_from_dict(): - test_update_session_entity_type(request_type=dict) - - def test_update_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1687,10 +1675,10 @@ async def test_update_session_entity_type_flattened_error_async(): ) -def test_delete_session_entity_type( - transport: str = "grpc", - request_type=session_entity_type.DeleteSessionEntityTypeRequest, -): +@pytest.mark.parametrize( + "request_type", [session_entity_type.DeleteSessionEntityTypeRequest, dict,] +) +def test_delete_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1716,10 +1704,6 @@ def test_delete_session_entity_type( assert response is None -def test_delete_session_entity_type_from_dict(): - test_delete_session_entity_type(request_type=dict) - - def test_delete_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2443,7 +2427,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_sessions.py b/tests/unit/gapic/dialogflow_v2/test_sessions.py index 4450d9cfa..d51c79a07 100644 --- a/tests/unit/gapic/dialogflow_v2/test_sessions.py +++ b/tests/unit/gapic/dialogflow_v2/test_sessions.py @@ -237,20 +237,20 @@ def test_sessions_client_client_options(client_class, transport_class, transport # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -307,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -398,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -425,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -456,9 +456,8 @@ def test_sessions_client_client_options_from_dict(): ) -def test_detect_intent( - transport: str = "grpc", request_type=gcd_session.DetectIntentRequest -): +@pytest.mark.parametrize("request_type", [gcd_session.DetectIntentRequest, dict,]) +def test_detect_intent(request_type, transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -486,10 +485,6 @@ def test_detect_intent( assert response.output_audio == b"output_audio_blob" -def test_detect_intent_from_dict(): - test_detect_intent(request_type=dict) - - def test_detect_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -702,9 +697,8 @@ async def test_detect_intent_flattened_error_async(): ) -def test_streaming_detect_intent( - transport: str = "grpc", request_type=session.StreamingDetectIntentRequest -): +@pytest.mark.parametrize("request_type", [session.StreamingDetectIntentRequest, dict,]) +def test_streaming_detect_intent(request_type, transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -732,10 +726,6 @@ def test_streaming_detect_intent( assert isinstance(message, session.StreamingDetectIntentResponse) -def test_streaming_detect_intent_from_dict(): - test_streaming_detect_intent(request_type=dict) - - @pytest.mark.asyncio async def test_streaming_detect_intent_async( transport: str = "grpc_asyncio", request_type=session.StreamingDetectIntentRequest @@ -1353,7 +1343,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2/test_versions.py b/tests/unit/gapic/dialogflow_v2/test_versions.py index e2fad9e8d..a1735e030 100644 --- a/tests/unit/gapic/dialogflow_v2/test_versions.py +++ b/tests/unit/gapic/dialogflow_v2/test_versions.py @@ -232,20 +232,20 @@ def test_versions_client_client_options(client_class, transport_class, transport # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -302,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -393,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -420,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -451,9 +451,8 @@ def test_versions_client_client_options_from_dict(): ) -def test_list_versions( - transport: str = "grpc", request_type=version.ListVersionsRequest -): +@pytest.mark.parametrize("request_type", [version.ListVersionsRequest, dict,]) +def test_list_versions(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -480,10 +479,6 @@ def test_list_versions( assert response.next_page_token == "next_page_token_value" -def test_list_versions_from_dict(): - test_list_versions(request_type=dict) - - def test_list_versions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -653,8 +648,10 @@ async def test_list_versions_flattened_error_async(): ) -def test_list_versions_pager(): - client = VersionsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_versions_pager(transport_name: str = "grpc"): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_versions), "__call__") as call: @@ -687,8 +684,10 @@ def test_list_versions_pager(): assert all(isinstance(i, version.Version) for i in results) -def test_list_versions_pages(): - client = VersionsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_versions_pages(transport_name: str = "grpc"): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_versions), "__call__") as call: @@ -775,7 +774,8 @@ async def test_list_versions_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_version(transport: str = "grpc", request_type=version.GetVersionRequest): +@pytest.mark.parametrize("request_type", [version.GetVersionRequest, dict,]) +def test_get_version(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -808,10 +808,6 @@ def test_get_version(transport: str = "grpc", request_type=version.GetVersionReq assert response.status == version.Version.VersionStatus.IN_PROGRESS -def test_get_version_from_dict(): - test_get_version(request_type=dict) - - def test_get_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -985,9 +981,8 @@ async def test_get_version_flattened_error_async(): ) -def test_create_version( - transport: str = "grpc", request_type=gcd_version.CreateVersionRequest -): +@pytest.mark.parametrize("request_type", [gcd_version.CreateVersionRequest, dict,]) +def test_create_version(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1020,10 +1015,6 @@ def test_create_version( assert response.status == gcd_version.Version.VersionStatus.IN_PROGRESS -def test_create_version_from_dict(): - test_create_version(request_type=dict) - - def test_create_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1211,9 +1202,8 @@ async def test_create_version_flattened_error_async(): ) -def test_update_version( - transport: str = "grpc", request_type=gcd_version.UpdateVersionRequest -): +@pytest.mark.parametrize("request_type", [gcd_version.UpdateVersionRequest, dict,]) +def test_update_version(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1246,10 +1236,6 @@ def test_update_version( assert response.status == gcd_version.Version.VersionStatus.IN_PROGRESS -def test_update_version_from_dict(): - test_update_version(request_type=dict) - - def test_update_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1443,9 +1429,8 @@ async def test_update_version_flattened_error_async(): ) -def test_delete_version( - transport: str = "grpc", request_type=version.DeleteVersionRequest -): +@pytest.mark.parametrize("request_type", [version.DeleteVersionRequest, dict,]) +def test_delete_version(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1469,10 +1454,6 @@ def test_delete_version( assert response is None -def test_delete_version_from_dict(): - test_delete_version(request_type=dict) - - def test_delete_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2146,7 +2127,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_agents.py b/tests/unit/gapic/dialogflow_v2beta1/test_agents.py index 35423f578..4ec55170b 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_agents.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_agents.py @@ -232,20 +232,20 @@ def test_agents_client_client_options(client_class, transport_class, transport_n # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -300,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -391,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -449,7 +449,8 @@ def test_agents_client_client_options_from_dict(): ) -def test_get_agent(transport: str = "grpc", request_type=agent.GetAgentRequest): +@pytest.mark.parametrize("request_type", [agent.GetAgentRequest, dict,]) +def test_get_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -500,10 +501,6 @@ def test_get_agent(transport: str = "grpc", request_type=agent.GetAgentRequest): assert response.tier == agent.Agent.Tier.TIER_STANDARD -def test_get_agent_from_dict(): - test_get_agent(request_type=dict) - - def test_get_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -695,7 +692,8 @@ async def test_get_agent_flattened_error_async(): ) -def test_set_agent(transport: str = "grpc", request_type=gcd_agent.SetAgentRequest): +@pytest.mark.parametrize("request_type", [gcd_agent.SetAgentRequest, dict,]) +def test_set_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -746,10 +744,6 @@ def test_set_agent(transport: str = "grpc", request_type=gcd_agent.SetAgentReque assert response.tier == gcd_agent.Agent.Tier.TIER_STANDARD -def test_set_agent_from_dict(): - test_set_agent(request_type=dict) - - def test_set_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -945,7 +939,8 @@ async def test_set_agent_flattened_error_async(): ) -def test_delete_agent(transport: str = "grpc", request_type=agent.DeleteAgentRequest): +@pytest.mark.parametrize("request_type", [agent.DeleteAgentRequest, dict,]) +def test_delete_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -969,10 +964,6 @@ def test_delete_agent(transport: str = "grpc", request_type=agent.DeleteAgentReq assert response is None -def test_delete_agent_from_dict(): - test_delete_agent(request_type=dict) - - def test_delete_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1135,7 +1126,8 @@ async def test_delete_agent_flattened_error_async(): ) -def test_search_agents(transport: str = "grpc", request_type=agent.SearchAgentsRequest): +@pytest.mark.parametrize("request_type", [agent.SearchAgentsRequest, dict,]) +def test_search_agents(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1162,10 +1154,6 @@ def test_search_agents(transport: str = "grpc", request_type=agent.SearchAgentsR assert response.next_page_token == "next_page_token_value" -def test_search_agents_from_dict(): - test_search_agents(request_type=dict) - - def test_search_agents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1335,8 +1323,10 @@ async def test_search_agents_flattened_error_async(): ) -def test_search_agents_pager(): - client = AgentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_agents_pager(transport_name: str = "grpc"): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.search_agents), "__call__") as call: @@ -1365,8 +1355,10 @@ def test_search_agents_pager(): assert all(isinstance(i, agent.Agent) for i in results) -def test_search_agents_pages(): - client = AgentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_agents_pages(transport_name: str = "grpc"): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.search_agents), "__call__") as call: @@ -1441,7 +1433,8 @@ async def test_search_agents_async_pages(): assert page_.raw_page.next_page_token == token -def test_train_agent(transport: str = "grpc", request_type=agent.TrainAgentRequest): +@pytest.mark.parametrize("request_type", [agent.TrainAgentRequest, dict,]) +def test_train_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1465,10 +1458,6 @@ def test_train_agent(transport: str = "grpc", request_type=agent.TrainAgentReque assert isinstance(response, future.Future) -def test_train_agent_from_dict(): - test_train_agent(request_type=dict) - - def test_train_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1637,7 +1626,8 @@ async def test_train_agent_flattened_error_async(): ) -def test_export_agent(transport: str = "grpc", request_type=agent.ExportAgentRequest): +@pytest.mark.parametrize("request_type", [agent.ExportAgentRequest, dict,]) +def test_export_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1661,10 +1651,6 @@ def test_export_agent(transport: str = "grpc", request_type=agent.ExportAgentReq assert isinstance(response, future.Future) -def test_export_agent_from_dict(): - test_export_agent(request_type=dict) - - def test_export_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1833,7 +1819,8 @@ async def test_export_agent_flattened_error_async(): ) -def test_import_agent(transport: str = "grpc", request_type=agent.ImportAgentRequest): +@pytest.mark.parametrize("request_type", [agent.ImportAgentRequest, dict,]) +def test_import_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1857,10 +1844,6 @@ def test_import_agent(transport: str = "grpc", request_type=agent.ImportAgentReq assert isinstance(response, future.Future) -def test_import_agent_from_dict(): - test_import_agent(request_type=dict) - - def test_import_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1961,7 +1944,8 @@ async def test_import_agent_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_restore_agent(transport: str = "grpc", request_type=agent.RestoreAgentRequest): +@pytest.mark.parametrize("request_type", [agent.RestoreAgentRequest, dict,]) +def test_restore_agent(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1985,10 +1969,6 @@ def test_restore_agent(transport: str = "grpc", request_type=agent.RestoreAgentR assert isinstance(response, future.Future) -def test_restore_agent_from_dict(): - test_restore_agent(request_type=dict) - - def test_restore_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2089,9 +2069,8 @@ async def test_restore_agent_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_get_validation_result( - transport: str = "grpc", request_type=agent.GetValidationResultRequest -): +@pytest.mark.parametrize("request_type", [agent.GetValidationResultRequest, dict,]) +def test_get_validation_result(request_type, transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2117,10 +2096,6 @@ def test_get_validation_result( assert isinstance(response, validation_result.ValidationResult) -def test_get_validation_result_from_dict(): - test_get_validation_result(request_type=dict) - - def test_get_validation_result_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2771,7 +2746,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py b/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py index ced898e69..71ca27e26 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py @@ -252,20 +252,20 @@ def test_answer_records_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -324,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -419,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -450,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -483,9 +483,8 @@ def test_answer_records_client_client_options_from_dict(): ) -def test_get_answer_record( - transport: str = "grpc", request_type=answer_record.GetAnswerRecordRequest -): +@pytest.mark.parametrize("request_type", [answer_record.GetAnswerRecordRequest, dict,]) +def test_get_answer_record(request_type, transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -517,10 +516,6 @@ def test_get_answer_record( assert response.name == "name_value" -def test_get_answer_record_from_dict(): - test_get_answer_record(request_type=dict) - - def test_get_answer_record_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -632,9 +627,10 @@ async def test_get_answer_record_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_list_answer_records( - transport: str = "grpc", request_type=answer_record.ListAnswerRecordsRequest -): +@pytest.mark.parametrize( + "request_type", [answer_record.ListAnswerRecordsRequest, dict,] +) +def test_list_answer_records(request_type, transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -663,10 +659,6 @@ def test_list_answer_records( assert response.next_page_token == "next_page_token_value" -def test_list_answer_records_from_dict(): - test_list_answer_records(request_type=dict) - - def test_list_answer_records_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -856,8 +848,10 @@ async def test_list_answer_records_flattened_error_async(): ) -def test_list_answer_records_pager(): - client = AnswerRecordsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_answer_records_pager(transport_name: str = "grpc"): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -901,8 +895,10 @@ def test_list_answer_records_pager(): assert all(isinstance(i, answer_record.AnswerRecord) for i in results) -def test_list_answer_records_pages(): - client = AnswerRecordsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_answer_records_pages(transport_name: str = "grpc"): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1022,9 +1018,10 @@ async def test_list_answer_records_async_pages(): assert page_.raw_page.next_page_token == token -def test_update_answer_record( - transport: str = "grpc", request_type=gcd_answer_record.UpdateAnswerRecordRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_answer_record.UpdateAnswerRecordRequest, dict,] +) +def test_update_answer_record(request_type, transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1056,10 +1053,6 @@ def test_update_answer_record( assert response.name == "name_value" -def test_update_answer_record_from_dict(): - test_update_answer_record(request_type=dict) - - def test_update_answer_record_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1794,7 +1787,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py b/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py index 9951713d9..27625ffa9 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py @@ -232,20 +232,20 @@ def test_contexts_client_client_options(client_class, transport_class, transport # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -302,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -393,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -420,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -451,9 +451,8 @@ def test_contexts_client_client_options_from_dict(): ) -def test_list_contexts( - transport: str = "grpc", request_type=context.ListContextsRequest -): +@pytest.mark.parametrize("request_type", [context.ListContextsRequest, dict,]) +def test_list_contexts(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -480,10 +479,6 @@ def test_list_contexts( assert response.next_page_token == "next_page_token_value" -def test_list_contexts_from_dict(): - test_list_contexts(request_type=dict) - - def test_list_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -653,8 +648,10 @@ async def test_list_contexts_flattened_error_async(): ) -def test_list_contexts_pager(): - client = ContextsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_contexts_pager(transport_name: str = "grpc"): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: @@ -687,8 +684,10 @@ def test_list_contexts_pager(): assert all(isinstance(i, context.Context) for i in results) -def test_list_contexts_pages(): - client = ContextsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_contexts_pages(transport_name: str = "grpc"): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: @@ -775,7 +774,8 @@ async def test_list_contexts_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_context(transport: str = "grpc", request_type=context.GetContextRequest): +@pytest.mark.parametrize("request_type", [context.GetContextRequest, dict,]) +def test_get_context(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -801,10 +801,6 @@ def test_get_context(transport: str = "grpc", request_type=context.GetContextReq assert response.lifespan_count == 1498 -def test_get_context_from_dict(): - test_get_context(request_type=dict) - - def test_get_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -971,9 +967,8 @@ async def test_get_context_flattened_error_async(): ) -def test_create_context( - transport: str = "grpc", request_type=gcd_context.CreateContextRequest -): +@pytest.mark.parametrize("request_type", [gcd_context.CreateContextRequest, dict,]) +def test_create_context(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -999,10 +994,6 @@ def test_create_context( assert response.lifespan_count == 1498 -def test_create_context_from_dict(): - test_create_context(request_type=dict) - - def test_create_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1183,9 +1174,8 @@ async def test_create_context_flattened_error_async(): ) -def test_update_context( - transport: str = "grpc", request_type=gcd_context.UpdateContextRequest -): +@pytest.mark.parametrize("request_type", [gcd_context.UpdateContextRequest, dict,]) +def test_update_context(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1211,10 +1201,6 @@ def test_update_context( assert response.lifespan_count == 1498 -def test_update_context_from_dict(): - test_update_context(request_type=dict) - - def test_update_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1401,9 +1387,8 @@ async def test_update_context_flattened_error_async(): ) -def test_delete_context( - transport: str = "grpc", request_type=context.DeleteContextRequest -): +@pytest.mark.parametrize("request_type", [context.DeleteContextRequest, dict,]) +def test_delete_context(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1427,10 +1412,6 @@ def test_delete_context( assert response is None -def test_delete_context_from_dict(): - test_delete_context(request_type=dict) - - def test_delete_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1593,9 +1574,8 @@ async def test_delete_context_flattened_error_async(): ) -def test_delete_all_contexts( - transport: str = "grpc", request_type=context.DeleteAllContextsRequest -): +@pytest.mark.parametrize("request_type", [context.DeleteAllContextsRequest, dict,]) +def test_delete_all_contexts(request_type, transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1621,10 +1601,6 @@ def test_delete_all_contexts( assert response is None -def test_delete_all_contexts_from_dict(): - test_delete_all_contexts(request_type=dict) - - def test_delete_all_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2313,7 +2289,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py b/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py index c00233ed7..20574f832 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py @@ -262,20 +262,20 @@ def test_conversation_profiles_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -344,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -443,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -478,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -511,10 +511,10 @@ def test_conversation_profiles_client_client_options_from_dict(): ) -def test_list_conversation_profiles( - transport: str = "grpc", - request_type=conversation_profile.ListConversationProfilesRequest, -): +@pytest.mark.parametrize( + "request_type", [conversation_profile.ListConversationProfilesRequest, dict,] +) +def test_list_conversation_profiles(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -543,10 +543,6 @@ def test_list_conversation_profiles( assert response.next_page_token == "next_page_token_value" -def test_list_conversation_profiles_from_dict(): - test_list_conversation_profiles(request_type=dict) - - def test_list_conversation_profiles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -745,9 +741,9 @@ async def test_list_conversation_profiles_flattened_error_async(): ) -def test_list_conversation_profiles_pager(): +def test_list_conversation_profiles_pager(transport_name: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -795,9 +791,9 @@ def test_list_conversation_profiles_pager(): ) -def test_list_conversation_profiles_pages(): +def test_list_conversation_profiles_pages(transport_name: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -927,10 +923,10 @@ async def test_list_conversation_profiles_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_conversation_profile( - transport: str = "grpc", - request_type=conversation_profile.GetConversationProfileRequest, -): +@pytest.mark.parametrize( + "request_type", [conversation_profile.GetConversationProfileRequest, dict,] +) +def test_get_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -967,10 +963,6 @@ def test_get_conversation_profile( assert response.security_settings == "security_settings_value" -def test_get_conversation_profile_from_dict(): - test_get_conversation_profile(request_type=dict) - - def test_get_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1175,10 +1167,10 @@ async def test_get_conversation_profile_flattened_error_async(): ) -def test_create_conversation_profile( - transport: str = "grpc", - request_type=gcd_conversation_profile.CreateConversationProfileRequest, -): +@pytest.mark.parametrize( + "request_type", [gcd_conversation_profile.CreateConversationProfileRequest, dict,] +) +def test_create_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1215,10 +1207,6 @@ def test_create_conversation_profile( assert response.security_settings == "security_settings_value" -def test_create_conversation_profile_from_dict(): - test_create_conversation_profile(request_type=dict) - - def test_create_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1447,10 +1435,10 @@ async def test_create_conversation_profile_flattened_error_async(): ) -def test_update_conversation_profile( - transport: str = "grpc", - request_type=gcd_conversation_profile.UpdateConversationProfileRequest, -): +@pytest.mark.parametrize( + "request_type", [gcd_conversation_profile.UpdateConversationProfileRequest, dict,] +) +def test_update_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1487,10 +1475,6 @@ def test_update_conversation_profile( assert response.security_settings == "security_settings_value" -def test_update_conversation_profile_from_dict(): - test_update_conversation_profile(request_type=dict) - - def test_update_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1725,10 +1709,10 @@ async def test_update_conversation_profile_flattened_error_async(): ) -def test_delete_conversation_profile( - transport: str = "grpc", - request_type=conversation_profile.DeleteConversationProfileRequest, -): +@pytest.mark.parametrize( + "request_type", [conversation_profile.DeleteConversationProfileRequest, dict,] +) +def test_delete_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1754,10 +1738,6 @@ def test_delete_conversation_profile( assert response is None -def test_delete_conversation_profile_from_dict(): - test_delete_conversation_profile(request_type=dict) - - def test_delete_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2595,7 +2575,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py b/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py index c65a290d3..d0f94ba48 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py @@ -253,20 +253,20 @@ def test_conversations_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -325,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -420,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -451,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -484,9 +484,10 @@ def test_conversations_client_client_options_from_dict(): ) -def test_create_conversation( - transport: str = "grpc", request_type=gcd_conversation.CreateConversationRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_conversation.CreateConversationRequest, dict,] +) +def test_create_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -527,10 +528,6 @@ def test_create_conversation( ) -def test_create_conversation_from_dict(): - test_create_conversation(request_type=dict) - - def test_create_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -749,9 +746,8 @@ async def test_create_conversation_flattened_error_async(): ) -def test_list_conversations( - transport: str = "grpc", request_type=conversation.ListConversationsRequest -): +@pytest.mark.parametrize("request_type", [conversation.ListConversationsRequest, dict,]) +def test_list_conversations(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -780,10 +776,6 @@ def test_list_conversations( assert response.next_page_token == "next_page_token_value" -def test_list_conversations_from_dict(): - test_list_conversations(request_type=dict) - - def test_list_conversations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -973,8 +965,10 @@ async def test_list_conversations_flattened_error_async(): ) -def test_list_conversations_pager(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_conversations_pager(transport_name: str = "grpc"): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1018,8 +1012,10 @@ def test_list_conversations_pager(): assert all(isinstance(i, conversation.Conversation) for i in results) -def test_list_conversations_pages(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_conversations_pages(transport_name: str = "grpc"): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1139,9 +1135,8 @@ async def test_list_conversations_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_conversation( - transport: str = "grpc", request_type=conversation.GetConversationRequest -): +@pytest.mark.parametrize("request_type", [conversation.GetConversationRequest, dict,]) +def test_get_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1179,10 +1174,6 @@ def test_get_conversation( ) -def test_get_conversation_from_dict(): - test_get_conversation(request_type=dict) - - def test_get_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1371,9 +1362,10 @@ async def test_get_conversation_flattened_error_async(): ) -def test_complete_conversation( - transport: str = "grpc", request_type=conversation.CompleteConversationRequest -): +@pytest.mark.parametrize( + "request_type", [conversation.CompleteConversationRequest, dict,] +) +def test_complete_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1413,10 +1405,6 @@ def test_complete_conversation( ) -def test_complete_conversation_from_dict(): - test_complete_conversation(request_type=dict) - - def test_complete_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1618,9 +1606,10 @@ async def test_complete_conversation_flattened_error_async(): ) -def test_batch_create_messages( - transport: str = "grpc", request_type=conversation.BatchCreateMessagesRequest -): +@pytest.mark.parametrize( + "request_type", [conversation.BatchCreateMessagesRequest, dict,] +) +def test_batch_create_messages(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1646,10 +1635,6 @@ def test_batch_create_messages( assert isinstance(response, conversation.BatchCreateMessagesResponse) -def test_batch_create_messages_from_dict(): - test_batch_create_messages(request_type=dict) - - def test_batch_create_messages_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1837,9 +1822,8 @@ async def test_batch_create_messages_flattened_error_async(): ) -def test_list_messages( - transport: str = "grpc", request_type=conversation.ListMessagesRequest -): +@pytest.mark.parametrize("request_type", [conversation.ListMessagesRequest, dict,]) +def test_list_messages(request_type, transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1866,10 +1850,6 @@ def test_list_messages( assert response.next_page_token == "next_page_token_value" -def test_list_messages_from_dict(): - test_list_messages(request_type=dict) - - def test_list_messages_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2045,8 +2025,10 @@ async def test_list_messages_flattened_error_async(): ) -def test_list_messages_pager(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_messages_pager(transport_name: str = "grpc"): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_messages), "__call__") as call: @@ -2083,8 +2065,10 @@ def test_list_messages_pager(): assert all(isinstance(i, participant.Message) for i in results) -def test_list_messages_pages(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_messages_pages(transport_name: str = "grpc"): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_messages), "__call__") as call: @@ -2758,7 +2742,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_documents.py b/tests/unit/gapic/dialogflow_v2beta1/test_documents.py index 3d7d5a27e..1f057c497 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_documents.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_documents.py @@ -243,20 +243,20 @@ def test_documents_client_client_options(client_class, transport_class, transpor # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -313,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -408,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -439,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -470,9 +470,8 @@ def test_documents_client_client_options_from_dict(): ) -def test_list_documents( - transport: str = "grpc", request_type=document.ListDocumentsRequest -): +@pytest.mark.parametrize("request_type", [document.ListDocumentsRequest, dict,]) +def test_list_documents(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -499,10 +498,6 @@ def test_list_documents( assert response.next_page_token == "next_page_token_value" -def test_list_documents_from_dict(): - test_list_documents(request_type=dict) - - def test_list_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -672,8 +667,10 @@ async def test_list_documents_flattened_error_async(): ) -def test_list_documents_pager(): - client = DocumentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_documents_pager(transport_name: str = "grpc"): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_documents), "__call__") as call: @@ -710,8 +707,10 @@ def test_list_documents_pager(): assert all(isinstance(i, document.Document) for i in results) -def test_list_documents_pages(): - client = DocumentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_documents_pages(transport_name: str = "grpc"): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_documents), "__call__") as call: @@ -810,9 +809,8 @@ async def test_list_documents_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_document( - transport: str = "grpc", request_type=document.GetDocumentRequest -): +@pytest.mark.parametrize("request_type", [document.GetDocumentRequest, dict,]) +def test_get_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -848,10 +846,6 @@ def test_get_document( assert response.enable_auto_reload is True -def test_get_document_from_dict(): - test_get_document(request_type=dict) - - def test_get_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1027,9 +1021,8 @@ async def test_get_document_flattened_error_async(): ) -def test_create_document( - transport: str = "grpc", request_type=gcd_document.CreateDocumentRequest -): +@pytest.mark.parametrize("request_type", [gcd_document.CreateDocumentRequest, dict,]) +def test_create_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1053,10 +1046,6 @@ def test_create_document( assert isinstance(response, future.Future) -def test_create_document_from_dict(): - test_create_document(request_type=dict) - - def test_create_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1239,9 +1228,8 @@ async def test_create_document_flattened_error_async(): ) -def test_import_documents( - transport: str = "grpc", request_type=document.ImportDocumentsRequest -): +@pytest.mark.parametrize("request_type", [document.ImportDocumentsRequest, dict,]) +def test_import_documents(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1265,10 +1253,6 @@ def test_import_documents( assert isinstance(response, future.Future) -def test_import_documents_from_dict(): - test_import_documents(request_type=dict) - - def test_import_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1369,9 +1353,8 @@ async def test_import_documents_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_delete_document( - transport: str = "grpc", request_type=document.DeleteDocumentRequest -): +@pytest.mark.parametrize("request_type", [document.DeleteDocumentRequest, dict,]) +def test_delete_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1395,10 +1378,6 @@ def test_delete_document( assert isinstance(response, future.Future) -def test_delete_document_from_dict(): - test_delete_document(request_type=dict) - - def test_delete_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1567,9 +1546,8 @@ async def test_delete_document_flattened_error_async(): ) -def test_update_document( - transport: str = "grpc", request_type=gcd_document.UpdateDocumentRequest -): +@pytest.mark.parametrize("request_type", [gcd_document.UpdateDocumentRequest, dict,]) +def test_update_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1593,10 +1571,6 @@ def test_update_document( assert isinstance(response, future.Future) -def test_update_document_from_dict(): - test_update_document(request_type=dict) - - def test_update_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1785,9 +1759,8 @@ async def test_update_document_flattened_error_async(): ) -def test_reload_document( - transport: str = "grpc", request_type=document.ReloadDocumentRequest -): +@pytest.mark.parametrize("request_type", [document.ReloadDocumentRequest, dict,]) +def test_reload_document(request_type, transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1811,10 +1784,6 @@ def test_reload_document( assert isinstance(response, future.Future) -def test_reload_document_from_dict(): - test_reload_document(request_type=dict) - - def test_reload_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2539,7 +2508,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py b/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py index 52eb0d9bb..0e4907a9a 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py @@ -244,20 +244,20 @@ def test_entity_types_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -314,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -409,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -440,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -471,9 +471,8 @@ def test_entity_types_client_client_options_from_dict(): ) -def test_list_entity_types( - transport: str = "grpc", request_type=entity_type.ListEntityTypesRequest -): +@pytest.mark.parametrize("request_type", [entity_type.ListEntityTypesRequest, dict,]) +def test_list_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -502,10 +501,6 @@ def test_list_entity_types( assert response.next_page_token == "next_page_token_value" -def test_list_entity_types_from_dict(): - test_list_entity_types(request_type=dict) - - def test_list_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -703,8 +698,10 @@ async def test_list_entity_types_flattened_error_async(): ) -def test_list_entity_types_pager(): - client = EntityTypesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_entity_types_pager(transport_name: str = "grpc"): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -745,8 +742,10 @@ def test_list_entity_types_pager(): assert all(isinstance(i, entity_type.EntityType) for i in results) -def test_list_entity_types_pages(): - client = EntityTypesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_entity_types_pages(transport_name: str = "grpc"): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -857,9 +856,8 @@ async def test_list_entity_types_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_entity_type( - transport: str = "grpc", request_type=entity_type.GetEntityTypeRequest -): +@pytest.mark.parametrize("request_type", [entity_type.GetEntityTypeRequest, dict,]) +def test_get_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -897,10 +895,6 @@ def test_get_entity_type( assert response.enable_fuzzy_extraction is True -def test_get_entity_type_from_dict(): - test_get_entity_type(request_type=dict) - - def test_get_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1097,9 +1091,10 @@ async def test_get_entity_type_flattened_error_async(): ) -def test_create_entity_type( - transport: str = "grpc", request_type=gcd_entity_type.CreateEntityTypeRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_entity_type.CreateEntityTypeRequest, dict,] +) +def test_create_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1139,10 +1134,6 @@ def test_create_entity_type( assert response.enable_fuzzy_extraction is True -def test_create_entity_type_from_dict(): - test_create_entity_type(request_type=dict) - - def test_create_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1364,9 +1355,10 @@ async def test_create_entity_type_flattened_error_async(): ) -def test_update_entity_type( - transport: str = "grpc", request_type=gcd_entity_type.UpdateEntityTypeRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_entity_type.UpdateEntityTypeRequest, dict,] +) +def test_update_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1406,10 +1398,6 @@ def test_update_entity_type( assert response.enable_fuzzy_extraction is True -def test_update_entity_type_from_dict(): - test_update_entity_type(request_type=dict) - - def test_update_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1635,9 +1623,8 @@ async def test_update_entity_type_flattened_error_async(): ) -def test_delete_entity_type( - transport: str = "grpc", request_type=entity_type.DeleteEntityTypeRequest -): +@pytest.mark.parametrize("request_type", [entity_type.DeleteEntityTypeRequest, dict,]) +def test_delete_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1663,10 +1650,6 @@ def test_delete_entity_type( assert response is None -def test_delete_entity_type_from_dict(): - test_delete_entity_type(request_type=dict) - - def test_delete_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1841,9 +1824,10 @@ async def test_delete_entity_type_flattened_error_async(): ) -def test_batch_update_entity_types( - transport: str = "grpc", request_type=entity_type.BatchUpdateEntityTypesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchUpdateEntityTypesRequest, dict,] +) +def test_batch_update_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1869,10 +1853,6 @@ def test_batch_update_entity_types( assert isinstance(response, future.Future) -def test_batch_update_entity_types_from_dict(): - test_batch_update_entity_types(request_type=dict) - - def test_batch_update_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1982,9 +1962,10 @@ async def test_batch_update_entity_types_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_batch_delete_entity_types( - transport: str = "grpc", request_type=entity_type.BatchDeleteEntityTypesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchDeleteEntityTypesRequest, dict,] +) +def test_batch_delete_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2010,10 +1991,6 @@ def test_batch_delete_entity_types( assert isinstance(response, future.Future) -def test_batch_delete_entity_types_from_dict(): - test_batch_delete_entity_types(request_type=dict) - - def test_batch_delete_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2209,9 +2186,10 @@ async def test_batch_delete_entity_types_flattened_error_async(): ) -def test_batch_create_entities( - transport: str = "grpc", request_type=entity_type.BatchCreateEntitiesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchCreateEntitiesRequest, dict,] +) +def test_batch_create_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2237,10 +2215,6 @@ def test_batch_create_entities( assert isinstance(response, future.Future) -def test_batch_create_entities_from_dict(): - test_batch_create_entities(request_type=dict) - - def test_batch_create_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2447,9 +2421,10 @@ async def test_batch_create_entities_flattened_error_async(): ) -def test_batch_update_entities( - transport: str = "grpc", request_type=entity_type.BatchUpdateEntitiesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchUpdateEntitiesRequest, dict,] +) +def test_batch_update_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2475,10 +2450,6 @@ def test_batch_update_entities( assert isinstance(response, future.Future) -def test_batch_update_entities_from_dict(): - test_batch_update_entities(request_type=dict) - - def test_batch_update_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2685,9 +2656,10 @@ async def test_batch_update_entities_flattened_error_async(): ) -def test_batch_delete_entities( - transport: str = "grpc", request_type=entity_type.BatchDeleteEntitiesRequest -): +@pytest.mark.parametrize( + "request_type", [entity_type.BatchDeleteEntitiesRequest, dict,] +) +def test_batch_delete_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2713,10 +2685,6 @@ def test_batch_delete_entities( assert isinstance(response, future.Future) -def test_batch_delete_entities_from_dict(): - test_batch_delete_entities(request_type=dict) - - def test_batch_delete_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3470,7 +3438,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_environments.py b/tests/unit/gapic/dialogflow_v2beta1/test_environments.py index 1c9635f21..7956a9c47 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_environments.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_environments.py @@ -243,20 +243,20 @@ def test_environments_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -313,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -408,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -439,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -470,9 +470,8 @@ def test_environments_client_client_options_from_dict(): ) -def test_list_environments( - transport: str = "grpc", request_type=environment.ListEnvironmentsRequest -): +@pytest.mark.parametrize("request_type", [environment.ListEnvironmentsRequest, dict,]) +def test_list_environments(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -501,10 +500,6 @@ def test_list_environments( assert response.next_page_token == "next_page_token_value" -def test_list_environments_from_dict(): - test_list_environments(request_type=dict) - - def test_list_environments_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -688,8 +683,10 @@ async def test_list_environments_flattened_error_async(): ) -def test_list_environments_pager(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_environments_pager(transport_name: str = "grpc"): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -730,8 +727,10 @@ def test_list_environments_pager(): assert all(isinstance(i, environment.Environment) for i in results) -def test_list_environments_pages(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_environments_pages(transport_name: str = "grpc"): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -842,9 +841,8 @@ async def test_list_environments_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_environment( - transport: str = "grpc", request_type=environment.GetEnvironmentRequest -): +@pytest.mark.parametrize("request_type", [environment.GetEnvironmentRequest, dict,]) +def test_get_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -877,10 +875,6 @@ def test_get_environment( assert response.state == environment.Environment.State.STOPPED -def test_get_environment_from_dict(): - test_get_environment(request_type=dict) - - def test_get_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -990,9 +984,8 @@ async def test_get_environment_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_create_environment( - transport: str = "grpc", request_type=environment.CreateEnvironmentRequest -): +@pytest.mark.parametrize("request_type", [environment.CreateEnvironmentRequest, dict,]) +def test_create_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1027,10 +1020,6 @@ def test_create_environment( assert response.state == environment.Environment.State.STOPPED -def test_create_environment_from_dict(): - test_create_environment(request_type=dict) - - def test_create_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1148,9 +1137,8 @@ async def test_create_environment_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_update_environment( - transport: str = "grpc", request_type=environment.UpdateEnvironmentRequest -): +@pytest.mark.parametrize("request_type", [environment.UpdateEnvironmentRequest, dict,]) +def test_update_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1185,10 +1173,6 @@ def test_update_environment( assert response.state == environment.Environment.State.STOPPED -def test_update_environment_from_dict(): - test_update_environment(request_type=dict) - - def test_update_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1310,9 +1294,8 @@ async def test_update_environment_field_headers_async(): ] -def test_delete_environment( - transport: str = "grpc", request_type=environment.DeleteEnvironmentRequest -): +@pytest.mark.parametrize("request_type", [environment.DeleteEnvironmentRequest, dict,]) +def test_delete_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1338,10 +1321,6 @@ def test_delete_environment( assert response is None -def test_delete_environment_from_dict(): - test_delete_environment(request_type=dict) - - def test_delete_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1446,9 +1425,10 @@ async def test_delete_environment_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_get_environment_history( - transport: str = "grpc", request_type=environment.GetEnvironmentHistoryRequest -): +@pytest.mark.parametrize( + "request_type", [environment.GetEnvironmentHistoryRequest, dict,] +) +def test_get_environment_history(request_type, transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1478,10 +1458,6 @@ def test_get_environment_history( assert response.next_page_token == "next_page_token_value" -def test_get_environment_history_from_dict(): - test_get_environment_history(request_type=dict) - - def test_get_environment_history_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1595,8 +1571,10 @@ async def test_get_environment_history_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_get_environment_history_pager(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_get_environment_history_pager(transport_name: str = "grpc"): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1639,8 +1617,10 @@ def test_get_environment_history_pager(): assert all(isinstance(i, environment.EnvironmentHistory.Entry) for i in results) -def test_get_environment_history_pages(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_get_environment_history_pages(transport_name: str = "grpc"): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2317,7 +2297,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py b/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py index d5aa85a73..608b83bc1 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py @@ -240,20 +240,20 @@ def test_fulfillments_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -310,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -405,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -436,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -467,9 +467,8 @@ def test_fulfillments_client_client_options_from_dict(): ) -def test_get_fulfillment( - transport: str = "grpc", request_type=fulfillment.GetFulfillmentRequest -): +@pytest.mark.parametrize("request_type", [fulfillment.GetFulfillmentRequest, dict,]) +def test_get_fulfillment(request_type, transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -503,10 +502,6 @@ def test_get_fulfillment( assert response.enabled is True -def test_get_fulfillment_from_dict(): - test_get_fulfillment(request_type=dict) - - def test_get_fulfillment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -680,9 +675,10 @@ async def test_get_fulfillment_flattened_error_async(): ) -def test_update_fulfillment( - transport: str = "grpc", request_type=gcd_fulfillment.UpdateFulfillmentRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_fulfillment.UpdateFulfillmentRequest, dict,] +) +def test_update_fulfillment(request_type, transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -718,10 +714,6 @@ def test_update_fulfillment( assert response.enabled is True -def test_update_fulfillment_from_dict(): - test_update_fulfillment(request_type=dict) - - def test_update_fulfillment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1438,7 +1430,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_intents.py b/tests/unit/gapic/dialogflow_v2beta1/test_intents.py index 1d09e6921..4b94b8a09 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_intents.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_intents.py @@ -232,20 +232,20 @@ def test_intents_client_client_options(client_class, transport_class, transport_ # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -300,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -391,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -449,7 +449,8 @@ def test_intents_client_client_options_from_dict(): ) -def test_list_intents(transport: str = "grpc", request_type=intent.ListIntentsRequest): +@pytest.mark.parametrize("request_type", [intent.ListIntentsRequest, dict,]) +def test_list_intents(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -476,10 +477,6 @@ def test_list_intents(transport: str = "grpc", request_type=intent.ListIntentsRe assert response.next_page_token == "next_page_token_value" -def test_list_intents_from_dict(): - test_list_intents(request_type=dict) - - def test_list_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -663,8 +660,10 @@ async def test_list_intents_flattened_error_async(): ) -def test_list_intents_pager(): - client = IntentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_intents_pager(transport_name: str = "grpc"): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_intents), "__call__") as call: @@ -695,8 +694,10 @@ def test_list_intents_pager(): assert all(isinstance(i, intent.Intent) for i in results) -def test_list_intents_pages(): - client = IntentsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_intents_pages(transport_name: str = "grpc"): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_intents), "__call__") as call: @@ -777,7 +778,8 @@ async def test_list_intents_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_intent(transport: str = "grpc", request_type=intent.GetIntentRequest): +@pytest.mark.parametrize("request_type", [intent.GetIntentRequest, dict,]) +def test_get_intent(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -836,10 +838,6 @@ def test_get_intent(transport: str = "grpc", request_type=intent.GetIntentReques assert response.parent_followup_intent_name == "parent_followup_intent_name_value" -def test_get_intent_from_dict(): - test_get_intent(request_type=dict) - - def test_get_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1053,9 +1051,8 @@ async def test_get_intent_flattened_error_async(): ) -def test_create_intent( - transport: str = "grpc", request_type=gcd_intent.CreateIntentRequest -): +@pytest.mark.parametrize("request_type", [gcd_intent.CreateIntentRequest, dict,]) +def test_create_intent(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1116,10 +1113,6 @@ def test_create_intent( assert response.parent_followup_intent_name == "parent_followup_intent_name_value" -def test_create_intent_from_dict(): - test_create_intent(request_type=dict) - - def test_create_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1349,9 +1342,8 @@ async def test_create_intent_flattened_error_async(): ) -def test_update_intent( - transport: str = "grpc", request_type=gcd_intent.UpdateIntentRequest -): +@pytest.mark.parametrize("request_type", [gcd_intent.UpdateIntentRequest, dict,]) +def test_update_intent(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1412,10 +1404,6 @@ def test_update_intent( assert response.parent_followup_intent_name == "parent_followup_intent_name_value" -def test_update_intent_from_dict(): - test_update_intent(request_type=dict) - - def test_update_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1645,9 +1633,8 @@ async def test_update_intent_flattened_error_async(): ) -def test_delete_intent( - transport: str = "grpc", request_type=intent.DeleteIntentRequest -): +@pytest.mark.parametrize("request_type", [intent.DeleteIntentRequest, dict,]) +def test_delete_intent(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1671,10 +1658,6 @@ def test_delete_intent( assert response is None -def test_delete_intent_from_dict(): - test_delete_intent(request_type=dict) - - def test_delete_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1837,9 +1820,8 @@ async def test_delete_intent_flattened_error_async(): ) -def test_batch_update_intents( - transport: str = "grpc", request_type=intent.BatchUpdateIntentsRequest -): +@pytest.mark.parametrize("request_type", [intent.BatchUpdateIntentsRequest, dict,]) +def test_batch_update_intents(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1865,10 +1847,6 @@ def test_batch_update_intents( assert isinstance(response, future.Future) -def test_batch_update_intents_from_dict(): - test_batch_update_intents(request_type=dict) - - def test_batch_update_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2077,9 +2055,8 @@ async def test_batch_update_intents_flattened_error_async(): ) -def test_batch_delete_intents( - transport: str = "grpc", request_type=intent.BatchDeleteIntentsRequest -): +@pytest.mark.parametrize("request_type", [intent.BatchDeleteIntentsRequest, dict,]) +def test_batch_delete_intents(request_type, transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2105,10 +2082,6 @@ def test_batch_delete_intents( assert isinstance(response, future.Future) -def test_batch_delete_intents_from_dict(): - test_batch_delete_intents(request_type=dict) - - def test_batch_delete_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2871,7 +2844,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py b/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py index 5d5e4c785..fac7f9fe8 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py @@ -252,20 +252,20 @@ def test_knowledge_bases_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -324,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -419,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -450,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -483,9 +483,10 @@ def test_knowledge_bases_client_client_options_from_dict(): ) -def test_list_knowledge_bases( - transport: str = "grpc", request_type=knowledge_base.ListKnowledgeBasesRequest -): +@pytest.mark.parametrize( + "request_type", [knowledge_base.ListKnowledgeBasesRequest, dict,] +) +def test_list_knowledge_bases(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -514,10 +515,6 @@ def test_list_knowledge_bases( assert response.next_page_token == "next_page_token_value" -def test_list_knowledge_bases_from_dict(): - test_list_knowledge_bases(request_type=dict) - - def test_list_knowledge_bases_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -708,8 +705,10 @@ async def test_list_knowledge_bases_flattened_error_async(): ) -def test_list_knowledge_bases_pager(): - client = KnowledgeBasesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_knowledge_bases_pager(transport_name: str = "grpc"): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -754,8 +753,10 @@ def test_list_knowledge_bases_pager(): assert all(isinstance(i, knowledge_base.KnowledgeBase) for i in results) -def test_list_knowledge_bases_pages(): - client = KnowledgeBasesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_knowledge_bases_pages(transport_name: str = "grpc"): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -878,9 +879,10 @@ async def test_list_knowledge_bases_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_knowledge_base( - transport: str = "grpc", request_type=knowledge_base.GetKnowledgeBaseRequest -): +@pytest.mark.parametrize( + "request_type", [knowledge_base.GetKnowledgeBaseRequest, dict,] +) +def test_get_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -913,10 +915,6 @@ def test_get_knowledge_base( assert response.language_code == "language_code_value" -def test_get_knowledge_base_from_dict(): - test_get_knowledge_base(request_type=dict) - - def test_get_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1110,9 +1108,10 @@ async def test_get_knowledge_base_flattened_error_async(): ) -def test_create_knowledge_base( - transport: str = "grpc", request_type=gcd_knowledge_base.CreateKnowledgeBaseRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_knowledge_base.CreateKnowledgeBaseRequest, dict,] +) +def test_create_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1145,10 +1144,6 @@ def test_create_knowledge_base( assert response.language_code == "language_code_value" -def test_create_knowledge_base_from_dict(): - test_create_knowledge_base(request_type=dict) - - def test_create_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1359,9 +1354,10 @@ async def test_create_knowledge_base_flattened_error_async(): ) -def test_delete_knowledge_base( - transport: str = "grpc", request_type=knowledge_base.DeleteKnowledgeBaseRequest -): +@pytest.mark.parametrize( + "request_type", [knowledge_base.DeleteKnowledgeBaseRequest, dict,] +) +def test_delete_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1387,10 +1383,6 @@ def test_delete_knowledge_base( assert response is None -def test_delete_knowledge_base_from_dict(): - test_delete_knowledge_base(request_type=dict) - - def test_delete_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1572,9 +1564,10 @@ async def test_delete_knowledge_base_flattened_error_async(): ) -def test_update_knowledge_base( - transport: str = "grpc", request_type=gcd_knowledge_base.UpdateKnowledgeBaseRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_knowledge_base.UpdateKnowledgeBaseRequest, dict,] +) +def test_update_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1607,10 +1600,6 @@ def test_update_knowledge_base( assert response.language_code == "language_code_value" -def test_update_knowledge_base_from_dict(): - test_update_knowledge_base(request_type=dict) - - def test_update_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2355,7 +2344,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_participants.py b/tests/unit/gapic/dialogflow_v2beta1/test_participants.py index dc2bfbac6..8b8b29ffd 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_participants.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_participants.py @@ -250,20 +250,20 @@ def test_participants_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -320,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -415,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -446,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -477,9 +477,10 @@ def test_participants_client_client_options_from_dict(): ) -def test_create_participant( - transport: str = "grpc", request_type=gcd_participant.CreateParticipantRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_participant.CreateParticipantRequest, dict,] +) +def test_create_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -512,10 +513,6 @@ def test_create_participant( assert response.obfuscated_external_user_id == "obfuscated_external_user_id_value" -def test_create_participant_from_dict(): - test_create_participant(request_type=dict) - - def test_create_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -720,9 +717,8 @@ async def test_create_participant_flattened_error_async(): ) -def test_get_participant( - transport: str = "grpc", request_type=participant.GetParticipantRequest -): +@pytest.mark.parametrize("request_type", [participant.GetParticipantRequest, dict,]) +def test_get_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -753,10 +749,6 @@ def test_get_participant( assert response.obfuscated_external_user_id == "obfuscated_external_user_id_value" -def test_get_participant_from_dict(): - test_get_participant(request_type=dict) - - def test_get_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -932,9 +924,8 @@ async def test_get_participant_flattened_error_async(): ) -def test_list_participants( - transport: str = "grpc", request_type=participant.ListParticipantsRequest -): +@pytest.mark.parametrize("request_type", [participant.ListParticipantsRequest, dict,]) +def test_list_participants(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -963,10 +954,6 @@ def test_list_participants( assert response.next_page_token == "next_page_token_value" -def test_list_participants_from_dict(): - test_list_participants(request_type=dict) - - def test_list_participants_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1150,8 +1137,10 @@ async def test_list_participants_flattened_error_async(): ) -def test_list_participants_pager(): - client = ParticipantsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_participants_pager(transport_name: str = "grpc"): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1192,8 +1181,10 @@ def test_list_participants_pager(): assert all(isinstance(i, participant.Participant) for i in results) -def test_list_participants_pages(): - client = ParticipantsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_participants_pages(transport_name: str = "grpc"): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1304,9 +1295,10 @@ async def test_list_participants_async_pages(): assert page_.raw_page.next_page_token == token -def test_update_participant( - transport: str = "grpc", request_type=gcd_participant.UpdateParticipantRequest -): +@pytest.mark.parametrize( + "request_type", [gcd_participant.UpdateParticipantRequest, dict,] +) +def test_update_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1339,10 +1331,6 @@ def test_update_participant( assert response.obfuscated_external_user_id == "obfuscated_external_user_id_value" -def test_update_participant_from_dict(): - test_update_participant(request_type=dict) - - def test_update_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1551,9 +1539,8 @@ async def test_update_participant_flattened_error_async(): ) -def test_analyze_content( - transport: str = "grpc", request_type=gcd_participant.AnalyzeContentRequest -): +@pytest.mark.parametrize("request_type", [gcd_participant.AnalyzeContentRequest, dict,]) +def test_analyze_content(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1580,10 +1567,6 @@ def test_analyze_content( assert response.reply_text == "reply_text_value" -def test_analyze_content_from_dict(): - test_analyze_content(request_type=dict) - - def test_analyze_content_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1769,9 +1752,8 @@ async def test_analyze_content_flattened_error_async(): ) -def test_suggest_articles( - transport: str = "grpc", request_type=participant.SuggestArticlesRequest -): +@pytest.mark.parametrize("request_type", [participant.SuggestArticlesRequest, dict,]) +def test_suggest_articles(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1799,10 +1781,6 @@ def test_suggest_articles( assert response.context_size == 1311 -def test_suggest_articles_from_dict(): - test_suggest_articles(request_type=dict) - - def test_suggest_articles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1975,9 +1953,8 @@ async def test_suggest_articles_flattened_error_async(): ) -def test_suggest_faq_answers( - transport: str = "grpc", request_type=participant.SuggestFaqAnswersRequest -): +@pytest.mark.parametrize("request_type", [participant.SuggestFaqAnswersRequest, dict,]) +def test_suggest_faq_answers(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2007,10 +1984,6 @@ def test_suggest_faq_answers( assert response.context_size == 1311 -def test_suggest_faq_answers_from_dict(): - test_suggest_faq_answers(request_type=dict) - - def test_suggest_faq_answers_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2195,9 +2168,10 @@ async def test_suggest_faq_answers_flattened_error_async(): ) -def test_suggest_smart_replies( - transport: str = "grpc", request_type=participant.SuggestSmartRepliesRequest -): +@pytest.mark.parametrize( + "request_type", [participant.SuggestSmartRepliesRequest, dict,] +) +def test_suggest_smart_replies(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2227,10 +2201,6 @@ def test_suggest_smart_replies( assert response.context_size == 1311 -def test_suggest_smart_replies_from_dict(): - test_suggest_smart_replies(request_type=dict) - - def test_suggest_smart_replies_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2415,9 +2385,8 @@ async def test_suggest_smart_replies_flattened_error_async(): ) -def test_list_suggestions( - transport: str = "grpc", request_type=participant.ListSuggestionsRequest -): +@pytest.mark.parametrize("request_type", [participant.ListSuggestionsRequest, dict,]) +def test_list_suggestions(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2444,10 +2413,6 @@ def test_list_suggestions( assert response.next_page_token == "next_page_token_value" -def test_list_suggestions_from_dict(): - test_list_suggestions(request_type=dict) - - def test_list_suggestions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2551,8 +2516,10 @@ async def test_list_suggestions_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_suggestions_pager(): - client = ParticipantsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_suggestions_pager(transport_name: str = "grpc"): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_suggestions), "__call__") as call: @@ -2589,8 +2556,10 @@ def test_list_suggestions_pager(): assert all(isinstance(i, participant.Suggestion) for i in results) -def test_list_suggestions_pages(): - client = ParticipantsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_suggestions_pages(transport_name: str = "grpc"): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_suggestions), "__call__") as call: @@ -2689,9 +2658,8 @@ async def test_list_suggestions_async_pages(): assert page_.raw_page.next_page_token == token -def test_compile_suggestion( - transport: str = "grpc", request_type=participant.CompileSuggestionRequest -): +@pytest.mark.parametrize("request_type", [participant.CompileSuggestionRequest, dict,]) +def test_compile_suggestion(request_type, transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2721,10 +2689,6 @@ def test_compile_suggestion( assert response.context_size == 1311 -def test_compile_suggestion_from_dict(): - test_compile_suggestion(request_type=dict) - - def test_compile_suggestion_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3241,10 +3205,32 @@ def test_participants_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel -def test_context_path(): +def test_answer_record_path(): project = "squid" - session = "clam" - context = "whelk" + answer_record = "clam" + expected = "projects/{project}/answerRecords/{answer_record}".format( + project=project, answer_record=answer_record, + ) + actual = ParticipantsClient.answer_record_path(project, answer_record) + assert expected == actual + + +def test_parse_answer_record_path(): + expected = { + "project": "whelk", + "answer_record": "octopus", + } + path = ParticipantsClient.answer_record_path(**expected) + + # Check that the path construction is reversible. + actual = ParticipantsClient.parse_answer_record_path(path) + assert expected == actual + + +def test_context_path(): + project = "oyster" + session = "nudibranch" + context = "cuttlefish" expected = "projects/{project}/agent/sessions/{session}/contexts/{context}".format( project=project, session=session, context=context, ) @@ -3254,9 +3240,9 @@ def test_context_path(): def test_parse_context_path(): expected = { - "project": "octopus", - "session": "oyster", - "context": "nudibranch", + "project": "mussel", + "session": "winkle", + "context": "nautilus", } path = ParticipantsClient.context_path(**expected) @@ -3266,9 +3252,9 @@ def test_parse_context_path(): def test_document_path(): - project = "cuttlefish" - knowledge_base = "mussel" - document = "winkle" + project = "scallop" + knowledge_base = "abalone" + document = "squid" expected = "projects/{project}/knowledgeBases/{knowledge_base}/documents/{document}".format( project=project, knowledge_base=knowledge_base, document=document, ) @@ -3278,9 +3264,9 @@ def test_document_path(): def test_parse_document_path(): expected = { - "project": "nautilus", - "knowledge_base": "scallop", - "document": "abalone", + "project": "clam", + "knowledge_base": "whelk", + "document": "octopus", } path = ParticipantsClient.document_path(**expected) @@ -3290,8 +3276,8 @@ def test_parse_document_path(): def test_intent_path(): - project = "squid" - intent = "clam" + project = "oyster" + intent = "nudibranch" expected = "projects/{project}/agent/intents/{intent}".format( project=project, intent=intent, ) @@ -3301,8 +3287,8 @@ def test_intent_path(): def test_parse_intent_path(): expected = { - "project": "whelk", - "intent": "octopus", + "project": "cuttlefish", + "intent": "mussel", } path = ParticipantsClient.intent_path(**expected) @@ -3312,9 +3298,9 @@ def test_parse_intent_path(): def test_message_path(): - project = "oyster" - conversation = "nudibranch" - message = "cuttlefish" + project = "winkle" + conversation = "nautilus" + message = "scallop" expected = "projects/{project}/conversations/{conversation}/messages/{message}".format( project=project, conversation=conversation, message=message, ) @@ -3324,9 +3310,9 @@ def test_message_path(): def test_parse_message_path(): expected = { - "project": "mussel", - "conversation": "winkle", - "message": "nautilus", + "project": "abalone", + "conversation": "squid", + "message": "clam", } path = ParticipantsClient.message_path(**expected) @@ -3336,9 +3322,9 @@ def test_parse_message_path(): def test_participant_path(): - project = "scallop" - conversation = "abalone" - participant = "squid" + project = "whelk" + conversation = "octopus" + participant = "oyster" expected = "projects/{project}/conversations/{conversation}/participants/{participant}".format( project=project, conversation=conversation, participant=participant, ) @@ -3348,9 +3334,9 @@ def test_participant_path(): def test_parse_participant_path(): expected = { - "project": "clam", - "conversation": "whelk", - "participant": "octopus", + "project": "nudibranch", + "conversation": "cuttlefish", + "participant": "mussel", } path = ParticipantsClient.participant_path(**expected) @@ -3360,9 +3346,9 @@ def test_parse_participant_path(): def test_session_entity_type_path(): - project = "oyster" - session = "nudibranch" - entity_type = "cuttlefish" + project = "winkle" + session = "nautilus" + entity_type = "scallop" expected = "projects/{project}/agent/sessions/{session}/entityTypes/{entity_type}".format( project=project, session=session, entity_type=entity_type, ) @@ -3372,9 +3358,9 @@ def test_session_entity_type_path(): def test_parse_session_entity_type_path(): expected = { - "project": "mussel", - "session": "winkle", - "entity_type": "nautilus", + "project": "abalone", + "session": "squid", + "entity_type": "clam", } path = ParticipantsClient.session_entity_type_path(**expected) @@ -3384,7 +3370,7 @@ def test_parse_session_entity_type_path(): def test_common_billing_account_path(): - billing_account = "scallop" + billing_account = "whelk" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3394,7 +3380,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "abalone", + "billing_account": "octopus", } path = ParticipantsClient.common_billing_account_path(**expected) @@ -3404,7 +3390,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "squid" + folder = "oyster" expected = "folders/{folder}".format(folder=folder,) actual = ParticipantsClient.common_folder_path(folder) assert expected == actual @@ -3412,7 +3398,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "clam", + "folder": "nudibranch", } path = ParticipantsClient.common_folder_path(**expected) @@ -3422,7 +3408,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "whelk" + organization = "cuttlefish" expected = "organizations/{organization}".format(organization=organization,) actual = ParticipantsClient.common_organization_path(organization) assert expected == actual @@ -3430,7 +3416,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "octopus", + "organization": "mussel", } path = ParticipantsClient.common_organization_path(**expected) @@ -3440,7 +3426,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "oyster" + project = "winkle" expected = "projects/{project}".format(project=project,) actual = ParticipantsClient.common_project_path(project) assert expected == actual @@ -3448,7 +3434,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "nudibranch", + "project": "nautilus", } path = ParticipantsClient.common_project_path(**expected) @@ -3458,8 +3444,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "cuttlefish" - location = "mussel" + project = "scallop" + location = "abalone" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3469,8 +3455,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "winkle", - "location": "nautilus", + "project": "squid", + "location": "clam", } path = ParticipantsClient.common_location_path(**expected) @@ -3479,7 +3465,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( 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 421b212a9..e91158936 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py @@ -256,20 +256,20 @@ def test_session_entity_types_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -338,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -433,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -464,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -497,10 +497,10 @@ def test_session_entity_types_client_client_options_from_dict(): ) -def test_list_session_entity_types( - transport: str = "grpc", - request_type=session_entity_type.ListSessionEntityTypesRequest, -): +@pytest.mark.parametrize( + "request_type", [session_entity_type.ListSessionEntityTypesRequest, dict,] +) +def test_list_session_entity_types(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -529,10 +529,6 @@ def test_list_session_entity_types( assert response.next_page_token == "next_page_token_value" -def test_list_session_entity_types_from_dict(): - test_list_session_entity_types(request_type=dict) - - def test_list_session_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -729,8 +725,10 @@ async def test_list_session_entity_types_flattened_error_async(): ) -def test_list_session_entity_types_pager(): - client = SessionEntityTypesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_session_entity_types_pager(transport_name: str = "grpc"): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -777,8 +775,10 @@ def test_list_session_entity_types_pager(): ) -def test_list_session_entity_types_pages(): - client = SessionEntityTypesClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_session_entity_types_pages(transport_name: str = "grpc"): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -907,10 +907,10 @@ async def test_list_session_entity_types_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_session_entity_type( - transport: str = "grpc", - request_type=session_entity_type.GetSessionEntityTypeRequest, -): +@pytest.mark.parametrize( + "request_type", [session_entity_type.GetSessionEntityTypeRequest, dict,] +) +def test_get_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -944,10 +944,6 @@ def test_get_session_entity_type( ) -def test_get_session_entity_type_from_dict(): - test_get_session_entity_type(request_type=dict) - - def test_get_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1149,10 +1145,10 @@ async def test_get_session_entity_type_flattened_error_async(): ) -def test_create_session_entity_type( - transport: str = "grpc", - request_type=gcd_session_entity_type.CreateSessionEntityTypeRequest, -): +@pytest.mark.parametrize( + "request_type", [gcd_session_entity_type.CreateSessionEntityTypeRequest, dict,] +) +def test_create_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1186,10 +1182,6 @@ def test_create_session_entity_type( ) -def test_create_session_entity_type_from_dict(): - test_create_session_entity_type(request_type=dict) - - def test_create_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1415,10 +1407,10 @@ async def test_create_session_entity_type_flattened_error_async(): ) -def test_update_session_entity_type( - transport: str = "grpc", - request_type=gcd_session_entity_type.UpdateSessionEntityTypeRequest, -): +@pytest.mark.parametrize( + "request_type", [gcd_session_entity_type.UpdateSessionEntityTypeRequest, dict,] +) +def test_update_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1452,10 +1444,6 @@ def test_update_session_entity_type( ) -def test_update_session_entity_type_from_dict(): - test_update_session_entity_type(request_type=dict) - - def test_update_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1687,10 +1675,10 @@ async def test_update_session_entity_type_flattened_error_async(): ) -def test_delete_session_entity_type( - transport: str = "grpc", - request_type=session_entity_type.DeleteSessionEntityTypeRequest, -): +@pytest.mark.parametrize( + "request_type", [session_entity_type.DeleteSessionEntityTypeRequest, dict,] +) +def test_delete_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1716,10 +1704,6 @@ def test_delete_session_entity_type( assert response is None -def test_delete_session_entity_type_from_dict(): - test_delete_session_entity_type(request_type=dict) - - def test_delete_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2443,7 +2427,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py b/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py index 0095c44db..aa54c83dd 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py @@ -238,20 +238,20 @@ def test_sessions_client_client_options(client_class, transport_class, transport # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -308,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -399,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -426,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -457,9 +457,8 @@ def test_sessions_client_client_options_from_dict(): ) -def test_detect_intent( - transport: str = "grpc", request_type=gcd_session.DetectIntentRequest -): +@pytest.mark.parametrize("request_type", [gcd_session.DetectIntentRequest, dict,]) +def test_detect_intent(request_type, transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -487,10 +486,6 @@ def test_detect_intent( assert response.output_audio == b"output_audio_blob" -def test_detect_intent_from_dict(): - test_detect_intent(request_type=dict) - - def test_detect_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -703,9 +698,8 @@ async def test_detect_intent_flattened_error_async(): ) -def test_streaming_detect_intent( - transport: str = "grpc", request_type=session.StreamingDetectIntentRequest -): +@pytest.mark.parametrize("request_type", [session.StreamingDetectIntentRequest, dict,]) +def test_streaming_detect_intent(request_type, transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -733,10 +727,6 @@ def test_streaming_detect_intent( assert isinstance(message, session.StreamingDetectIntentResponse) -def test_streaming_detect_intent_from_dict(): - test_streaming_detect_intent(request_type=dict) - - @pytest.mark.asyncio async def test_streaming_detect_intent_async( transport: str = "grpc_asyncio", request_type=session.StreamingDetectIntentRequest @@ -1378,7 +1368,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/dialogflow_v2beta1/test_versions.py b/tests/unit/gapic/dialogflow_v2beta1/test_versions.py index a4fa212bf..2e20752cd 100644 --- a/tests/unit/gapic/dialogflow_v2beta1/test_versions.py +++ b/tests/unit/gapic/dialogflow_v2beta1/test_versions.py @@ -232,20 +232,20 @@ def test_versions_client_client_options(client_class, transport_class, transport # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -302,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -393,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -420,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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -451,9 +451,8 @@ def test_versions_client_client_options_from_dict(): ) -def test_list_versions( - transport: str = "grpc", request_type=version.ListVersionsRequest -): +@pytest.mark.parametrize("request_type", [version.ListVersionsRequest, dict,]) +def test_list_versions(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -480,10 +479,6 @@ def test_list_versions( assert response.next_page_token == "next_page_token_value" -def test_list_versions_from_dict(): - test_list_versions(request_type=dict) - - def test_list_versions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -653,8 +648,10 @@ async def test_list_versions_flattened_error_async(): ) -def test_list_versions_pager(): - client = VersionsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_versions_pager(transport_name: str = "grpc"): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_versions), "__call__") as call: @@ -687,8 +684,10 @@ def test_list_versions_pager(): assert all(isinstance(i, version.Version) for i in results) -def test_list_versions_pages(): - client = VersionsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_versions_pages(transport_name: str = "grpc"): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_versions), "__call__") as call: @@ -775,7 +774,8 @@ async def test_list_versions_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_version(transport: str = "grpc", request_type=version.GetVersionRequest): +@pytest.mark.parametrize("request_type", [version.GetVersionRequest, dict,]) +def test_get_version(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -808,10 +808,6 @@ def test_get_version(transport: str = "grpc", request_type=version.GetVersionReq assert response.status == version.Version.VersionStatus.IN_PROGRESS -def test_get_version_from_dict(): - test_get_version(request_type=dict) - - def test_get_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -985,9 +981,8 @@ async def test_get_version_flattened_error_async(): ) -def test_create_version( - transport: str = "grpc", request_type=gcd_version.CreateVersionRequest -): +@pytest.mark.parametrize("request_type", [gcd_version.CreateVersionRequest, dict,]) +def test_create_version(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1020,10 +1015,6 @@ def test_create_version( assert response.status == gcd_version.Version.VersionStatus.IN_PROGRESS -def test_create_version_from_dict(): - test_create_version(request_type=dict) - - def test_create_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1211,9 +1202,8 @@ async def test_create_version_flattened_error_async(): ) -def test_update_version( - transport: str = "grpc", request_type=gcd_version.UpdateVersionRequest -): +@pytest.mark.parametrize("request_type", [gcd_version.UpdateVersionRequest, dict,]) +def test_update_version(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1246,10 +1236,6 @@ def test_update_version( assert response.status == gcd_version.Version.VersionStatus.IN_PROGRESS -def test_update_version_from_dict(): - test_update_version(request_type=dict) - - def test_update_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1443,9 +1429,8 @@ async def test_update_version_flattened_error_async(): ) -def test_delete_version( - transport: str = "grpc", request_type=version.DeleteVersionRequest -): +@pytest.mark.parametrize("request_type", [version.DeleteVersionRequest, dict,]) +def test_delete_version(request_type, transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1469,10 +1454,6 @@ def test_delete_version( assert response is None -def test_delete_version_from_dict(): - test_delete_version(request_type=dict) - - def test_delete_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2146,7 +2127,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object(