Skip to content

Commit

Permalink
Renaming datastore.api.get_entities to get.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jan 8, 2015
1 parent ae463f9 commit 6eaa636
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gcloud/datastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from gcloud import credentials
from gcloud.datastore import _implicit_environ
from gcloud.datastore.api import allocate_ids
from gcloud.datastore.api import get_entities
from gcloud.datastore.api import get
from gcloud.datastore.connection import Connection


Expand Down
5 changes: 2 additions & 3 deletions gcloud/datastore/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _require_connection(connection=None):
return connection


def get_entities(keys, missing=None, deferred=None, connection=None):
def get(keys, missing=None, deferred=None, connection=None):
"""Retrieves entities, along with their attributes.
:type keys: list of :class:`gcloud.datastore.key.Key`
Expand Down Expand Up @@ -92,8 +92,7 @@ def get_entities(keys, missing=None, deferred=None, connection=None):
# or if we made sure that a prefix s~ or e~ was on each key.
for key in keys[1:]:
if key.dataset_id != dataset_id:
raise ValueError('All keys in get_entities must be from the '
'same dataset.')
raise ValueError('All keys in get must be from the same dataset.')

entity_pbs = connection.lookup(
dataset_id=dataset_id,
Expand Down
8 changes: 4 additions & 4 deletions gcloud/datastore/demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
toy.save()

# If we look it up by its key, we should find it...
from gcloud.datastore import get_entities
print(get_entities([toy.key]))
from gcloud.datastore import get
print(get([toy.key]))

# And we should be able to delete it...
toy.key.delete()

# Since we deleted it, if we do another lookup it shouldn't be there again:
print(get_entities([toy.key]))
print(get([toy.key]))

# Now let's try a more advanced query.
# First, let's create some entities.
Expand Down Expand Up @@ -104,7 +104,7 @@
t.rollback()

# Let's check if the entity was actually created:
created = get_entities([key])
created = get([key])
print('yes' if created else 'no')

# Remember, a key won't be complete until the transaction is commited.
Expand Down
2 changes: 1 addition & 1 deletion gcloud/datastore/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def get(self, connection=None):

# We allow partial keys to attempt a get, the backend will fail.
connection = connection or _implicit_environ.CONNECTION
entities = api.get_entities([self], connection=connection)
entities = api.get([self], connection=connection)

if entities:
result = entities[0]
Expand Down
26 changes: 13 additions & 13 deletions gcloud/datastore/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ def test__require_connection_implicit_set_passed_explicitly(self):
self.assertTrue(self._callFUT(CONNECTION) is CONNECTION)


class Test_get_entities_function(unittest2.TestCase):
class Test_get_function(unittest2.TestCase):

def _callFUT(self, keys, missing=None, deferred=None, connection=None):
from gcloud.datastore import get_entities
return get_entities(keys, missing=missing, deferred=deferred,
connection=connection)
from gcloud.datastore.api import get
return get(keys, missing=missing, deferred=deferred,
connection=connection)

def test_get_entities_no_keys(self):
def test_get_no_keys(self):
results = self._callFUT([])
self.assertEqual(results, [])

def test_get_entities_miss(self):
def test_get_miss(self):
from gcloud.datastore.key import Key
from gcloud.datastore.test_connection import _Connection

Expand All @@ -111,7 +111,7 @@ def test_get_entities_miss(self):
results = self._callFUT([key], connection=connection)
self.assertEqual(results, [])

def test_get_entities_miss_w_missing(self):
def test_get_miss_w_missing(self):
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
from gcloud.datastore.key import Key
from gcloud.datastore.test_connection import _Connection
Expand All @@ -138,7 +138,7 @@ def test_get_entities_miss_w_missing(self):
self.assertEqual([missed.key.to_protobuf() for missed in missing],
[key.to_protobuf()])

def test_get_entities_miss_w_deferred(self):
def test_get_miss_w_deferred(self):
from gcloud.datastore.key import Key
from gcloud.datastore.test_connection import _Connection

Expand Down Expand Up @@ -172,7 +172,7 @@ def _make_entity_pb(self, dataset_id, kind, integer_id,

return entity_pb

def test_get_entities_hit(self):
def test_get_hit(self):
from gcloud.datastore.key import Key
from gcloud.datastore.test_connection import _Connection

Expand All @@ -199,7 +199,7 @@ def test_get_entities_hit(self):
self.assertEqual(list(result), ['foo'])
self.assertEqual(result['foo'], 'Foo')

def test_get_entities_hit_multiple_keys_same_dataset(self):
def test_get_hit_multiple_keys_same_dataset(self):
from gcloud.datastore.key import Key
from gcloud.datastore.test_connection import _Connection

Expand All @@ -226,7 +226,7 @@ def test_get_entities_hit_multiple_keys_same_dataset(self):
self.assertEqual(retrieved2.key.path, key2.path)
self.assertEqual(dict(retrieved2), {})

def test_get_entities_hit_multiple_keys_different_dataset(self):
def test_get_hit_multiple_keys_different_dataset(self):
from gcloud.datastore.key import Key

DATASET_ID1 = 'DATASET'
Expand All @@ -240,7 +240,7 @@ def test_get_entities_hit_multiple_keys_different_dataset(self):
with self.assertRaises(ValueError):
self._callFUT([key1, key2], connection=object())

def test_get_entities_implicit(self):
def test_get_implicit(self):
from gcloud.datastore import _implicit_environ
from gcloud.datastore.key import Key
from gcloud.datastore.test_connection import _Connection
Expand Down Expand Up @@ -281,7 +281,7 @@ def test_get_entities_implicit(self):
class Test_allocate_ids_function(unittest2.TestCase):

def _callFUT(self, incomplete_key, num_ids, connection=None):
from gcloud.datastore import allocate_ids
from gcloud.datastore.api import allocate_ids
return allocate_ids(incomplete_key, num_ids, connection=connection)

def test_allocate_ids(self):
Expand Down
2 changes: 1 addition & 1 deletion regression/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_save_multiple(self):
self.case_entities_to_delete.append(entity2)

keys = [entity1.key, entity2.key]
matches = datastore.get_entities(keys)
matches = datastore.get(keys)
self.assertEqual(len(matches), 2)

def test_empty_kind(self):
Expand Down

0 comments on commit 6eaa636

Please sign in to comment.