def test_update_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.update_document()
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = document_pb2.UpdateDocumentRequest()
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_update_document(self):
        # Setup Expected Response
        name = "name3373707"
        display_name = "displayName1615086568"
        mime_type = "mimeType-196041627"
        content_uri = "contentUri-388807514"
        enable_auto_reload = False
        expected_response = {
            "name": name,
            "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_update_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
        document = {}

        response = client.update_document(document)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = document_pb2.UpdateDocumentRequest(
            document=document)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def update_document(
        self,
        document,
        update_mask=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Updates the specified document.

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

        Example:
            >>> import dialogflow_v2beta1
            >>>
            >>> client = dialogflow_v2beta1.DocumentsClient()
            >>>
            >>> # TODO: Initialize `document`:
            >>> document = {}
            >>>
            >>> response = client.update_document(document)
            >>>
            >>> def callback(operation_future):
            ...     # Handle result.
            ...     result = operation_future.result()
            >>>
            >>> response.add_done_callback(callback)
            >>>
            >>> # Handle metadata.
            >>> metadata = response.metadata()

        Args:
            document (Union[dict, ~google.cloud.dialogflow_v2beta1.types.Document]): Required. The document to update.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.dialogflow_v2beta1.types.Document`
            update_mask (Union[dict, ~google.cloud.dialogflow_v2beta1.types.FieldMask]): Optional. Not specified means ``update all``. Currently, only
                ``display_name`` can be updated, an InvalidArgument will be returned for
                attempting to update other fields.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.dialogflow_v2beta1.types.FieldMask`
            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 "update_document" not in self._inner_api_calls:
            self._inner_api_calls[
                "update_document"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.update_document,
                    default_retry=self._method_configs["UpdateDocument"].retry,
                    default_timeout=self._method_configs["UpdateDocument"].
                    timeout,
                    client_info=self._client_info,
                )

        request = document_pb2.UpdateDocumentRequest(document=document,
                                                     update_mask=update_mask)
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("document.name", document.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["update_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,
        )
Exemple #4
0
    def update_document(self,
                        document=None,
                        update_mask=None,
                        retry=google.api_core.gapic_v1.method.DEFAULT,
                        timeout=google.api_core.gapic_v1.method.DEFAULT,
                        metadata=None):
        """
        Updates the specified document. Operation <response: ``Document``,
        metadata: ``KnowledgeOperationMetadata``>

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

        Args:
            document (Union[dict, ~google.cloud.dialogflow_v2beta1.types.Document]): Required. The document to update.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.dialogflow_v2beta1.types.Document`
            update_mask (Union[dict, ~google.cloud.dialogflow_v2beta1.types.FieldMask]): Optional. Not specified means ``update all``. Currently, only
                ``display_name`` can be updated, an InvalidArgument will be returned for
                attempting to update other fields.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.dialogflow_v2beta1.types.FieldMask`
            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 'update_document' not in self._inner_api_calls:
            self._inner_api_calls[
                'update_document'] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.update_document,
                    default_retry=self._method_configs['UpdateDocument'].retry,
                    default_timeout=self._method_configs['UpdateDocument'].
                    timeout,
                    client_info=self._client_info,
                )

        request = document_pb2.UpdateDocumentRequest(
            document=document,
            update_mask=update_mask,
        )
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [('document.name', document.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['update_document'](request,
                                                        retry=retry,
                                                        timeout=timeout,
                                                        metadata=metadata)