Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming path_element->path in Key. #1457

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcloud/datastore/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def _commit(self):
# order) directly ``_partial_key_entities``.
for new_key_pb, entity in zip(updated_keys,
self._partial_key_entities):
new_id = new_key_pb.path_element[-1].id
new_id = new_key_pb.path[-1].id
entity.key = entity.key.completed_key(new_id)

def commit(self):
Expand Down
2 changes: 1 addition & 1 deletion gcloud/datastore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def allocate_ids(self, incomplete_key, num_ids):
conn = self.connection
allocated_key_pbs = conn.allocate_ids(incomplete_key.project,
incomplete_key_pbs)
allocated_ids = [allocated_key_pb.path_element[-1].id
allocated_ids = [allocated_key_pb.path[-1].id
for allocated_key_pb in allocated_key_pbs]
return [incomplete_key.completed_key(allocated_id)
for allocated_id in allocated_ids]
Expand Down
2 changes: 1 addition & 1 deletion gcloud/datastore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def key_from_protobuf(pb):
:returns: a new `Key` instance
"""
path_args = []
for element in pb.path_element:
for element in pb.path:
path_args.append(element.kind)
if element.id: # Simple field (int64)
path_args.append(element.id)
Expand Down
2 changes: 1 addition & 1 deletion gcloud/datastore/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def to_protobuf(self):
key.partition_id.namespace_id = self.namespace

for item in self.path:
element = key.path_element.add()
element = key.path.add()
if 'kind' in item:
element.kind = item['kind']
if 'id' in item:
Expand Down
4 changes: 2 additions & 2 deletions gcloud/datastore/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def __init__(self, id):
class _KeyPB(object):

def __init__(self, id):
self.path_element = [_PathElementPB(id)]
self.path = [_PathElementPB(id)]


class _Connection(object):
Expand Down Expand Up @@ -390,7 +390,7 @@ def to_protobuf(self):
# Don't assign it, because it will just get ripped out
# key.partition_id.project_id = self.project

element = key.path_element.add()
element = key.path.add()
element.kind = self._kind
if self._id is not None:
element.id = self._id
Expand Down
4 changes: 2 additions & 2 deletions gcloud/datastore/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _make_entity_pb(project, kind, integer_id, name=None, str_val=None):

entity_pb = entity_pb2.Entity()
entity_pb.key.partition_id.project_id = project
path_element = entity_pb.key.path_element.add()
path_element = entity_pb.key.path.add()
path_element.kind = kind
path_element.id = integer_id
if name is not None and str_val is not None:
Expand Down Expand Up @@ -323,7 +323,7 @@ def test_get_multi_miss_w_missing(self):
# Make a missing entity pb to be returned from mock backend.
missed = entity_pb2.Entity()
missed.key.partition_id.project_id = self.PROJECT
path_element = missed.key.path_element.add()
path_element = missed.key.path.add()
path_element.kind = KIND
path_element.id = ID

Expand Down
16 changes: 8 additions & 8 deletions gcloud/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ def test_lookup_single_key_nonempty_response(self):
(found,), missing, deferred = conn.lookup(PROJECT, [key_pb])
self.assertEqual(len(missing), 0)
self.assertEqual(len(deferred), 0)
self.assertEqual(found.key.path_element[0].kind, 'Kind')
self.assertEqual(found.key.path_element[0].id, 1234)
self.assertEqual(found.key.path[0].kind, 'Kind')
self.assertEqual(found.key.path[0].id, 1234)
cw = http._called_with
self._verifyProtobufCall(cw, URI, conn)
rq_class = datastore_pb2.LookupRequest
Expand Down Expand Up @@ -816,15 +816,15 @@ def test_it(self):
index_updates = 1337
keys = [
entity_pb2.Key(
path_element=[
path=[
entity_pb2.Key.PathElement(
kind='Foo',
id=1234,
),
],
),
entity_pb2.Key(
path_element=[
path=[
entity_pb2.Key.PathElement(
kind='Bar',
name='baz',
Expand Down Expand Up @@ -861,9 +861,9 @@ def _compare_key_pb_after_request(test, key_before, key_after):
test.assertEqual(key_after.partition_id.project_id, '')
test.assertEqual(key_before.partition_id.namespace_id,
key_after.partition_id.namespace_id)
test.assertEqual(len(key_before.path_element),
len(key_after.path_element))
for elt1, elt2 in zip(key_before.path_element, key_after.path_element):
test.assertEqual(len(key_before.path),
len(key_after.path))
for elt1, elt2 in zip(key_before.path, key_after.path):
test.assertEqual(elt1, elt2)


Expand All @@ -876,4 +876,4 @@ def __init__(self, _id):
class _KeyProto(object):

def __init__(self, id_):
self.path_element = [_PathElementProto(id_)]
self.path = [_PathElementProto(id_)]
20 changes: 10 additions & 10 deletions gcloud/datastore/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_it(self):
_ID = 1234
entity_pb = entity_pb2.Entity()
entity_pb.key.partition_id.project_id = _PROJECT
entity_pb.key.path_element.add(kind=_KIND, id=_ID)
entity_pb.key.path.add(kind=_KIND, id=_ID)

value_pb = _new_value_pb(entity_pb, 'foo')
value_pb.string_value = 'Foo'
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_mismatched_value_indexed(self):
_ID = 1234
entity_pb = entity_pb2.Entity()
entity_pb.key.partition_id.project_id = _PROJECT
entity_pb.key.path_element.add(kind=_KIND, id=_ID)
entity_pb.key.path.add(kind=_KIND, id=_ID)

list_val_pb = _new_value_pb(entity_pb, 'baz')
list_pb = list_val_pb.list_value
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_nested_entity_no_key(self):

entity_pb = entity_pb2.Entity()
entity_pb.key.partition_id.project_id = PROJECT
element = entity_pb.key.path_element.add()
element = entity_pb.key.path.add()
element.kind = KIND

outside_val_pb = _new_value_pb(entity_pb, OUTSIDE_NAME)
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_key_only(self):

expected_pb = entity_pb2.Entity()
expected_pb.key.partition_id.project_id = project
path_elt = expected_pb.key.path_element.add()
path_elt = expected_pb.key.path.add()
path_elt.kind = kind
path_elt.name = name

Expand Down Expand Up @@ -278,10 +278,10 @@ def test_inverts_to_protobuf(self):
original_pb = entity_pb2.Entity()
# Add a key.
original_pb.key.partition_id.project_id = project = 'PROJECT'
elem1 = original_pb.key.path_element.add()
elem1 = original_pb.key.path.add()
elem1.kind = 'Family'
elem1.id = 1234
elem2 = original_pb.key.path_element.add()
elem2 = original_pb.key.path.add()
elem2.kind = 'King'
elem2.name = 'Spades'

Expand Down Expand Up @@ -357,7 +357,7 @@ def _makePB(self, project=None, namespace=None, path=()):
if namespace is not None:
pb.partition_id.namespace_id = namespace
for elem in path:
added = pb.path_element.add()
added = pb.path.add()
added.kind = elem['kind']
if 'id' in elem:
added.id = elem['id']
Expand Down Expand Up @@ -560,7 +560,7 @@ def test_entity(self):

pb = entity_pb2.Value()
entity_pb = pb.entity_value
entity_pb.key.path_element.add(kind='KIND')
entity_pb.key.path.add(kind='KIND')
entity_pb.key.partition_id.project_id = 'PROJECT'

value_pb = _new_value_pb(entity_pb, 'foo')
Expand Down Expand Up @@ -776,7 +776,7 @@ def test_unprefixed_bogus_key_miss(self):

# Make sure just one.
called_key_pb, = CONNECTION._called_key_pbs
path_element = called_key_pb.path_element
path_element = called_key_pb.path
self.assertEqual(len(path_element), 1)
self.assertEqual(path_element[0].kind, '__MissingLookupKind')
self.assertEqual(path_element[0].id, 1)
Expand All @@ -797,7 +797,7 @@ def test_unprefixed_bogus_key_hit(self):

# Make sure just one.
called_key_pb, = CONNECTION._called_key_pbs
path_element = called_key_pb.path_element
path_element = called_key_pb.path
self.assertEqual(len(path_element), 1)
self.assertEqual(path_element[0].kind, '__MissingLookupKind')
self.assertEqual(path_element[0].id, 1)
Expand Down
6 changes: 3 additions & 3 deletions gcloud/datastore/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_to_protobuf_defaults(self):
self.assertEqual(pb.partition_id.namespace_id, '')

# Check the element PB matches the partial key and kind.
elem, = list(pb.path_element)
elem, = list(pb.path)
self.assertEqual(elem.kind, _KIND)
# Unset values are False-y.
self.assertEqual(elem.name, '')
Expand Down Expand Up @@ -374,7 +374,7 @@ def test_to_protobuf_w_explicit_path(self):
key = self._makeOne(_PARENT, _NAME, _CHILD, _ID,
project=self._DEFAULT_PROJECT)
pb = key.to_protobuf()
elems = list(pb.path_element)
elems = list(pb.path)
self.assertEqual(len(elems), 2)
self.assertEqual(elems[0].kind, _PARENT)
self.assertEqual(elems[0].name, _NAME)
Expand All @@ -388,7 +388,7 @@ def test_to_protobuf_w_no_kind(self):
key._path[-1].pop('kind')
pb = key.to_protobuf()
# Unset values are False-y.
self.assertEqual(pb.path_element[0].kind, '')
self.assertEqual(pb.path[0].kind, '')

def test_is_partial_no_name_or_id(self):
key = self._makeOne('KIND', project=self._DEFAULT_PROJECT)
Expand Down
2 changes: 1 addition & 1 deletion gcloud/datastore/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _addQueryResults(self, connection, cursor=_END, more=False):
_ID = 123
entity_pb = entity_pb2.Entity()
entity_pb.key.partition_id.project_id = self._PROJECT
path_element = entity_pb.key.path_element.add()
path_element = entity_pb.key.path.add()
path_element.kind = self._KIND
path_element.id = _ID
value_pb = _new_value_pb(entity_pb, 'foo')
Expand Down
2 changes: 1 addition & 1 deletion gcloud/datastore/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _make_key(kind, id_, project):

key = entity_pb2.Key()
key.partition_id.project_id = project
elem = key.path_element.add()
elem = key.path.add()
elem.kind = kind
elem.id = id_
return key
Expand Down