def test_can_disable_bucket_validation(self): s3_object_lambda_arn = ( 'arn:aws:s3-object-lambda:us-west-2:123456789012:' 'accesspoint:my-accesspoint') config = TransferConfig() manager = TransferManager(self.client, config) manager.VALIDATE_SUPPORTED_BUCKET_VALUES = False manager.delete(s3_object_lambda_arn, 'my-key')
class TestDeleteObject(BaseGeneralInterfaceTest): __test__ = True def setUp(self): super(TestDeleteObject, self).setUp() self.bucket = 'mybucket' self.key = 'mykey' self.manager = TransferManager(self.client) @property def method(self): """The transfer manager method to invoke i.e. upload()""" return self.manager.delete def create_call_kwargs(self): """The kwargs to be passed to the transfer manager method""" return { 'bucket': self.bucket, 'key': self.key, } def create_invalid_extra_args(self): return { 'BadKwargs': True, } def create_stubbed_responses(self): """A list of stubbed responses that will cause the request to succeed The elements of this list is a dictionary that will be used as key word arguments to botocore.Stubber.add_response(). For example:: [{'method': 'put_object', 'service_response': {}}] """ return [{ 'method': 'delete_object', 'service_response': {}, 'expected_params': {'Bucket': self.bucket, 'Key': self.key}, }] def create_expected_progress_callback_info(self): return [] def test_known_allowed_args_in_input_shape(self): op_model = self.client.meta.service_model.operation_model( 'DeleteObject') for allowed_arg in self.manager.ALLOWED_DELETE_ARGS: self.assertIn(allowed_arg, op_model.input_shape.members) def test_raise_exception_on_s3_object_lambda_resource(self): s3_object_lambda_arn = ( 'arn:aws:s3-object-lambda:us-west-2:123456789012:' 'accesspoint:my-accesspoint' ) with self.assertRaisesRegexp(ValueError, 'methods do not support'): self.manager.delete(s3_object_lambda_arn, self.key)
def test_cntrl_c_in_context_manager_cancels_incomplete_transfers(self): # The purpose of this test is to make sure if an error is raised # in the body of the context manager, incomplete transfers will # be cancelled with value of the exception wrapped by a CancelledError # NOTE: The fact that delete() was chosen to test this is arbitrary # other than it is the easiet to set up for the stubber. # The specific operation is not important to the purpose of this test. num_transfers = 100 futures = [] for _ in range(num_transfers): self.stubber.add_response('delete_object', {}) manager = TransferManager( self.client, TransferConfig(max_request_concurrency=1, max_submission_concurrency=1)) try: with manager: for i in range(num_transfers): futures.append(manager.delete('mybucket', 'mykey')) raise KeyboardInterrupt() except KeyboardInterrupt: # At least one of the submitted futures should have been # cancelled. with self.assertRaisesRegexp(CancelledError, 'KeyboardInterrupt()'): for future in futures: future.result()
def test_cntrl_c_in_context_manager_cancels_incomplete_transfers(self): # The purpose of this test is to make sure if an error is raised # in the body of the context manager, incomplete transfers will # be cancelled with value of the exception wrapped by a CancelledError # NOTE: The fact that delete() was chosen to test this is arbitrary # other than it is the easiet to set up for the stubber. # The specific operation is not important to the purpose of this test. num_transfers = 100 futures = [] for _ in range(num_transfers): self.stubber.add_response('delete_object', {}) manager = TransferManager( self.client, TransferConfig( max_request_concurrency=1, max_submission_concurrency=1) ) try: with manager: for i in range(num_transfers): futures.append(manager.delete('mybucket', 'mykey')) raise KeyboardInterrupt() except KeyboardInterrupt: # At least one of the submitted futures should have been # cancelled. with self.assertRaisesRegexp( CancelledError, 'KeyboardInterrupt()'): for future in futures: future.result()
def test_use_custom_executor_implementation(self): mocked_executor_cls = mock.Mock(BaseExecutor) transfer_manager = TransferManager(self.client, executor_cls=mocked_executor_cls) transfer_manager.delete('bucket', 'key') self.assertTrue(mocked_executor_cls.return_value.submit.called)