diff options
author | James Saryerwinnie <js@jamesls.com> | 2013-04-18 04:14:08 -0700 |
---|---|---|
committer | James Saryerwinnie <js@jamesls.com> | 2013-04-18 04:14:08 -0700 |
commit | 89f4947000587e12042e5b35c4557871b21137b9 (patch) | |
tree | 0606c64058f8402e74b29c621105b74292ff366c /tests/unit/test_exception.py | |
parent | b5852b0aa5ac91f462b28ac9decee33d872dec4d (diff) | |
parent | 699d861f453aff8a398f9cd5a8de91ec8e36a8cf (diff) | |
download | boto-2.9.0.tar.gz |
Merge branch 'release-2.9.0'2.9.0
* release-2.9.0: (158 commits)
Bump version to 2.9.0
Added underlying DynamoDB v2 support.
Add redshift to setup.py/docs index
Updated requests to something more modern.
Only use 2 metadata service calls to get credentials
Fix #1146: return response from custom url opener
Fixed missing import.
Add metadata_service_num_attempts config option
Added cleanup for the snapshots created.
Added support for redshift.
Let total attempts by 1 + num_retries
Add more diagnostics to debug logs
Change GS calls to make_request to always convert to utf-8 bytes.
Allow kwargs to be passed through to uplaoder
Remove whitespace, fix long line lengths
Improve VPC and VPN support
Added sleeps to allow amazon time to propogate
Added error handling for out of space during downloads
Initial integration tests for idempotent subscribe
Removed dead code from resumable upload handler
...
Diffstat (limited to 'tests/unit/test_exception.py')
-rw-r--r-- | tests/unit/test_exception.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/unit/test_exception.py b/tests/unit/test_exception.py new file mode 100644 index 00000000..684ca0ce --- /dev/null +++ b/tests/unit/test_exception.py @@ -0,0 +1,78 @@ +from tests.unit import unittest + +from boto.exception import BotoServerError + +from httpretty import HTTPretty, httprettified + +class TestBotoServerError(unittest.TestCase): + + def test_botoservererror_basics(self): + bse = BotoServerError('400', 'Bad Request') + self.assertEqual(bse.status, '400') + self.assertEqual(bse.reason, 'Bad Request') + + def test_message_elb_xml(self): + # This test XML response comes from #509 + xml = """ +<ErrorResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2011-11-15/"> + <Error> + <Type>Sender</Type> + <Code>LoadBalancerNotFound</Code> + <Message>Cannot find Load Balancer webapp-balancer2</Message> + </Error> + <RequestId>093f80d0-4473-11e1-9234-edce8ec08e2d</RequestId> +</ErrorResponse>""" + bse = BotoServerError('400', 'Bad Request', body=xml) + + self.assertEqual(bse.error_message, 'Cannot find Load Balancer webapp-balancer2') + self.assertEqual(bse.request_id, '093f80d0-4473-11e1-9234-edce8ec08e2d') + self.assertEqual(bse.error_code, 'LoadBalancerNotFound') + self.assertEqual(bse.status, '400') + self.assertEqual(bse.reason, 'Bad Request') + + def test_message_sd_xml(self): + # Sample XML response from: https://forums.aws.amazon.com/thread.jspa?threadID=87393 + xml = """ +<Response> + <Errors> + <Error> + <Code>AuthorizationFailure</Code> + <Message>Session does not have permission to perform (sdb:CreateDomain) on resource (arn:aws:sdb:us-east-1:xxxxxxx:domain/test_domain). Contact account owner.</Message> + <BoxUsage>0.0055590278</BoxUsage> + </Error> + </Errors> + <RequestID>e73bb2bb-63e3-9cdc-f220-6332de66dbbe</RequestID> +</Response>""" + bse = BotoServerError('403', 'Forbidden', body=xml) + self.assertEqual(bse.error_message, + 'Session does not have permission to perform (sdb:CreateDomain) on ' + 'resource (arn:aws:sdb:us-east-1:xxxxxxx:domain/test_domain). ' + 'Contact account owner.') + self.assertEqual(bse.box_usage, '0.0055590278') + self.assertEqual(bse.error_code, 'AuthorizationFailure') + self.assertEqual(bse.status, '403') + self.assertEqual(bse.reason, 'Forbidden') + + @httprettified + def test_xmlns_not_loaded(self): + xml = '<ErrorResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2011-11-15/">' + bse = BotoServerError('403', 'Forbidden', body=xml) + self.assertEqual([], HTTPretty.latest_requests) + + @httprettified + def test_xml_entity_not_loaded(self): + xml = '<!DOCTYPE Message [<!ENTITY xxe SYSTEM "http://aws.amazon.com/">]><Message>error:&xxe;</Message>' + bse = BotoServerError('403', 'Forbidden', body=xml) + self.assertEqual([], HTTPretty.latest_requests) + + def test_message_not_xml(self): + body = 'This is not XML' + + bse = BotoServerError('400', 'Bad Request', body=body) + self.assertEqual(bse.error_message, 'This is not XML') + + def test_getters(self): + body = "This is the body" + + bse = BotoServerError('400', 'Bad Request', body=body) + self.assertEqual(bse.code, bse.error_code) |