From 49c947ece753e6e501f48d83b196f2aa9cd0db5f Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Sat, 3 Jun 2017 19:06:49 -0400 Subject: [PATCH] Stop autodecoding content so we can mimic requests. Closes #963. --- moto/packages/responses/responses.py | 2 ++ tests/test_s3/test_s3.py | 29 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/moto/packages/responses/responses.py b/moto/packages/responses/responses.py index 1f5892b25..0226a7fb1 100644 --- a/moto/packages/responses/responses.py +++ b/moto/packages/responses/responses.py @@ -270,6 +270,8 @@ class RequestsMock(object): body=body, headers=headers, preload_content=False, + # Need to not decode_content to mimic requests + decode_content=False, ) response = adapter.build_response(request, response) diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index a4b8719f6..5c830a905 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -6,7 +6,9 @@ import datetime from six.moves.urllib.request import urlopen from six.moves.urllib.error import HTTPError from functools import wraps +from gzip import GzipFile from io import BytesIO +import zlib import json import boto @@ -1405,6 +1407,33 @@ def test_boto3_delete_markers(): ) +@mock_s3 +def test_get_stream_gzipped(): + payload = "this is some stuff here" + + s3_client = boto3.client("s3", region_name='us-east-1') + s3_client.create_bucket(Bucket='moto-tests') + buffer_ = BytesIO() + with GzipFile(fileobj=buffer_, mode='w') as f: + f.write(payload) + payload_gz = buffer_.getvalue() + + s3_client.put_object( + Bucket='moto-tests', + Key='keyname', + Body=payload_gz, + ContentEncoding='gzip', + ) + + obj = s3_client.get_object( + Bucket='moto-tests', + Key='keyname', + ) + res = zlib.decompress(obj['Body'].read(), 16+zlib.MAX_WBITS) + assert res == payload + + + TEST_XML = """\