From a43d1e92c86c87645c73a91a5c1593412bd3018d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 22 Dec 2021 20:08:10 +0000 Subject: [PATCH] feat(v2): added export documentation method (#449) - [x] Regenerate this pull request now. PiperOrigin-RevId: 417030293 Source-Link: https://github.com/googleapis/googleapis/commit/ebef8e6c5ad95fcaa306935565086bed4ffbf663 Source-Link: https://github.com/googleapis/googleapis-gen/commit/13951268b009d98d82355ccd9647f4350590609d Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTM5NTEyNjhiMDA5ZDk4ZDgyMzU1Y2NkOTY0N2Y0MzUwNTkwNjA5ZCJ9 feat(v2): added filter in list documentations request feat(v2): added option to import custom metadata from Google Cloud Storage in reload document request feat(v2): added option to apply partial update to the smart messaging allowlist in reload document request feat(v2): added filter in list knowledge bases request --- google/cloud/dialogflow/__init__.py | 4 + google/cloud/dialogflow_v2/__init__.py | 4 + .../cloud/dialogflow_v2/gapic_metadata.json | 10 ++ .../services/documents/async_client.py | 78 +++++++++++ .../services/documents/client.py | 79 +++++++++++ .../services/documents/transports/base.py | 12 ++ .../services/documents/transports/grpc.py | 36 +++++ .../documents/transports/grpc_asyncio.py | 38 +++++ google/cloud/dialogflow_v2/types/__init__.py | 4 + google/cloud/dialogflow_v2/types/document.py | 69 +++++++++ google/cloud/dialogflow_v2/types/gcs.py | 21 ++- .../dialogflow_v2/types/knowledge_base.py | 30 ++++ scripts/fixup_dialogflow_v2_keywords.py | 7 +- .../gapic/dialogflow_v2/test_documents.py | 132 ++++++++++++++++++ 14 files changed, 520 insertions(+), 4 deletions(-) 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/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..c3f70ac35 100644 --- a/google/cloud/dialogflow_v2/services/documents/transports/base.py +++ b/google/cloud/dialogflow_v2/services/documents/transports/base.py @@ -145,6 +145,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 +220,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/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/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/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/tests/unit/gapic/dialogflow_v2/test_documents.py b/tests/unit/gapic/dialogflow_v2/test_documents.py index 842f8581d..d32bdafa0 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 @@ -1862,6 +1863,136 @@ async def test_reload_document_flattened_error_async(): ) +def test_export_document( + transport: str = "grpc", request_type=document.ExportDocumentRequest +): + 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_from_dict(): + test_export_document(request_type=dict) + + +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 +2093,7 @@ def test_documents_base_transport(): "delete_document", "update_document", "reload_document", + "export_document", ) for method in methods: with pytest.raises(NotImplementedError):