Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/s3/test_rb_command.py
1567 views
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 awscli.testutils import BaseAWSCommandParamsTest
14
15
16
class TestRb(BaseAWSCommandParamsTest):
17
18
prefix = 's3 rb '
19
20
def test_rb(self):
21
command = self.prefix + 's3://bucket'
22
self.run_cmd(command)
23
self.assertEqual(len(self.operations_called), 1)
24
self.assertEqual(self.operations_called[0][0].name, 'DeleteBucket')
25
26
def test_rb_force_empty_bucket(self):
27
command = self.prefix + 's3://bucket --force'
28
self.run_cmd(command)
29
self.assertEqual(len(self.operations_called), 2)
30
self.assertEqual(self.operations_called[0][0].name, 'ListObjectsV2')
31
self.assertEqual(self.operations_called[1][0].name, 'DeleteBucket')
32
33
def test_rb_force_non_empty_bucket(self):
34
command = self.prefix + 's3://bucket --force'
35
self.parsed_responses = [{
36
'Contents': [
37
{
38
'Key': 'foo',
39
'Size': 100,
40
'LastModified': '2016-03-01T23:50:13.000Z'
41
}
42
]
43
}, {}, {}]
44
self.run_cmd(command)
45
self.assertEqual(len(self.operations_called), 3)
46
self.assertEqual(self.operations_called[0][0].name, 'ListObjectsV2')
47
self.assertEqual(self.operations_called[1][0].name, 'DeleteObject')
48
self.assertEqual(self.operations_called[2][0].name, 'DeleteBucket')
49
50
def test_rb_failed_rc(self):
51
command = self.prefix + 's3://bucket'
52
self.http_response.status_code = 500
53
_, stderr, _ = self.run_cmd(command, expected_rc=1)
54
self.assertIn('remove_bucket failed:', stderr)
55
56
def test_rb_force_with_failed_rm(self):
57
command = self.prefix + 's3://bucket --force'
58
self.http_response.status_code = 500
59
_, stderr, _ = self.run_cmd(command, expected_rc=255)
60
self.assertIn('remove_bucket failed:', stderr)
61
self.assertEqual(len(self.operations_called), 1)
62
self.assertEqual(self.operations_called[0][0].name, 'ListObjectsV2')
63
64
def test_nonzero_exit_if_uri_scheme_not_provided(self):
65
command = self.prefix + 'bucket'
66
self.run_cmd(command, expected_rc=255)
67
68
def test_nonzero_exit_if_key_provided(self):
69
command = self.prefix + 's3://bucket/key --force'
70
self.run_cmd(command, expected_rc=255)
71
72
command = self.prefix + 's3://bucket/key'
73
self.run_cmd(command, expected_rc=255)
74
75