From 0145efa280d52f4b565f2078480b1a029ddf9989 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 6 Jan 2016 19:54:03 -0800 Subject: [PATCH 1/4] Renaming datastore operation->op on CompositeFilter and PropertyFilter. --- gcloud/datastore/query.py | 6 +++--- gcloud/datastore/test_query.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gcloud/datastore/query.py b/gcloud/datastore/query.py index a1d012b65061..b1f54519b8f9 100644 --- a/gcloud/datastore/query.py +++ b/gcloud/datastore/query.py @@ -483,7 +483,7 @@ def _pb_from_query(query): pb.kind.add().name = query.kind composite_filter = pb.filter.composite_filter - composite_filter.operator = _query_pb2.CompositeFilter.AND + composite_filter.op = _query_pb2.CompositeFilter.AND if query.ancestor: ancestor_pb = helpers._prepare_key_for_request( @@ -492,7 +492,7 @@ def _pb_from_query(query): # Filter on __key__ HAS_ANCESTOR == ancestor. ancestor_filter = composite_filter.filter.add().property_filter ancestor_filter.property.name = '__key__' - ancestor_filter.operator = _query_pb2.PropertyFilter.HAS_ANCESTOR + ancestor_filter.op = _query_pb2.PropertyFilter.HAS_ANCESTOR ancestor_filter.value.key_value.CopyFrom(ancestor_pb) for property_name, operator, value in query.filters: @@ -501,7 +501,7 @@ def _pb_from_query(query): # Add the specific filter property_filter = composite_filter.filter.add().property_filter property_filter.property.name = property_name - property_filter.operator = pb_op_enum + property_filter.op = pb_op_enum # Set the value to filter on based on the type. if property_name == '__key__': diff --git a/gcloud/datastore/test_query.py b/gcloud/datastore/test_query.py index 4014c95c2936..91e6c346c383 100644 --- a/gcloud/datastore/test_query.py +++ b/gcloud/datastore/test_query.py @@ -560,7 +560,7 @@ def test_empty(self): self.assertEqual(list(pb.group_by), []) self.assertEqual(pb.filter.property_filter.property.name, '') cfilter = pb.filter.composite_filter - self.assertEqual(cfilter.operator, query_pb2.CompositeFilter.AND) + self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) self.assertEqual(list(cfilter.filter), []) self.assertEqual(pb.start_cursor, b'') self.assertEqual(pb.end_cursor, b'') @@ -584,7 +584,7 @@ def test_ancestor(self): ancestor = Key('Ancestor', 123, project='PROJECT') pb = self._callFUT(_Query(ancestor=ancestor)) cfilter = pb.filter.composite_filter - self.assertEqual(cfilter.operator, query_pb2.CompositeFilter.AND) + self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) self.assertEqual(len(cfilter.filter), 1) pfilter = cfilter.filter[0].property_filter self.assertEqual(pfilter.property.name, '__key__') @@ -600,7 +600,7 @@ def test_filter(self): } pb = self._callFUT(query) cfilter = pb.filter.composite_filter - self.assertEqual(cfilter.operator, query_pb2.CompositeFilter.AND) + self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) self.assertEqual(len(cfilter.filter), 1) pfilter = cfilter.filter[0].property_filter self.assertEqual(pfilter.property.name, 'name') @@ -618,7 +618,7 @@ def test_filter_key(self): } pb = self._callFUT(query) cfilter = pb.filter.composite_filter - self.assertEqual(cfilter.operator, query_pb2.CompositeFilter.AND) + self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) self.assertEqual(len(cfilter.filter), 1) pfilter = cfilter.filter[0].property_filter self.assertEqual(pfilter.property.name, '__key__') From a1848dd8b81ad4bd5abf4d4af73f143bfb8835cf Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 6 Jan 2016 19:59:22 -0800 Subject: [PATCH 2/4] Renaming filter->filters in CompositeFilter. --- gcloud/datastore/query.py | 6 +++--- gcloud/datastore/test_query.py | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gcloud/datastore/query.py b/gcloud/datastore/query.py index b1f54519b8f9..969be28633b6 100644 --- a/gcloud/datastore/query.py +++ b/gcloud/datastore/query.py @@ -490,7 +490,7 @@ def _pb_from_query(query): query.ancestor.to_protobuf()) # Filter on __key__ HAS_ANCESTOR == ancestor. - ancestor_filter = composite_filter.filter.add().property_filter + ancestor_filter = composite_filter.filters.add().property_filter ancestor_filter.property.name = '__key__' ancestor_filter.op = _query_pb2.PropertyFilter.HAS_ANCESTOR ancestor_filter.value.key_value.CopyFrom(ancestor_pb) @@ -499,7 +499,7 @@ def _pb_from_query(query): pb_op_enum = query.OPERATORS.get(operator) # Add the specific filter - property_filter = composite_filter.filter.add().property_filter + property_filter = composite_filter.filters.add().property_filter property_filter.property.name = property_name property_filter.op = pb_op_enum @@ -511,7 +511,7 @@ def _pb_from_query(query): else: helpers._set_protobuf_value(property_filter.value, value) - if not composite_filter.filter: + if not composite_filter.filters: pb.ClearField('filter') for prop in query.order: diff --git a/gcloud/datastore/test_query.py b/gcloud/datastore/test_query.py index 91e6c346c383..717c159b0ffe 100644 --- a/gcloud/datastore/test_query.py +++ b/gcloud/datastore/test_query.py @@ -561,7 +561,7 @@ def test_empty(self): self.assertEqual(pb.filter.property_filter.property.name, '') cfilter = pb.filter.composite_filter self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) - self.assertEqual(list(cfilter.filter), []) + self.assertEqual(list(cfilter.filters), []) self.assertEqual(pb.start_cursor, b'') self.assertEqual(pb.end_cursor, b'') self.assertEqual(pb.limit, 0) @@ -585,8 +585,8 @@ def test_ancestor(self): pb = self._callFUT(_Query(ancestor=ancestor)) cfilter = pb.filter.composite_filter self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) - self.assertEqual(len(cfilter.filter), 1) - pfilter = cfilter.filter[0].property_filter + self.assertEqual(len(cfilter.filters), 1) + pfilter = cfilter.filters[0].property_filter self.assertEqual(pfilter.property.name, '__key__') ancestor_pb = _prepare_key_for_request(ancestor.to_protobuf()) self.assertEqual(pfilter.value.key_value, ancestor_pb) @@ -601,8 +601,8 @@ def test_filter(self): pb = self._callFUT(query) cfilter = pb.filter.composite_filter self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) - self.assertEqual(len(cfilter.filter), 1) - pfilter = cfilter.filter[0].property_filter + self.assertEqual(len(cfilter.filters), 1) + pfilter = cfilter.filters[0].property_filter self.assertEqual(pfilter.property.name, 'name') self.assertEqual(pfilter.value.string_value, u'John') @@ -619,8 +619,8 @@ def test_filter_key(self): pb = self._callFUT(query) cfilter = pb.filter.composite_filter self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) - self.assertEqual(len(cfilter.filter), 1) - pfilter = cfilter.filter[0].property_filter + self.assertEqual(len(cfilter.filters), 1) + pfilter = cfilter.filters[0].property_filter self.assertEqual(pfilter.property.name, '__key__') key_pb = _prepare_key_for_request(key.to_protobuf()) self.assertEqual(pfilter.value.key_value, key_pb) From d85fb6423a21c036144d8cbd24d6ced112f74829 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 6 Jan 2016 20:01:56 -0800 Subject: [PATCH 3/4] Updating to new default for CompositeFilter.Operator. --- gcloud/datastore/test_query.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcloud/datastore/test_query.py b/gcloud/datastore/test_query.py index 717c159b0ffe..2c301df0e6cc 100644 --- a/gcloud/datastore/test_query.py +++ b/gcloud/datastore/test_query.py @@ -560,7 +560,8 @@ def test_empty(self): self.assertEqual(list(pb.group_by), []) self.assertEqual(pb.filter.property_filter.property.name, '') cfilter = pb.filter.composite_filter - self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND) + self.assertEqual(cfilter.op, + query_pb2.CompositeFilter.OPERATOR_UNSPECIFIED) self.assertEqual(list(cfilter.filters), []) self.assertEqual(pb.start_cursor, b'') self.assertEqual(pb.end_cursor, b'') From 1d920313cbea9850b4a69ca1d3567cad568cf6e0 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Thu, 7 Jan 2016 12:31:34 -0800 Subject: [PATCH 4/4] Updating to new default for ReadOptions.ReadConsistency. --- gcloud/datastore/test_connection.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcloud/datastore/test_connection.py b/gcloud/datastore/test_connection.py index 34b3ca1c685c..390fc023b056 100644 --- a/gcloud/datastore/test_connection.py +++ b/gcloud/datastore/test_connection.py @@ -524,8 +524,9 @@ def test_run_query_wo_eventual_w_transaction(self): request.ParseFromString(cw['body']) self.assertEqual(request.partition_id.namespace_id, '') self.assertEqual(request.query, q_pb) - self.assertEqual(request.read_options.read_consistency, - datastore_pb2.ReadOptions.DEFAULT) + self.assertEqual( + request.read_options.read_consistency, + datastore_pb2.ReadOptions.READ_CONSISTENCY_UNSPECIFIED) self.assertEqual(request.read_options.transaction, TRANSACTION) def test_run_query_w_eventual_and_transaction(self):