Skip to content

Commit

Permalink
fix the helper function and test case while checking null value
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemia committed Oct 28, 2014
1 parent 014b658 commit a208132
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
10 changes: 1 addition & 9 deletions gcloud/datastore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,7 @@ def _set_protobuf_value(value_pb, val):
:param val: The value to be assigned.
"""
if val is None:
value_pb.ClearField('boolean_value')
value_pb.ClearField('integer_value')
value_pb.ClearField('double_value')
value_pb.ClearField('timestamp_microseconds_value')
value_pb.ClearField('key_value')
value_pb.ClearField('blob_key_value')
value_pb.ClearField('string_value')
value_pb.ClearField('blob_value')
value_pb.ClearField('entity_value')
value_pb.Clear()
return

attr, val = _get_protobuf_attribute_and_value(val)
Expand Down
25 changes: 15 additions & 10 deletions gcloud/datastore/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,23 @@ def test_key(self):
self.assertEqual(value, key.to_protobuf())

def test_none(self):
from gcloud.datastore.entity import Entity

entity = Entity()
pb = self._makePB()

self._callFUT(pb, False)
self._callFUT(pb, 3.1415926)
self._callFUT(pb, 42)
self._callFUT(pb, (1 << 63) - 1)
self._callFUT(pb, 'str')
self._callFUT(pb, b'str')
self._callFUT(pb, u'str')
self._callFUT(pb, entity)
self._callFUT(pb, [u'a', 0, 3.14])

self._callFUT(pb, None)
self.assertEqual(pb.HasField('boolean_value'), False)
self.assertEqual(pb.HasField('integer_value'), False)
self.assertEqual(pb.HasField('double_value'), False)
self.assertEqual(pb.HasField('timestamp_microseconds_value'), False)
self.assertEqual(pb.HasField('key_value'), False)
self.assertEqual(pb.HasField('blob_key_value'), False)
self.assertEqual(pb.HasField('string_value'), False)
self.assertEqual(pb.HasField('blob_value'), False)
self.assertEqual(pb.HasField('entity_value'), False)
self.assertEqual(len(pb.list_value), 0)
self.assertEqual(len(pb.ListFields()), 0)

def test_bool(self):
pb = self._makePB()
Expand Down

0 comments on commit a208132

Please sign in to comment.