Skip to content

Commit

Permalink
Merge branch 'fix-json-serialization' into develop
Browse files Browse the repository at this point in the history
* fix-json-serialization:
  Add integ test for blob serialization in json protocol
  Switch kinesis integ tests over to client interface
  Fix base64 serialization in JSON protocol
  • Loading branch information
jamesls committed Dec 2, 2014
2 parents 9f601ca + 4cc7aed commit ffcef5f
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 9 deletions.
18 changes: 18 additions & 0 deletions botocore/data/aws/kinesis/2013-12-02.waiters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 2,
"waiters": {
"StreamExists": {
"delay": 10,
"operation": "DescribeStream",
"maxAttempts": 18,
"acceptors": [
{
"expected": "ACTIVE",
"matcher": "path",
"state": "success",
"argument": "StreamDescription.StreamStatus"
}
]
}
}
}
14 changes: 12 additions & 2 deletions botocore/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
from xml.etree import ElementTree
import calendar

import datetime
from dateutil.tz import tzutc
import six

from botocore.compat import json, formatdate
Expand Down Expand Up @@ -327,12 +325,24 @@ def _serialize_type_structure(self, serialized, value, shape, key):
member_shape = members[member_key]
self._serialize(serialized, member_value, member_shape, member_key)

def _serialize_type_map(self, serialized, value, shape, key):
map_obj = self.MAP_TYPE()
serialized[key] = map_obj
for sub_key, sub_value in value.items():
self._serialize(map_obj, sub_value, shape.value, sub_key)

def _default_serialize(self, serialized, value, shape, key):
serialized[key] = value

def _serialize_type_timestamp(self, serialized, value, shape, key):
serialized[key] = self._convert_timestamp_to_str(value)

def _serialize_type_blob(self, serialized, value, shape, key):
b64_encoded = base64.b64encode(
value.encode(self.DEFAULT_ENCODING)).strip().decode(
self.DEFAULT_ENCODING)
serialized[key] = b64_encoded


class BaseRestSerializer(Serializer):
"""Base class for rest protocols.
Expand Down
37 changes: 30 additions & 7 deletions tests/integration/test_kinesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,48 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import time
import random
from tests import unittest
import itertools

import botocore.session


class TestKinesisListStreams(unittest.TestCase):
def setUp(self):
self.session = botocore.session.get_session()
self.service = self.session.get_service('kinesis')
self.endpoint = self.service.get_endpoint('us-east-1')
self.client = self.session.create_client('kinesis', 'us-east-1')
self.stream_name = 'botocore-test-%s-%s' % (int(time.time()),
random.randint(1, 100))

def test_list_streams(self):
operation = self.service.get_operation('ListStreams')
http, parsed = operation.call(self.endpoint)
self.assertEqual(http.status_code, 200)
parsed = self.client.list_streams()
self.assertIn('StreamNames', parsed)

def test_can_put_stream_blob(self):
self.client.create_stream(StreamName=self.stream_name,
ShardCount=1)
waiter = self.client.get_waiter('stream_exists')
waiter.wait(StreamName=self.stream_name)
self.addCleanup(self.client.delete_stream,
StreamName=self.stream_name)

self.client.put_record(
StreamName=self.stream_name, PartitionKey='foo', Data='foobar')
# Give it a few seconds for the record to get into the stream.
time.sleep(10)

stream = self.client.describe_stream(StreamName=self.stream_name)
shard = stream['StreamDescription']['Shards'][0]
shard_iterator = self.client.get_shard_iterator(
StreamName=self.stream_name, ShardId=shard['ShardId'],
ShardIteratorType='TRIM_HORIZON')

records = self.client.get_records(
ShardIterator=shard_iterator['ShardIterator'])
self.assertTrue(len(records['Records']) > 0)
self.assertEqual(records['Records'][0]['Data'], 'foobar')


if __name__ == '__main__':
unittest.main()
75 changes: 75 additions & 0 deletions tests/unit/protocols/input/json.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,81 @@
}
]
},
{
"description": "Base64 encoded Blobs",
"metadata": {
"protocol": "json",
"jsonVersion": 1.1,
"targetPrefix": "com.amazonaws.foo"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"BlobArg": {
"shape": "BlobType"
},
"BlobMap": {
"shape": "BlobMapType"
}
}
},
"BlobType": {
"type": "blob"
},
"BlobMapType": {
"type": "map",
"key": {"shape": "StringType"},
"value": {"shape": "BlobType"}
},
"StringType": {
"type": "string"
}
},
"cases": [
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"BlobArg": "foo"
},
"serialized": {
"body": "{\"BlobArg\": \"Zm9v\"}",
"headers": {
"X-Amz-Target": "com.amazonaws.foo.OperationName",
"Content-Type": "application/x-amz-json-1.1"
},
"uri": "/"
}
},
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"BlobMap": {
"key1": "foo",
"key2": "bar"
}
},
"serialized": {
"body": "{\"BlobMap\": {\"key1\": \"Zm9v\", \"key2\": \"YmFy\"}}",
"headers": {
"X-Amz-Target": "com.amazonaws.foo.OperationName",
"Content-Type": "application/x-amz-json-1.1"
},
"uri": "/"
}
}
]
},
{
"description": "Recursive shapes",
"metadata": {
Expand Down

0 comments on commit ffcef5f

Please sign in to comment.