Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/s3/test_mb_command.py
1567 views
1
#!/usr/bin/env python
2
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License"). You
5
# may not use this file except in compliance with the License. A copy of
6
# the License is located at
7
#
8
# http://aws.amazon.com/apache2.0/
9
#
10
# or in the "license" file accompanying this file. This file is
11
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
# ANY KIND, either express or implied. See the License for the specific
13
# language governing permissions and limitations under the License.
14
from awscli.testutils import BaseAWSCommandParamsTest
15
16
17
class TestMBCommand(BaseAWSCommandParamsTest):
18
19
prefix = 's3 mb '
20
21
def test_make_bucket(self):
22
command = self.prefix + 's3://bucket'
23
self.run_cmd(command)
24
self.assertEqual(len(self.operations_called), 1)
25
self.assertEqual(self.operations_called[0][0].name, 'CreateBucket')
26
27
def test_adds_location_constraint(self):
28
command = self.prefix + 's3://bucket --region us-west-2'
29
self.parsed_responses = [{'Location': 'us-west-2'}]
30
expected_params = {
31
'Bucket': 'bucket',
32
'CreateBucketConfiguration': {
33
'LocationConstraint': 'us-west-2'
34
}
35
}
36
self.assert_params_for_cmd(command, expected_params)
37
38
def test_location_constraint_not_added_on_us_east_1(self):
39
command = self.prefix + 's3://bucket --region us-east-1'
40
expected_params = {
41
'Bucket': 'bucket'
42
}
43
self.assert_params_for_cmd(command, expected_params)
44
45
def test_nonzero_exit_if_invalid_path_provided(self):
46
command = self.prefix + 'bucket'
47
self.run_cmd(command, expected_rc=255)
48
49
def test_incompatible_with_express_directory_bucket(self):
50
command = self.prefix + 's3://bucket--usw2-az1--x-s3/'
51
stderr = self.run_cmd(command, expected_rc=255)[1]
52
self.assertIn('Cannot use mb command with a directory bucket.', stderr)
53