Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
import calendar
from datetime import datetime, timedelta

from google.protobuf.internal.type_checkers import Int64ValueChecker
import pytz

from gcloud.datastore.key import Key


INT64 = Int64ValueChecker().CheckValue

This comment was marked as spam.

def get_protobuf_attribute_and_value(val):
"""Given a value, return the protobuf attribute name and proper value.

Expand Down Expand Up @@ -53,7 +56,7 @@ def get_protobuf_attribute_and_value(val):
elif isinstance(val, float):
name, value = 'double', val
elif isinstance(val, (int, long)):
name, value = 'integer', val
name, value = 'integer', INT64(val)
elif isinstance(val, basestring):
name, value = 'string', val

Expand Down
10 changes: 9 additions & 1 deletion gcloud/datastore/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ def test_int(self):
self.assertEqual(value, 42)

def test_long(self):
must_be_long = 1 << 63
must_be_long = (1 << 63) - 1

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

name, value = self._callFUT(must_be_long)
self.assertEqual(name, 'integer_value')
self.assertEqual(value, must_be_long)

def test_long_too_small(self):
too_small = -(1 << 63) - 1

This comment was marked as spam.

self.assertRaises(ValueError, self._callFUT, too_small)

def test_long_too_large(self):
too_large = 1 << 63
self.assertRaises(ValueError, self._callFUT, too_large)

def test_native_str(self):
name, value = self._callFUT('str')
self.assertEqual(name, 'string_value')
Expand Down