Permalink
Browse files

Added some tests to ensure we gracefully handle exceptional

responses from AWS
  • Loading branch information...
1 parent 056a601 commit 189ecaafc52f47f816c9ffc0d18d80041de4fc3b @csaunders csaunders committed Apr 12, 2012
@@ -263,6 +263,7 @@ def parse_error(http_response)
response[:response_comment] = "#{response[:error_code]}: #{response[:error_message]}"
response
rescue REXML::ParseException => e
+ rescue NoMethodError => e
response[:http_body] = http_response.body
response[:response_status] = FAILURE
response[:response_comment] = "#{response[:http_code]}: #{response[:http_message]}"
@@ -0,0 +1,9 @@
+<ErrorResponse
+ xmlns="http://mws.amazonaws.com/FulfillmentOutboundShipment/2010-10-01/">
+ <Error>
+ <Type>Sender</Type>
+ <Code>UnknownError</Code>
+ <Message>Something has gone terribly wrong!</Message>
+ </Error>
+ <RequestId>2d51bcf0-9237-49a6-a778-62195564575f</RequestId>
+</ErrorResponse>
@@ -181,9 +181,31 @@ def test_fetch_tracking_numbers_ignores_not_found
end
def test_fetch_tracking_numbers_aborts_on_error
+ response = mock('response')
+ response.stubs(:code).returns(500)
+ response.stubs(:message).returns("Internal Server Error")
+ response.stubs(:body).returns(xml_fixture('amazon_mws/tracking_response_error'))
+
+ @service.expects(:ssl_post).twice.
+ returns(xml_fixture('amazon_mws/fulfillment_get_fulfillment_order')).
+ raises(ActiveMerchant::ResponseError.new(response))
+
+ response = @service.fetch_tracking_numbers(['extern_id_1154539615776', 'ERROR', 'extern_id_1154539615777'])
+ assert !response.success?
+ assert_equal 'Something has gone terribly wrong!', response.faultstring
end
def test_404_error
+ http_response = build_mock_response(response_from_404, "Not Found", "404")
+ @service.expects(:ssl_post).raises(ActiveMerchant::ResponseError.new(http_response))
+
+ response = @service.fulfill('987654321', @address, @line_items, @options)
+ assert !response.success?
+
+ assert_equal "404: Not Found", response.response_comment
+ assert_equal "404", response.http_code
+ assert_equal "Not Found", response.http_message
+ assert_equal response_from_404, response.http_body
end
private
@@ -234,4 +256,8 @@ def invalid_create_response
XML
end
+
+ def response_from_404
+ '<html><head><title>Apache Tomcat</title></head><body>That was not found</body></html>'
+ end
end

0 comments on commit 189ecaa

Please sign in to comment.