from awscli.testutils import BaseAWSCommandParamsTest
class TestMBCommand(BaseAWSCommandParamsTest):
prefix = 's3 mb '
def test_make_bucket(self):
command = self.prefix + 's3://bucket'
self.run_cmd(command)
self.assertEqual(len(self.operations_called), 1)
self.assertEqual(self.operations_called[0][0].name, 'CreateBucket')
def test_adds_location_constraint(self):
command = self.prefix + 's3://bucket --region us-west-2'
self.parsed_responses = [{'Location': 'us-west-2'}]
expected_params = {
'Bucket': 'bucket',
'CreateBucketConfiguration': {
'LocationConstraint': 'us-west-2'
}
}
self.assert_params_for_cmd(command, expected_params)
def test_location_constraint_not_added_on_us_east_1(self):
command = self.prefix + 's3://bucket --region us-east-1'
expected_params = {
'Bucket': 'bucket'
}
self.assert_params_for_cmd(command, expected_params)
def test_nonzero_exit_if_invalid_path_provided(self):
command = self.prefix + 'bucket'
self.run_cmd(command, expected_rc=255)
def test_incompatible_with_express_directory_bucket(self):
command = self.prefix + 's3://bucket--usw2-az1--x-s3/'
stderr = self.run_cmd(command, expected_rc=255)[1]
self.assertIn('Cannot use mb command with a directory bucket.', stderr)