-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from jgeewax/datastore-helper-missing-import
Fix #50 - Missing time import.
- Loading branch information
Showing
3 changed files
with
61 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from datetime import datetime | ||
import time | ||
|
||
import unittest2 | ||
|
||
from gcloud.datastore import helpers | ||
from gcloud.datastore.key import Key | ||
|
||
|
||
class TestHelpers(unittest2.TestCase): | ||
|
||
def test_get_protobuf_attribute(self): | ||
mapping = ( | ||
(str(), 'string_value'), | ||
(unicode(), 'string_value'), | ||
(int(), 'integer_value'), | ||
(long(), 'integer_value'), | ||
(float(), 'double_value'), | ||
(bool(), 'boolean_value'), | ||
(datetime.now(), 'timestamp_microseconds_value'), | ||
(Key(), 'key_value'), | ||
) | ||
|
||
for test_value, expected_name in mapping: | ||
actual_name, _ = helpers.get_protobuf_attribute_and_value(test_value) | ||
self.assertEqual(expected_name, actual_name, | ||
'Test value "%s" expected %s, got %s' % ( | ||
test_value, expected_name, actual_name)) | ||
|
||
def test_get_protobuf_value(self): | ||
now = datetime.now() | ||
|
||
mapping = ( | ||
(str('string'), 'string'), | ||
(unicode('string'), 'string'), | ||
(int(), int()), | ||
(long(), int()), | ||
(float(), float()), | ||
(bool(), bool()), | ||
(now, time.mktime(now.timetuple())), | ||
(Key(), Key().to_protobuf()), | ||
) | ||
|
||
for test_value, expected_value in mapping: | ||
_, actual_value = helpers.get_protobuf_attribute_and_value(test_value) | ||
self.assertEqual(expected_value, actual_value, | ||
'Test value "%s" expected %s, got %s.' % ( | ||
test_value, expected_value, actual_value)) |