示例#1
0
class TestRbCommand(unittest.TestCase):
    def setUp(self):
        self.session = mock.Mock()
        self.session.get_scoped_config.return_value = {}
        self.rb_command = RbCommand(self.session)
        self.parsed_args = FakeArgs(paths='s3://mybucket/',
                                    force=True,
                                    dir_op=False)
        self.parsed_globals = FakeArgs(region=None,
                                       endpoint_url=None,
                                       verify_ssl=None)
        self.cmd_name = 'awscli.customizations.s3.subcommands.RmCommand'
        self.arch_name = 'awscli.customizations.s3.subcommands.CommandArchitecture'

    def test_rb_command_with_force_deletes_objects_in_bucket(self):
        with mock.patch(self.cmd_name) as rm_command:
            with mock.patch(self.arch_name):
                # RmCommand returns an RmCommand instance whose __call__
                # should be the RC of the command.
                # In this case we'll have it return an RC of 0 which indicates
                # success.
                rm_command.return_value.return_value = 0
                self.rb_command._run_main(self.parsed_args,
                                          parsed_globals=self.parsed_globals)
            # Because of --force we should have called the
            # rm_command with the --recursive option.
            rm_command.return_value.assert_called_with(
                ['s3://mybucket', '--recursive'], mock.ANY)

    def test_rb_command_with_force_requires_strict_path(self):
        with self.assertRaises(ValueError):
            self.parsed_args.paths = 's3://mybucket/mykey'
            self.rb_command._run_main(self.parsed_args,
                                      parsed_globals=self.parsed_globals)
示例#2
0
class TestRbCommand(unittest.TestCase):
    def setUp(self):
        self.session = mock.Mock()
        self.session.get_scoped_config.return_value = {}
        self.rb_command = RbCommand(self.session)
        self.parsed_args = FakeArgs(path='s3://mybucket/',
                                    force=True, dir_op=False)
        self.parsed_globals = FakeArgs(region=None, endpoint_url=None,
                                       verify_ssl=None)
        self.cmd_name = 'awscli.customizations.s3.subcommands.RmCommand'
        self.arch_name = 'awscli.customizations.s3.subcommands.CommandArchitecture'

    def test_rb_command_with_force_deletes_objects_in_bucket(self):
        with mock.patch(self.cmd_name) as rm_command:
            with mock.patch(self.arch_name):
                # RmCommand returns an RmCommand instance whose __call__
                # should be the RC of the command.
                # In this case we'll have it return an RC of 0 which indicates
                # success.
                rm_command.return_value.return_value = 0
                self.rb_command._run_main(self.parsed_args,
                                          parsed_globals=self.parsed_globals)
            # Because of --force we should have called the
            # rm_command with the --recursive option.
            rm_command.return_value.assert_called_with(
                ['s3://mybucket/', '--recursive'], mock.ANY)

    def test_rb_command_with_force_requires_strict_path(self):
        with self.assertRaises(ValueError):
            self.parsed_args.path = 's3://mybucket/mykey'
            self.rb_command._run_main(self.parsed_args,
                                      parsed_globals=self.parsed_globals)
示例#3
0
 def setUp(self):
     self.session = mock.Mock()
     self.session.get_scoped_config.return_value = {}
     self.rb_command = RbCommand(self.session)
     self.parsed_args = FakeArgs(path='s3://mybucket/',
                                 force=True, dir_op=False)
     self.parsed_globals = FakeArgs(region=None, endpoint_url=None,
                                    verify_ssl=None)
     self.cmd_name = 'awscli.customizations.s3.subcommands.RmCommand'
     self.arch_name = 'awscli.customizations.s3.subcommands.CommandArchitecture'
示例#4
0
 def test_rb_command_with_force_deletes_objects_in_bucket(self):
     self.session = mock.Mock()
     self.session.get_scoped_config.return_value = {}
     rb_command = RbCommand(self.session)
     parsed_args = FakeArgs(paths='s3://mybucket/',
                            force=True,
                            dir_op=False)
     parsed_globals = FakeArgs(region=None, endpoint_url=None,
                               verify_ssl=None)
     cmd_name = 'awscli.customizations.s3.subcommands.RmCommand'
     arch_name = 'awscli.customizations.s3.subcommands.CommandArchitecture'
     with mock.patch(cmd_name) as rm_command:
         with mock.patch(arch_name):
             rb_command._run_main(parsed_args,
                                  parsed_globals=parsed_globals)
         # Because of --force we should have called the
         # rm_command with the --recursive option.
         rm_command.return_value.assert_called_with(
             ['s3://mybucket', '--recursive'], mock.ANY)
示例#5
0
    def test_rb_force_does_not_delete_bucket_on_failure(self):
        cmd = RbCommand(self.session)
        self.session.register('before-call', self.handler)
        self.responses['ListObjects'] = [(StatusCode(500), {})]

        global_args = FakeArgs(endpoint_url=None, region=None, verify_ssl=None)
        with self.assertRaisesRegexp(
                RuntimeError, "Unable to delete all objects in the bucket"):
            with capture_output():
                cmd(['s3://bucket/', '--force'], global_args)
        # Note there's no DeleteObject nor DeleteBucket calls
        # because the ListOBjects call failed.
        self.assertEqual(self.method_calls, ['ListObjects'])
示例#6
0
    def test_rb_force_deletes_bucket_on_success(self):
        cmd = RbCommand(self.session)
        self.session.register('before-call', self.handler)

        self.responses['ListObjects'] = [(StatusCode(200), {
            'Contents': [{
                'Key': 'foo',
                'Size': 100,
                'LastModified': '2016-03-01T23:50:13.000Z'
            }]
        })]
        self.responses['DeleteObject'] = [(StatusCode(200), {})]
        self.responses['DeleteBucket'] = [(StatusCode(200), {})]

        global_args = FakeArgs(endpoint_url=None, region=None, verify_ssl=None)
        rc = cmd(['s3://bucket/', '--force'], global_args)
        self.assertEqual(self.method_calls,
                         ['ListObjects', 'DeleteObject', 'DeleteBucket'])
        self.assertEqual(rc, 0)