Skip to content

Commit

Permalink
Merge pull request #274 from GoogleCloudPlatform/revert-259-121-drop_…
Browse files Browse the repository at this point in the history
…dataset_prefixes_in_keys

Revert "Fix #121:  Drop munging of 's~' prefix onto keys."
  • Loading branch information
tseaver committed Oct 21, 2014
2 parents fab0237 + 374cdf8 commit 8b97707
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions gcloud/datastore/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ def to_protobuf(self):
# but we shouldn't throw a cryptic error if one isn't provided
# in the initializer.
if self.dataset():
# Apparently 's~' is a prefix for High-Replication and is necessary
# here. Another valid preflix is 'e~' indicating EU datacenters.
dataset_id = self.dataset().id()
if dataset_id:
if dataset_id[:2] not in ['s~', 'e~']:
dataset_id = 's~' + dataset_id

key.partition_id.dataset_id = dataset_id

if self._namespace:
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 @@ -425,7 +425,7 @@ def test_lookup_single_key_empty_response(self):
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '24',
'Content-Length': '26',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
Expand Down Expand Up @@ -466,7 +466,7 @@ def test_lookup_single_key_nonempty_response(self):
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '24',
'Content-Length': '26',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
Expand Down Expand Up @@ -504,7 +504,7 @@ def test_lookup_multiple_keys_empty_response(self):
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '48',
'Content-Length': '52',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
Expand Down Expand Up @@ -549,7 +549,7 @@ def test_commit_wo_transaction(self):
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '45',
'Content-Length': '47',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
Expand Down Expand Up @@ -597,7 +597,7 @@ def id(self):
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '51',
'Content-Length': '53',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
Expand Down Expand Up @@ -634,7 +634,7 @@ def test_save_entity_wo_transaction_w_upsert(self):
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '45',
'Content-Length': '47',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
Expand Down Expand Up @@ -687,7 +687,7 @@ def test_save_entity_wo_transaction_w_auto_id(self):
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '42',
'Content-Length': '44',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
Expand Down Expand Up @@ -784,7 +784,7 @@ def test_delete_entities_wo_transaction(self):
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '28',
'Content-Length': '30',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
Expand Down
18 changes: 17 additions & 1 deletion gcloud/datastore/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,28 @@ def test_to_protobuf_w_explicit_dataset_empty_id(self):
pb = key.to_protobuf()
self.assertEqual(pb.partition_id.dataset_id, '')

def test_to_protobuf_w_explicit_dataset(self):
def test_to_protobuf_w_explicit_dataset_no_prefix(self):
from gcloud.datastore.dataset import Dataset
_DATASET = 'DATASET'
dataset = Dataset(_DATASET)
key = self._makeOne(dataset)
pb = key.to_protobuf()
self.assertEqual(pb.partition_id.dataset_id, 's~%s' % _DATASET)

def test_to_protobuf_w_explicit_dataset_w_s_prefix(self):
from gcloud.datastore.dataset import Dataset
_DATASET = 's~DATASET'
dataset = Dataset(_DATASET)
key = self._makeOne(dataset)
pb = key.to_protobuf()
self.assertEqual(pb.partition_id.dataset_id, _DATASET)

def test_to_protobuf_w_explicit_dataset_w_e_prefix(self):
from gcloud.datastore.dataset import Dataset
_DATASET = 'e~DATASET'
dataset = Dataset(_DATASET)
key = self._makeOne(dataset)
pb = key.to_protobuf()
self.assertEqual(pb.partition_id.dataset_id, _DATASET)

def test_to_protobuf_w_explicit_namespace(self):
Expand Down

0 comments on commit 8b97707

Please sign in to comment.