Skip to content

Commit

Permalink
Remove 'Connection.delete_entity' API.
Browse files Browse the repository at this point in the history
Fixes #169.
  • Loading branch information
tseaver committed Oct 17, 2014
1 parent 64c711e commit 94e606b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 92 deletions.
22 changes: 0 additions & 22 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,25 +411,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])
6 changes: 4 additions & 2 deletions gcloud/datastore/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,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:
Expand Down
65 changes: 0 additions & 65 deletions gcloud/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,71 +790,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')
self.assertEqual(cw['headers'],
{'Content-Type': 'application/x-protobuf',
'Content-Length': '30',
'User-Agent': conn.USER_AGENT,
})
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):

Expand Down
6 changes: 3 additions & 3 deletions gcloud/datastore/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -262,8 +262,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):
Expand Down

0 comments on commit 94e606b

Please sign in to comment.