Skip to content

Instantly share code, notes, and snippets.

@bryanyang0528
Created December 4, 2014 15:01
Show Gist options
  • Save bryanyang0528/ec4ab627da5fa4434056 to your computer and use it in GitHub Desktop.
Save bryanyang0528/ec4ab627da5fa4434056 to your computer and use it in GitHub Desktop.
unitest
def test_get_entity_path(self):
from gcloud.datastore.connection import datastore_pb
DATASET_ID = 'DATASET'
KIND = 'Kind'
ID = 1234
PATH = [{'kind': KIND, 'id': ID}]
entity_pb = datastore_pb.Entity()
entity_pb.key.partition_id.dataset_id = DATASET_ID
path_element = entity_pb.key.path_element.add()
path_element.kind = KIND
path_element.id = ID
prop = entity_pb.property.add()
prop.name = 'foo'
prop.value.string_value = 'Foo'
connection = _Connection(entity_pb)
dataset = self._makeOne(DATASET_ID, connection)
result = dataset.get_entity([KIND, ID])
key = result.key()
self.assertEqual(key._dataset_id, DATASET_ID)
self.assertEqual(key.path(), PATH)
self.assertEqual(list(result), ['foo'])
self.assertEqual(result['foo'], 'Foo')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment