Repository: googleapis/google-cloud-python

Issue:
In datastore.connection.Connection.delete_entities, make return values consistent with one another
From TODO:

``` python
    # TODO: Make this return value be a True/False (or something more useful).
```

See [`datastore.connection.Connection.delete_entities`](https://github.com/GoogleCloudPlatform/gcloud-python/blob/1f2aaf3606802f4f02eeb30e22e1082ef7f4594e/gcloud/datastore/connection.py#L380) for relevant code and #146 for some context.

`git blame` output

```
dec0e7c6 (JJ Geewax 2014-01-28 15:15:40 -0500 380)     # TODO: Make this return value be a True/False (or something more useful).
```

In datastore.connection.Connection.delete_entities, make return values consistent with one another
From TODO:

``` python
    # TODO: Make this return value be a True/False (or something more useful).
```

See [`datastore.connection.Connection.delete_entities`](https://github.com/GoogleCloudPlatform/gcloud-python/blob/1f2aaf3606802f4f02eeb30e22e1082ef7f4594e/gcloud/datastore/connection.py#L380) for relevant code and #146 for some context.

`git blame` output

```
dec0e7c6 (JJ Geewax 2014-01-28 15:15:40 -0500 380)     # TODO: Make this return value be a True/False (or something more useful).
```



Discussion:

Resolving patch:
diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py
--- a/gcloud/datastore/connection.py
+++ b/gcloud/datastore/connection.py
@@ -405,8 +405,7 @@ def delete_entities(self, dataset_id, key_pbs):
 
         :rtype: boolean (if in a transaction) or else
                 :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
-        :returns: True (if in a transaction) or else a mutation result
-                  protobuf.
+        :returns: True
         """
         mutation = self.mutation()
 
@@ -414,29 +413,7 @@ def delete_entities(self, dataset_id, key_pbs):
             delete = mutation.delete.add()
             delete.CopyFrom(key_pb)
 
-        if self.transaction():
-            return True
-        else:
-            return self.commit(dataset_id, mutation)
-
-    def delete_entity(self, dataset_id, key_pb):
-        """Delete a single key from a dataset in the Cloud Datastore.
-
-        This method deals only with
-        :class:`gcloud.datastore.datastore_v1_pb2.Key` protobufs
-        and not with any of the other abstractions.
-        For example, it's used under the hood in the
-        :func:`gcloud.datastore.entity.Entity.delete` method.
-
-        :type dataset_id: string
-        :param dataset_id: The dataset from which to delete the key.
-
-        :type key_pb: :class:`gcloud.datastore.datastore_v1_pb2.Key`
-        :param key_pb: The key to delete from the datastore.
+        if not self.transaction():
+            self.commit(dataset_id, mutation)
 
-        :rtype: boolean (if in a transaction) or else
-                :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
-        :returns: True (if in a transaction) or else a mutation result
-                  protobuf.
-        """
-        return self.delete_entities(dataset_id, [key_pb])
+        return True
diff --git a/gcloud/datastore/entity.py b/gcloud/datastore/entity.py
--- a/gcloud/datastore/entity.py
+++ b/gcloud/datastore/entity.py
@@ -242,8 +242,10 @@ def delete(self):
         """
         key = self._must_key
         dataset = key.dataset()
-        dataset.connection().delete_entity(
-            dataset_id=dataset.id(), key_pb=key.to_protobuf())
+        dataset.connection().delete_entities(
+            dataset_id=dataset.id(),
+            key_pbs=[key.to_protobuf()],
+            )
 
     def __repr__(self):
         if self._key:


Test patch:
diff --git a/gcloud/datastore/test_connection.py b/gcloud/datastore/test_connection.py
--- a/gcloud/datastore/test_connection.py
+++ b/gcloud/datastore/test_connection.py
@@ -778,8 +778,7 @@ def test_delete_entities_wo_transaction(self):
         ])
         http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
         result = conn.delete_entities(DATASET_ID, [key_pb])
-        self.assertEqual(result.index_updates, 0)
-        self.assertEqual(list(result.insert_auto_id_key), [])
+        self.assertEqual(result, True)
         cw = http._called_with
         self.assertEqual(cw['uri'], URI)
         self.assertEqual(cw['method'], 'POST')
