test_delete.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.delete import DeleteObjectTask
  14. from tests import BaseTaskTest
  15. class TestDeleteObjectTask(BaseTaskTest):
  16. def setUp(self):
  17. super().setUp()
  18. self.bucket = 'mybucket'
  19. self.key = 'mykey'
  20. self.extra_args = {}
  21. self.callbacks = []
  22. def get_delete_task(self, **kwargs):
  23. default_kwargs = {
  24. 'client': self.client,
  25. 'bucket': self.bucket,
  26. 'key': self.key,
  27. 'extra_args': self.extra_args,
  28. }
  29. default_kwargs.update(kwargs)
  30. return self.get_task(DeleteObjectTask, main_kwargs=default_kwargs)
  31. def test_main(self):
  32. self.stubber.add_response(
  33. 'delete_object',
  34. service_response={},
  35. expected_params={
  36. 'Bucket': self.bucket,
  37. 'Key': self.key,
  38. },
  39. )
  40. task = self.get_delete_task()
  41. task()
  42. self.stubber.assert_no_pending_responses()
  43. def test_extra_args(self):
  44. self.extra_args['MFA'] = 'mfa-code'
  45. self.extra_args['VersionId'] = '12345'
  46. self.stubber.add_response(
  47. 'delete_object',
  48. service_response={},
  49. expected_params={
  50. 'Bucket': self.bucket,
  51. 'Key': self.key,
  52. # These extra_args should be injected into the
  53. # expected params for the delete_object call.
  54. 'MFA': 'mfa-code',
  55. 'VersionId': '12345',
  56. },
  57. )
  58. task = self.get_delete_task()
  59. task()
  60. self.stubber.assert_no_pending_responses()