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

Fix #133: preserve PB namespace in Key.from_protobuf. #183

Merged
merged 2 commits into from
Sep 30, 2014
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
5 changes: 4 additions & 1 deletion gcloud/datastore/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ def from_protobuf(cls, pb, dataset=None):

if not dataset:
dataset = Dataset(id=pb.partition_id.dataset_id)
namespace = pb.partition_id.namespace
else:
namespace = None

return cls(path=path, dataset=dataset)
return cls(dataset, namespace, path)

This comment was marked as spam.

This comment was marked as spam.


def to_protobuf(self):
"""Return a protobuf corresponding to the key.
Expand Down
14 changes: 11 additions & 3 deletions gcloud/datastore/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ def test_from_protobuf_w_dataset_in_pb(self):
key = self._getTargetClass().from_protobuf(pb)
self.assertEqual(key.dataset().id(), _DATASET)

def test_from_protobuf_w_namespace_in_pb(self):
def test_from_protobuf_w_namespace_in_pb_wo_dataset_passed(self):
_NAMESPACE = 'NAMESPACE'

This comment was marked as spam.

This comment was marked as spam.

pb = self._makePB(namespace=_NAMESPACE)
key = self._getTargetClass().from_protobuf(pb)
# See: https://github.com/GoogleCloudPlatform/gcloud-python/issues/133
# self.assertEqual(key.namespace(), _NAMESPACE) XXX
self.assertEqual(key.namespace(), _NAMESPACE)

def test_from_protobuf_w_namespace_in_pb_w_dataset_passed(self):
from gcloud.datastore.dataset import Dataset

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

_DATASET = 'DATASET'
_NAMESPACE = 'NAMESPACE'
dataset = Dataset(_DATASET)
pb = self._makePB(namespace=_NAMESPACE)
key = self._getTargetClass().from_protobuf(pb, dataset)
self.assertEqual(key.namespace(), None)

def test_from_protobuf_w_path_in_pb(self):
_DATASET = 'DATASET'
Expand Down