@@ -825,73 +824,6 @@ def mutation(self):
         mutation = conn.mutation()
         self.assertEqual(len(mutation.delete), 1)
 
-    def test_delete_entity_wo_transaction(self):
-        from gcloud.datastore.connection import datastore_pb
-        from gcloud.datastore.dataset import Dataset
-        from gcloud.datastore.key import Key
-
-        DATASET_ID = 'DATASET'
-        key_pb = Key(dataset=Dataset(DATASET_ID),
-                     path=[{'kind': 'Kind', 'id': 1234}]).to_protobuf()
-        rsp_pb = datastore_pb.CommitResponse()
-        conn = self._makeOne()
-        URI = '/'.join([
-            conn.API_BASE_URL,
-            'datastore',
-            conn.API_VERSION,
-            'datasets',
-            DATASET_ID,
-            'commit',
-        ])
-        http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
-        result = conn.delete_entity(DATASET_ID, key_pb)
-        self.assertEqual(result.index_updates, 0)
-        self.assertEqual(list(result.insert_auto_id_key), [])
-        cw = http._called_with
-        self.assertEqual(cw['uri'], URI)
-        self.assertEqual(cw['method'], 'POST')
-        expected_headers = {
-            'Content-Type': 'application/x-protobuf',
-            'Content-Length': '30',
-            'User-Agent': conn.USER_AGENT,
-        }
-        self.assertEqual(cw['headers'], expected_headers)
-        rq_class = datastore_pb.CommitRequest
-        request = rq_class()
-        request.ParseFromString(cw['body'])
-        self.assertEqual(request.transaction, '')
-        mutation = request.mutation
-        self.assertEqual(len(mutation.insert_auto_id), 0)
-        self.assertEqual(len(mutation.upsert), 0)
-        deletes = list(mutation.delete)
-        self.assertEqual(len(deletes), 1)
-        delete = deletes[0]
-        self.assertEqual(delete, key_pb)
-        self.assertEqual(request.mode, rq_class.NON_TRANSACTIONAL)
-
-    def test_delete_entity_w_transaction(self):
-        from gcloud.datastore.connection import datastore_pb
-        from gcloud.datastore.dataset import Dataset
-        from gcloud.datastore.key import Key
-
-        mutation = datastore_pb.Mutation()
-
-        class Xact(object):
-            def mutation(self):
-                return mutation
-        DATASET_ID = 'DATASET'
-        key_pb = Key(dataset=Dataset(DATASET_ID),
-                     path=[{'kind': 'Kind', 'id': 1234}]).to_protobuf()
-        rsp_pb = datastore_pb.CommitResponse()
-        conn = self._makeOne()
-        conn.transaction(Xact())
-        http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
-        result = conn.delete_entity(DATASET_ID, key_pb)
-        self.assertEqual(result, True)
-        self.assertEqual(http._called_with, None)
-        mutation = conn.mutation()
-        self.assertEqual(len(mutation.delete), 1)
-
 
 class Http(object):
 
diff --git a/gcloud/datastore/test_entity.py b/gcloud/datastore/test_entity.py
--- a/gcloud/datastore/test_entity.py
+++ b/gcloud/datastore/test_entity.py
@@ -196,7 +196,7 @@ def test_delete(self):
         entity.key(key)
         entity['foo'] = 'Foo'
         self.assertTrue(entity.delete() is None)
-        self.assertEqual(connection._deleted, (_DATASET_ID, 'KEY'))
+        self.assertEqual(connection._deleted, (_DATASET_ID, ['KEY']))
 
     def test___repr___no_key_empty(self):
         entity = self._makeOne(None, None)
@@ -264,8 +264,8 @@ def save_entity(self, dataset_id, key_pb, properties):
         self._saved = (dataset_id, key_pb, properties)
         return self._save_result
 
-    def delete_entity(self, dataset_id, key_pb):
-        self._deleted = (dataset_id, key_pb)
+    def delete_entities(self, dataset_id, key_pbs):
+        self._deleted = (dataset_id, key_pbs)
 
 
 class _Transaction(object):