From 16738fec0c910ef3f115fb8014d836328bc6650f Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 17 Oct 2014 11:36:57 -0400 Subject: [PATCH] Remove 'Connection.delete_entity' API. Fixes #169. --- gcloud/datastore/connection.py | 22 ---------- gcloud/datastore/entity.py | 6 ++- gcloud/datastore/test_connection.py | 67 ----------------------------- gcloud/datastore/test_entity.py | 6 +-- 4 files changed, 7 insertions(+), 94 deletions(-) diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py index c2ead0315f40..c87fbd5a75ed 100644 --- a/gcloud/datastore/connection.py +++ b/gcloud/datastore/connection.py @@ -418,25 +418,3 @@ def delete_entities(self, dataset_id, key_pbs): 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. - - :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]) diff --git a/gcloud/datastore/entity.py b/gcloud/datastore/entity.py index 4171408345e8..e992a8018379 100644 --- 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: diff --git a/gcloud/datastore/test_connection.py b/gcloud/datastore/test_connection.py index 9ad853bf3a56..f1a9fc6dbb6a 100644 --- a/gcloud/datastore/test_connection.py +++ b/gcloud/datastore/test_connection.py @@ -825,73 +825,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 index 89e56e813e20..1d67001b4ab9 100644 --- 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):