test_delete.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"). You
  4. # may not use this file except in compliance with the License. A copy of
  5. # the License is located at
  6. #
  7. # http://aws.amazon.com/apache2.0/
  8. #
  9. # or in the "license" file accompanying this file. This file is
  10. # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  11. # ANY KIND, either express or implied. See the License for the specific
  12. # language governing permissions and limitations under the License.
  13. from s3transfer.manager import TransferManager
  14. from tests import BaseGeneralInterfaceTest
  15. class TestDeleteObject(BaseGeneralInterfaceTest):
  16. __test__ = True
  17. def setUp(self):
  18. super().setUp()
  19. self.bucket = 'mybucket'
  20. self.key = 'mykey'
  21. self.manager = TransferManager(self.client)
  22. @property
  23. def method(self):
  24. """The transfer manager method to invoke i.e. upload()"""
  25. return self.manager.delete
  26. def create_call_kwargs(self):
  27. """The kwargs to be passed to the transfer manager method"""
  28. return {
  29. 'bucket': self.bucket,
  30. 'key': self.key,
  31. }
  32. def create_invalid_extra_args(self):
  33. return {
  34. 'BadKwargs': True,
  35. }
  36. def create_stubbed_responses(self):
  37. """A list of stubbed responses that will cause the request to succeed
  38. The elements of this list is a dictionary that will be used as key
  39. word arguments to botocore.Stubber.add_response(). For example::
  40. [{'method': 'put_object', 'service_response': {}}]
  41. """
  42. return [
  43. {
  44. 'method': 'delete_object',
  45. 'service_response': {},
  46. 'expected_params': {'Bucket': self.bucket, 'Key': self.key},
  47. }
  48. ]
  49. def create_expected_progress_callback_info(self):
  50. return []
  51. def test_known_allowed_args_in_input_shape(self):
  52. op_model = self.client.meta.service_model.operation_model(
  53. 'DeleteObject'
  54. )
  55. for allowed_arg in self.manager.ALLOWED_DELETE_ARGS:
  56. self.assertIn(allowed_arg, op_model.input_shape.members)
  57. def test_raise_exception_on_s3_object_lambda_resource(self):
  58. s3_object_lambda_arn = (
  59. 'arn:aws:s3-object-lambda:us-west-2:123456789012:'
  60. 'accesspoint:my-accesspoint'
  61. )
  62. with self.assertRaisesRegex(ValueError, 'methods do not support'):
  63. self.manager.delete(s3_object_lambda_arn, self.key)