class TestS3Retry200SpecialCases(unittest.TestCase): def setUp(self): super(TestS3Retry200SpecialCases, self).setUp() self.total_calls = 0 self.auth = Mock() self.session = create_session(include_builtin_handlers=True) self.service = Mock() self.service.endpoint_prefix = 's3' self.service.session = self.session self.endpoint = RestEndpoint( self.service, 'us-east-1', 'https://s3.amazonaws.com/', auth=self.auth) self.http_session = Mock() self.endpoint.http_session = self.http_session self.get_response_patch = patch('botocore.response.get_response') self.get_response = self.get_response_patch.start() self.retried_on_exception = None def tearDown(self): self.get_response_patch.stop() def test_retry_special_case_s3_200_response(self): # Test for: # http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html op = Mock() op.name = 'CopyObject' op.http = {'uri': '', 'method': 'PUT'} http_response = Mock() http_response.status_code = 200 parsed = {'Errors': [{'Code': 'InternalError', 'Message': 'foo'}]} self.get_response.return_value = (http_response, parsed) self.endpoint.make_request(op, {'headers': {}, 'payload': None}) # The response code should have been switched to 500. self.assertEqual(http_response.status_code, 500)
def test_quote_uri_safe_key(self): uri = '/{foo}/{bar}' operation = Mock() operation.http = {'uri': uri} params = {'uri_params': {'foo': 'foo', 'bar': 'bar~'}} endpoint = RestEndpoint(Mock(), None, None, None) built_uri = endpoint.build_uri(operation, params) self.assertEqual(built_uri, '/foo/bar~?')
def test_encode_uri_params_unicode(self): uri = '/{foo}/{bar}' operation = Mock() operation.http = {'uri': uri} params = {'uri_params': {'foo': u'\u2713', 'bar': 'bar'}} endpoint = RestEndpoint(Mock(), None, None, None) built_uri = endpoint.build_uri(operation, params) self.assertEqual(built_uri, '/%E2%9C%93/bar?')
def setUp(self): super(TestResetStreamOnRetry, self).setUp() self.total_calls = 0 self.auth = Mock() self.session = Session(include_builtin_handlers=False) self.service = Mock() self.service.endpoint_prefix = 's3' self.service.session = self.session self.endpoint = RestEndpoint( self.service, 'us-east-1', 'https://s3.amazonaws.com/', auth=self.auth) self.http_session = Mock() self.endpoint.http_session = self.http_session self.get_response_patch = patch('botocore.response.get_response') self.get_response = self.get_response_patch.start() self.retried_on_exception = None
class TestResetStreamOnRetry(unittest.TestCase): def setUp(self): super(TestResetStreamOnRetry, self).setUp() self.total_calls = 0 self.auth = Mock() self.session = create_session(include_builtin_handlers=False) self.service = Mock() self.service.endpoint_prefix = 's3' self.service.session = self.session self.endpoint = RestEndpoint(self.service, 'us-east-1', 'https://s3.amazonaws.com/', auth=self.auth) self.http_session = Mock() self.endpoint.http_session = self.http_session self.get_response_patch = patch('botocore.response.get_response') self.get_response = self.get_response_patch.start() self.retried_on_exception = None def tearDown(self): self.get_response_patch.stop() def max_attempts_retry_handler(self, attempts, **kwargs): # Simulate a max requests of 3. self.total_calls += 1 if attempts == 3: return None else: # Returning anything non-None will trigger a retry, # but 0 here is so that time.sleep(0) happens. return 0 def test_reset_stream_on_retry(self): # It doesn't really matter what the operation is, we will # check in general if we're self.session.register('needs-retry.s3.PutObject', self.max_attempts_retry_handler) op = Mock() payload = Payload() payload.literal_value = RecordStreamResets('foobar') op.name = 'PutObject' op.http = {'uri': '', 'method': 'POST'} self.endpoint.make_request(op, {'headers': {}, 'payload': payload}) self.assertEqual(self.total_calls, 3) self.assertEqual(payload.literal_value.total_resets, 2)
class TestResetStreamOnRetry(unittest.TestCase): def setUp(self): super(TestResetStreamOnRetry, self).setUp() self.total_calls = 0 self.auth = Mock() self.session = Session(include_builtin_handlers=False) self.service = Mock() self.service.endpoint_prefix = 's3' self.service.session = self.session self.endpoint = RestEndpoint( self.service, 'us-east-1', 'https://s3.amazonaws.com/', auth=self.auth) self.http_session = Mock() self.endpoint.http_session = self.http_session self.get_response_patch = patch('botocore.response.get_response') self.get_response = self.get_response_patch.start() self.retried_on_exception = None def tearDown(self): self.get_response_patch.stop() def max_attempts_retry_handler(self, attempts, **kwargs): # Simulate a max requests of 3. self.total_calls += 1 if attempts == 3: return None else: # Returning anything non-None will trigger a retry, # but 0 here is so that time.sleep(0) happens. return 0 def test_reset_stream_on_retry(self): # It doesn't really matter what the operation is, we will # check in general if we're self.session.register('needs-retry.s3.PutObject', self.max_attempts_retry_handler) op = Mock() payload = Payload() payload.literal_value = RecordStreamResets('foobar') op.name = 'PutObject' op.http = {'uri': '', 'method': 'POST'} self.endpoint.make_request(op, {'headers': {}, 'payload': payload}) self.assertEqual(self.total_calls, 3) self.assertEqual(payload.literal_value.total_resets, 2)