From 00dc427d2dbd1a31e0593023b27c410dca0cc6aa Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Thu, 14 Jan 2016 22:41:37 -0800 Subject: [PATCH] Rename Value.indexed->exclude_from_indexes. Towards #1288. --- gcloud/datastore/helpers.py | 17 +++++++++-------- gcloud/datastore/test_batch.py | 24 ++++++++++++------------ gcloud/datastore/test_helpers.py | 14 ++++++-------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/gcloud/datastore/helpers.py b/gcloud/datastore/helpers.py index 9db96eb83705..b31e2811cfb5 100644 --- a/gcloud/datastore/helpers.py +++ b/gcloud/datastore/helpers.py @@ -176,19 +176,20 @@ def entity_from_protobuf(pb): if meaning is not None: entity_meanings[prop_name] = (meaning, value) - # Check if ``value_pb`` was indexed. Lists need to be special-cased - # and we require all ``indexed`` values in a list agree. + # Check if ``value_pb`` was excluded from index. Lists need to be + # special-cased and we require all ``exclude_from_indexes`` values + # in a list agree. if is_list: - indexed_values = set(value_pb.indexed + exclude_values = set(value_pb.exclude_from_indexes for value_pb in value_pb.list_value) - if len(indexed_values) != 1: + if len(exclude_values) != 1: raise ValueError('For a list_value, subvalues must either all ' 'be indexed or all excluded from indexes.') - if not indexed_values.pop(): + if exclude_values.pop(): exclude_from_indexes.append(prop_name) else: - if not value_pb.indexed: + if value_pb.exclude_from_indexes: exclude_from_indexes.append(prop_name) entity = Entity(key=key, exclude_from_indexes=exclude_from_indexes) @@ -223,10 +224,10 @@ def entity_to_protobuf(entity): # Add index information to protobuf. if name in entity.exclude_from_indexes: if not value_is_list: - value_pb.indexed = False + value_pb.exclude_from_indexes = True for sub_value in value_pb.list_value: - sub_value.indexed = False + sub_value.exclude_from_indexes = True # Add meaning information to protobuf. if name in entity._meanings: diff --git a/gcloud/datastore/test_batch.py b/gcloud/datastore/test_batch.py index 316070bcfeb1..13bc57d8dda2 100644 --- a/gcloud/datastore/test_batch.py +++ b/gcloud/datastore/test_batch.py @@ -118,12 +118,12 @@ def test_put_entity_w_completed_key(self): prop_dict = dict(_property_tuples(mutated_entity)) self.assertEqual(len(prop_dict), 3) - self.assertTrue(prop_dict['foo'].indexed) - self.assertFalse(prop_dict['baz'].indexed) - self.assertTrue(prop_dict['spam'].indexed) - self.assertFalse(prop_dict['spam'].list_value[0].indexed) - self.assertFalse(prop_dict['spam'].list_value[1].indexed) - self.assertFalse(prop_dict['spam'].list_value[2].indexed) + self.assertFalse(prop_dict['foo'].exclude_from_indexes) + self.assertTrue(prop_dict['baz'].exclude_from_indexes) + self.assertFalse(prop_dict['spam'].exclude_from_indexes) + self.assertTrue(prop_dict['spam'].list_value[0].exclude_from_indexes) + self.assertTrue(prop_dict['spam'].list_value[1].exclude_from_indexes) + self.assertTrue(prop_dict['spam'].list_value[2].exclude_from_indexes) self.assertFalse('frotz' in prop_dict) def test_put_entity_w_completed_key_prefixed_project(self): @@ -150,12 +150,12 @@ def test_put_entity_w_completed_key_prefixed_project(self): prop_dict = dict(_property_tuples(mutated_entity)) self.assertEqual(len(prop_dict), 3) - self.assertTrue(prop_dict['foo'].indexed) - self.assertFalse(prop_dict['baz'].indexed) - self.assertTrue(prop_dict['spam'].indexed) - self.assertFalse(prop_dict['spam'].list_value[0].indexed) - self.assertFalse(prop_dict['spam'].list_value[1].indexed) - self.assertFalse(prop_dict['spam'].list_value[2].indexed) + self.assertFalse(prop_dict['foo'].exclude_from_indexes) + self.assertTrue(prop_dict['baz'].exclude_from_indexes) + self.assertFalse(prop_dict['spam'].exclude_from_indexes) + self.assertTrue(prop_dict['spam'].list_value[0].exclude_from_indexes) + self.assertTrue(prop_dict['spam'].list_value[1].exclude_from_indexes) + self.assertTrue(prop_dict['spam'].list_value[2].exclude_from_indexes) self.assertFalse('frotz' in prop_dict) def test_delete_w_partial_key(self): diff --git a/gcloud/datastore/test_helpers.py b/gcloud/datastore/test_helpers.py index af746a154c9d..1dd6cbd59314 100644 --- a/gcloud/datastore/test_helpers.py +++ b/gcloud/datastore/test_helpers.py @@ -78,21 +78,20 @@ def test_it(self): unindexed_val_pb = _new_value_pb(entity_pb, 'bar') unindexed_val_pb.integer_value = 10 - unindexed_val_pb.indexed = False + unindexed_val_pb.exclude_from_indexes = True list_val_pb1 = _new_value_pb(entity_pb, 'baz') list_pb1 = list_val_pb1.list_value unindexed_list_val_pb = list_pb1.add() unindexed_list_val_pb.integer_value = 11 - unindexed_list_val_pb.indexed = False + unindexed_list_val_pb.exclude_from_indexes = True list_val_pb2 = _new_value_pb(entity_pb, 'qux') list_pb2 = list_val_pb2.list_value indexed_list_val_pb = list_pb2.add() indexed_list_val_pb.integer_value = 12 - indexed_list_val_pb.indexed = True entity = self._callFUT(entity_pb) self.assertEqual(entity.kind, _KIND) @@ -125,11 +124,10 @@ def test_mismatched_value_indexed(self): unindexed_value_pb1 = list_pb.add() unindexed_value_pb1.integer_value = 10 - unindexed_value_pb1.indexed = False + unindexed_value_pb1.exclude_from_indexes = True unindexed_value_pb2 = list_pb.add() unindexed_value_pb2.integer_value = 11 - unindexed_value_pb2.indexed = True with self.assertRaises(ValueError): self._callFUT(entity_pb) @@ -290,7 +288,7 @@ def test_inverts_to_protobuf(self): # Add an integer property. val_pb1 = _new_value_pb(original_pb, 'foo') val_pb1.integer_value = 1337 - val_pb1.indexed = False + val_pb1.exclude_from_indexes = True # Add a string property. val_pb2 = _new_value_pb(original_pb, 'bar') val_pb2.string_value = u'hello' @@ -308,11 +306,11 @@ def test_inverts_to_protobuf(self): # Add a list property. val_pb4 = _new_value_pb(original_pb, 'list-quux') list_val1 = val_pb4.list_value.add() - list_val1.indexed = False + list_val1.exclude_from_indexes = True list_val1.meaning = meaning = 22 list_val1.blob_value = b'\xe2\x98\x83' list_val2 = val_pb4.list_value.add() - list_val2.indexed = False + list_val2.exclude_from_indexes = True list_val2.meaning = meaning list_val2.blob_value = b'\xe2\x98\x85'