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

Handling datastore renames key -> keys #1456

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
6 changes: 3 additions & 3 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def lookup(self, project, key_pbs,
"""
lookup_request = _datastore_pb2.LookupRequest()
_set_read_options(lookup_request, eventual, transaction_id)
_add_keys_to_request(lookup_request.key, key_pbs)
_add_keys_to_request(lookup_request.keys, key_pbs)

lookup_response = self._rpc(project, 'lookup', lookup_request,
_datastore_pb2.LookupResponse)
Expand Down Expand Up @@ -359,11 +359,11 @@ def allocate_ids(self, project, key_pbs):
:returns: An equal number of keys, with IDs filled in by the backend.
"""
request = _datastore_pb2.AllocateIdsRequest()
_add_keys_to_request(request.key, key_pbs)
_add_keys_to_request(request.keys, key_pbs)
# Nothing to do with this response, so just execute the method.
response = self._rpc(project, 'allocateIds', request,
_datastore_pb2.AllocateIdsResponse)
return list(response.key)
return list(response.keys)


def _set_read_options(request, eventual, transaction_id):
Expand Down
24 changes: 12 additions & 12 deletions gcloud/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_lookup_single_key_empty_response(self):
rq_class = datastore_pb2.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
keys = list(request.key)
keys = list(request.keys)
self.assertEqual(len(keys), 1)
_compare_key_pb_after_request(self, key_pb, keys[0])

Expand Down Expand Up @@ -275,7 +275,7 @@ def test_lookup_single_key_empty_response_w_eventual(self):
rq_class = datastore_pb2.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
keys = list(request.key)
keys = list(request.keys)
self.assertEqual(len(keys), 1)
_compare_key_pb_after_request(self, key_pb, keys[0])
self.assertEqual(request.read_options.read_consistency,
Expand Down Expand Up @@ -315,7 +315,7 @@ def test_lookup_single_key_empty_response_w_transaction(self):
rq_class = datastore_pb2.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
keys = list(request.key)
keys = list(request.keys)
self.assertEqual(len(keys), 1)
_compare_key_pb_after_request(self, key_pb, keys[0])
self.assertEqual(request.read_options.transaction, TRANSACTION)
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_lookup_single_key_nonempty_response(self):
rq_class = datastore_pb2.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
keys = list(request.key)
keys = list(request.keys)
self.assertEqual(len(keys), 1)
_compare_key_pb_after_request(self, key_pb, keys[0])

Expand Down Expand Up @@ -376,7 +376,7 @@ def test_lookup_multiple_keys_empty_response(self):
rq_class = datastore_pb2.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
keys = list(request.key)
keys = list(request.keys)
self.assertEqual(len(keys), 2)
_compare_key_pb_after_request(self, key_pb1, keys[0])
_compare_key_pb_after_request(self, key_pb2, keys[1])
Expand Down Expand Up @@ -410,7 +410,7 @@ def test_lookup_multiple_keys_w_missing(self):
rq_class = datastore_pb2.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
keys = list(request.key)
keys = list(request.keys)
self.assertEqual(len(keys), 2)
_compare_key_pb_after_request(self, key_pb1, keys[0])
_compare_key_pb_after_request(self, key_pb2, keys[1])
Expand Down Expand Up @@ -446,7 +446,7 @@ def test_lookup_multiple_keys_w_deferred(self):
rq_class = datastore_pb2.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
keys = list(request.key)
keys = list(request.keys)
self.assertEqual(len(keys), 2)
_compare_key_pb_after_request(self, key_pb1, keys[0])
_compare_key_pb_after_request(self, key_pb2, keys[1])
Expand Down Expand Up @@ -766,7 +766,7 @@ def test_allocate_ids_empty(self):
rq_class = datastore_pb2.AllocateIdsRequest
request = rq_class()
request.ParseFromString(cw['body'])
self.assertEqual(list(request.key), [])
self.assertEqual(list(request.keys), [])

def test_allocate_ids_non_empty(self):
from gcloud.datastore._generated import datastore_pb2
Expand All @@ -781,8 +781,8 @@ def test_allocate_ids_non_empty(self):
self._make_key_pb(PROJECT, id=2345),
]
rsp_pb = datastore_pb2.AllocateIdsResponse()
rsp_pb.key.add().CopyFrom(after_key_pbs[0])
rsp_pb.key.add().CopyFrom(after_key_pbs[1])
rsp_pb.keys.add().CopyFrom(after_key_pbs[0])
rsp_pb.keys.add().CopyFrom(after_key_pbs[1])
conn = self._makeOne()
URI = '/'.join([
conn.api_base_url,
Expand All @@ -798,8 +798,8 @@ def test_allocate_ids_non_empty(self):
rq_class = datastore_pb2.AllocateIdsRequest
request = rq_class()
request.ParseFromString(cw['body'])
self.assertEqual(len(request.key), len(before_key_pbs))
for key_before, key_after in zip(before_key_pbs, request.key):
self.assertEqual(len(request.keys), len(before_key_pbs))
for key_before, key_after in zip(before_key_pbs, request.keys):
_compare_key_pb_after_request(self, key_before, key_after)


Expand Down