Skip to content

Commit

Permalink
fix json -> xml request payload conversion
Browse files Browse the repository at this point in the history
When creating request payload from json data, json `null` will now be converted to empty string '' not string 'None'.
  • Loading branch information
quiver committed Feb 9, 2014
1 parent eb41623 commit 2009432
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion botocore/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def build_parameter(self, style, value, built_params, label=''):
def to_xml(self, value, label=None):
if not label:
label = self.name
return '<%s>%s</%s>' % (label, value, label)
if value is None:
return '<%s></%s>' % (label, label)
else:
return '<%s>%s</%s>' % (label, value, label)


class IntegerParameter(Parameter):
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/test_s3_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
'<ErrorDocument><Key>SomeErrorDocument.html</Key></ErrorDocument>'
'<IndexDocument><Suffix>index.html</Suffix></IndexDocument>'
'</WebsiteConfiguration>')
XMLBODY9 = ('<LifecycleConfiguration><Rule><ID>archive-objects-glacier-'
'immediately-upon-creation</ID><Prefix></Prefix>'
'<Status>Enabled</Status><Transition><Days>0</Days>'
'<StorageClass>GLACIER</StorageClass></Transition></Rule>'
'</LifecycleConfiguration>')

POLICY = ('{"Version": "2008-10-17","Statement": [{"Sid": "AddPerm",'
'"Effect": "Allow","Principal": {"AWS": "*"},'
Expand Down Expand Up @@ -108,6 +113,30 @@ def test_create_bucket_lifecycle(self):
self.assertEqual(params['payload'].getvalue(), XMLBODY2)
self.assertEqual(params['headers'], headers)

def test_create_entire_bucket_lifecycle(self):
op = self.s3.get_operation('PutBucketLifecycle')
config = {'Rules': [
{'ID': 'archive-objects-glacier-immediately-upon-creation',
'Prefix': None,
'Status': 'Enabled',
'Transition': {'Days': 0,
'StorageClass': 'GLACIER'}
}
]
}
params = op.build_parameters(bucket=self.bucket_name,
lifecycle_configuration=config)
# There is a handler for the before-call event that will
# add the Content-MD5 header to the parameters if it is not
# already there. We are going to fire the event here to
# simulate that and make sure the right header is added.
self.session.emit('before-call.s3.PutBucketLifecycle', params=params)
uri_params = {'Bucket': self.bucket_name}
headers = {'Content-MD5': 'RLlxIC2KsifRLSfsrCKkVg=='}
self.assertEqual(params['uri_params'], uri_params)
self.assertEqual(params['payload'].getvalue(), XMLBODY9)
self.assertEqual(params['headers'], headers)

def test_put_bucket_tagging(self):
op = self.s3.get_operation('PutBucketTagging')
tag_set = {'TagSet': [
Expand Down

0 comments on commit 2009432

Please sign in to comment.