def test_reload_document(self):
        # Setup Expected Response
        name = "name3373707"
        done = True
        expected_response = {"name": name, "done": done}
        expected_response = operations_pb2.Operation(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.DocumentsClient()

        response = client.reload_document()
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = document_pb2.ReloadDocumentRequest()
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_reload_document(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        display_name = "displayName1615086568"
        mime_type = "mimeType-196041627"
        content_uri = "contentUri-388807514"
        enable_auto_reload = False
        expected_response = {
            "name": name_2,
            "display_name": display_name,
            "mime_type": mime_type,
            "content_uri": content_uri,
            "enable_auto_reload": enable_auto_reload,
        }
        expected_response = document_pb2.Document(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_reload_document", done=True)
        operation.response.Pack(expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.DocumentsClient()

        # Setup Request
        name = client.document_path("[PROJECT]", "[KNOWLEDGE_BASE]",
                                    "[DOCUMENT]")

        response = client.reload_document(name)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = document_pb2.ReloadDocumentRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def reload_document(
        self,
        name=None,
        gcs_source=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Reloads the specified document from its specified source,
        content_uri or content. The previously loaded content of the document
        will be deleted. Note: Even when the content of the document has not
        changed, there still may be side effects because of internal
        implementation changes.

        Note: The ``projects.agent.knowledgeBases.documents`` resource is
        deprecated; only use ``projects.knowledgeBases.documents``.

        Example:
            >>> import dialogflow_v2beta1
            >>>
            >>> client = dialogflow_v2beta1.DocumentsClient()
            >>>
            >>> name = client.document_path('[PROJECT]', '[KNOWLEDGE_BASE]', '[DOCUMENT]')
            >>>
            >>> response = client.reload_document(name)
            >>>
            >>> def callback(operation_future):
            ...     # Handle result.
            ...     result = operation_future.result()
            >>>
            >>> response.add_done_callback(callback)
            >>>
            >>> # Handle metadata.
            >>> metadata = response.metadata()

        Args:
            name (str): Required. The name of the document to reload. Format:
                ``projects/<Project ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>``
            gcs_source (Union[dict, ~google.cloud.dialogflow_v2beta1.types.GcsSource]): The path for a Cloud Storage source file for reloading document content.
                If not provided, the Document's existing source will be reloaded.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.dialogflow_v2beta1.types.GcsSource`
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will
                be retried using a default configuration.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.dialogflow_v2beta1.types._OperationFuture` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "reload_document" not in self._inner_api_calls:
            self._inner_api_calls[
                "reload_document"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.reload_document,
                    default_retry=self._method_configs["ReloadDocument"].retry,
                    default_timeout=self._method_configs["ReloadDocument"].
                    timeout,
                    client_info=self._client_info,
                )

        # Sanity check: We have some fields which are mutually exclusive;
        # raise ValueError if more than one is sent.
        google.api_core.protobuf_helpers.check_oneof(gcs_source=gcs_source)

        request = document_pb2.ReloadDocumentRequest(name=name,
                                                     gcs_source=gcs_source)
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("name", name)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header)
            metadata.append(routing_metadata)

        operation = self._inner_api_calls["reload_document"](request,
                                                             retry=retry,
                                                             timeout=timeout,
                                                             metadata=metadata)
        return google.api_core.operation.from_gapic(
            operation,
            self.transport._operations_client,
            document_pb2.Document,
            metadata_type=document_pb2.KnowledgeOperationMetadata,
        )
Esempio n. 4
0
    def reload_document(self,
                        name=None,
                        retry=google.api_core.gapic_v1.method.DEFAULT,
                        timeout=google.api_core.gapic_v1.method.DEFAULT,
                        metadata=None):
        """
        Reloads the specified document from its specified source, content\_uri
        or content. The previously loaded content of the document will be
        deleted. Note: Even when the content of the document has not changed,
        there still may be side effects because of internal implementation
        changes. Operation <response: ``Document``, metadata:
        ``KnowledgeOperationMetadata``>

        Example:
            >>> import dialogflow_v2beta1
            >>>
            >>> client = dialogflow_v2beta1.DocumentsClient()
            >>>
            >>> response = client.reload_document()

        Args:
            name (str): The name of the document to reload. Format:
                ``projects/<Project ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>``
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.dialogflow_v2beta1.types.Operation` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if 'reload_document' not in self._inner_api_calls:
            self._inner_api_calls[
                'reload_document'] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.reload_document,
                    default_retry=self._method_configs['ReloadDocument'].retry,
                    default_timeout=self._method_configs['ReloadDocument'].
                    timeout,
                    client_info=self._client_info,
                )

        request = document_pb2.ReloadDocumentRequest(name=name, )
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [('name', name)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header)
            metadata.append(routing_metadata)

        return self._inner_api_calls['reload_document'](request,
                                                        retry=retry,
                                                        timeout=timeout,
                                                        metadata=metadata)