From bdb9d59e465bd6f15920ac5d989bf0585004d25e Mon Sep 17 00:00:00 2001 From: Taro Sato Date: Tue, 20 Sep 2016 15:42:21 -0700 Subject: [PATCH] Update response headers with response_dict from key; add tests --- moto/s3/responses.py | 1 + tests/test_s3/test_s3.py | 37 +++++++++++++++++++++++++++++++++++++ tox.ini | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 0a7566538..b07b50fa6 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -400,6 +400,7 @@ class ResponseObject(_TemplateEnvironmentMixin): return 200, headers, template.render(obj=key) headers.update(key.metadata) + headers.update(key.response_dict) return 200, headers, key.value def _key_response_put(self, request, body, bucket_name, query, key_name, headers): diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 8dcd28172..9a5181074 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -981,6 +981,15 @@ boto3 """ +@mock_s3 +def test_boto3_key_etag(): + s3 = boto3.client('s3', region_name='us-east-1') + s3.create_bucket(Bucket='mybucket') + s3.put_object(Bucket='mybucket', Key='steve', Body=b'is awesome') + resp = s3.get_object(Bucket='mybucket', Key='steve') + resp['ETag'].should.equal('"d32bda93738f7e03adb22e66c90fbc04"') + + @mock_s3 def test_boto3_bucket_create(): s3 = boto3.resource('s3', region_name='us-east-1') @@ -1051,6 +1060,34 @@ def test_boto3_head_object_with_versioning(): old_head_object['ContentLength'].should.equal(len(old_content)) +@mock_s3 +@reduced_min_part_size +def test_boto3_multipart_etag(): + # Create Bucket so that test can run + s3 = boto3.client('s3', region_name='us-east-1') + s3.create_bucket(Bucket='mybucket') + + upload_id = s3.create_multipart_upload( + Bucket='mybucket', Key='the-key')['UploadId'] + part1 = b'0' * REDUCED_PART_SIZE + etags = [] + etags.append( + s3.upload_part(Bucket='mybucket', Key='the-key', PartNumber=1, + UploadId=upload_id, Body=part1)['ETag']) + # last part, can be less than 5 MB + part2 = b'1' + etags.append( + s3.upload_part(Bucket='mybucket', Key='the-key', PartNumber=2, + UploadId=upload_id, Body=part2)['ETag']) + s3.complete_multipart_upload( + Bucket='mybucket', Key='the-key', UploadId=upload_id, + MultipartUpload={'Parts': [{'ETag': etag, 'PartNumber': i} + for i, etag in enumerate(etags, 1)]}) + # we should get both parts as the key contents + resp = s3.get_object(Bucket='mybucket', Key='the-key') + resp['ETag'].should.equal('"66d1a1a2ed08fd05c137f316af4ff255-2"') + + TEST_XML = """\ diff --git a/tox.ini b/tox.ini index 1a2391a45..368eba9c2 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ deps = -r{toxinidir}/requirements-dev.txt commands = {envpython} setup.py test - nosetests + nosetests {posargs} [flake8] ignore = E128,E501