Skip to content

Commit

Permalink
Serialize s3 metadata properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesls committed Apr 21, 2014
1 parent 570a6f8 commit 865fcb2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions botocore/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,21 @@ def build_parameter_json(self, value, built_params, label=''):
for key in value:
new_value[key] = value[key]

def build_parameter_rest(self, style, value, built_params, label=''):
# There's a special case for rest-xml with header locations
# that we we need to handle for maps. If this is not the
# case we can defer to the base class's implementation of
# map parameters serialization.
if style == 'rest-xml' and getattr(self, 'location', '') == 'header':
prefix = getattr(self, 'location_name', '') or self.name
user_params = value
for key, value in user_params.items():
full_key_name = prefix + key
built_params['headers'][full_key_name] = value
else:
return super(MapParameter, self).build_parameter_rest(
style, value, build_params, label)


class StructParameter(Parameter):

Expand Down
13 changes: 13 additions & 0 deletions tests/integration/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,19 @@ def test_copy_with_quoted_char(self):
data = response[1]
self.assertEqual(data['Body'].read().decode('utf-8'), 'foo')

def test_copy_with_s3_metadata(self):
key_name = 'foo.txt'
self.create_object(key_name=key_name)
copied_key = 'copied.txt'
operation = self.service.get_operation('CopyObject')
http, parsed = operation.call(
self.endpoint, bucket=self.bucket_name, key=copied_key,
copy_source='%s/%s' % (self.bucket_name, key_name),
metadata_directive='REPLACE',
metadata={"mykey": "myvalue", "mykey2": "myvalue2"})
self.keys.append(copied_key)
self.assertEqual(http.status_code, 200)


if __name__ == '__main__':
unittest.main()
17 changes: 17 additions & 0 deletions tests/unit/test_s3_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ def test_put_object(self):
self.assertEqual(params['uri_params'], uri_params)
self.assertEqual(params['payload'].getvalue(), fp)

def test_copy_object(self):
operation = self.s3.get_operation('CopyObject')
bucket_name = 'mybucket'
key_name = 'key1'
copied_key= 'copied'
params = operation.build_parameters(
bucket=self.bucket_name, key=copied_key,
copy_source='%s/%s' % (bucket_name, key_name),
metadata_directive='REPLACE',
metadata={"mykey": "myvalue", "mykey2": "myvalue2"})
self.assertEqual(params['headers'], {
'x-amz-copy-source': 'mybucket/key1',
'x-amz-metadata-directive': 'REPLACE',
'x-amz-meta-mykey': 'myvalue',
'x-amz-meta-mykey2': 'myvalue2',
})

def test_complete_multipart_upload(self):
op = self.s3.get_operation('CompleteMultipartUpload')
parts = {
Expand Down

0 comments on commit 865fcb2

Please sign in to comment.