Update response headers with response_dict from key; add tests

This commit is contained in:
Taro Sato 2016-09-20 15:42:21 -07:00
parent 97513590c8
commit bdb9d59e46
3 changed files with 39 additions and 1 deletions

View File

@ -400,6 +400,7 @@ class ResponseObject(_TemplateEnvironmentMixin):
return 200, headers, template.render(obj=key) return 200, headers, template.render(obj=key)
headers.update(key.metadata) headers.update(key.metadata)
headers.update(key.response_dict)
return 200, headers, key.value return 200, headers, key.value
def _key_response_put(self, request, body, bucket_name, query, key_name, headers): def _key_response_put(self, request, body, bucket_name, query, key_name, headers):

View File

@ -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 @mock_s3
def test_boto3_bucket_create(): def test_boto3_bucket_create():
s3 = boto3.resource('s3', region_name='us-east-1') 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)) 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 = """\ TEST_XML = """\
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ns0:WebsiteConfiguration xmlns:ns0="http://s3.amazonaws.com/doc/2006-03-01/"> <ns0:WebsiteConfiguration xmlns:ns0="http://s3.amazonaws.com/doc/2006-03-01/">

View File

@ -7,7 +7,7 @@ deps =
-r{toxinidir}/requirements-dev.txt -r{toxinidir}/requirements-dev.txt
commands = commands =
{envpython} setup.py test {envpython} setup.py test
nosetests nosetests {posargs}
[flake8] [flake8]
ignore = E128,E501 ignore = E128,E501