示例#1
0
    def delete_document(self, name, current_document=None, options=None):
        """
        Deletes a document.

        Example:
            >>> from google.cloud import firestore_v1beta1
            >>>
            >>> client = firestore_v1beta1.FirestoreClient()
            >>>
            >>> name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]')
            >>>
            >>> client.delete_document(name)

        Args:
            name (str): The resource name of the Document to delete. In the format:
                ``projects/{project_id}/databases/{database_id}/documents/{document_path}``.
            current_document (Union[dict, ~google.cloud.firestore_v1beta1.types.Precondition]): An optional precondition on the document.
                The request will fail if this is set and not met by the target document.
                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.firestore_v1beta1.types.Precondition`
            options (~google.gax.CallOptions): Overrides the default
                settings for this call, e.g, timeout, retries etc.

        Raises:
            :exc:`google.gax.errors.GaxError` if the RPC is aborted.
            :exc:`ValueError` if the parameters are invalid.
        """
        request = firestore_pb2.DeleteDocumentRequest(
            name=name, current_document=current_document)
        self._delete_document(request, options)
示例#2
0
    def test_delete_document(self):
        channel = ChannelStub()
        client = firestore_client.FirestoreClient(channel=channel)

        # Setup Request
        name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]',
                                    '[ANY_PATH]')

        client.delete_document(name)

        assert len(channel.requests) == 1
        expected_request = firestore_pb2.DeleteDocumentRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_delete_document(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = firestore_client.FirestoreClient()

        # Setup Request
        name = "name3373707"

        client.delete_document(name)

        assert len(channel.requests) == 1
        expected_request = firestore_pb2.DeleteDocumentRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
示例#4
0
    def test_delete_document(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = firestore_client.FirestoreClient()

        # Setup Request
        name = client.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]",
                                    "[ANY_PATH]")

        client.delete_document(name)

        assert len(channel.requests) == 1
        expected_request = firestore_pb2.DeleteDocumentRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
示例#5
0
    def test_delete_document(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = firestore_client.FirestoreClient()

        # Mock request
        name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]',
                                    '[ANY_PATH]')

        client.delete_document(name)

        grpc_stub.DeleteDocument.assert_called_once()
        args, kwargs = grpc_stub.DeleteDocument.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = firestore_pb2.DeleteDocumentRequest(name=name)
        self.assertEqual(expected_request, actual_request)