def test_handle_invalid_regions(self, captured_log): cmd = 'include-regions' self.pm.handle_command(cmd, [cmd, REG1, 'oof']) check_logs(captured_log, 'bac.profile_manager', 'WARNING', ['Following regions have not been found:', 'oof']) expected = {REG1} self.assertEqual(self.pm.active_regions, expected)
def test_handle_all_profiles_invalid(self, faked_session): faked_session.side_effect = BotoCoreError with LogCapture() as captured_log: with self.assertRaises(errors.NoProfilesError): profile_manager.ProfileManager() check_logs(captured_log, 'bac.profile_manager', 'ERROR', ['No valid profiles found', 'Exiting BAC.'])
def test_handle_invalid_profiles(self, captured_log): cmd = 'include-profiles' self.pm.handle_command(cmd, [cmd, PROFILE1, 'foo']) check_logs(captured_log, 'bac.profile_manager', 'WARNING', ['Following profiles/roles have not been found:', 'foo']) expected = {PROFILE1} self.assertEqual(self.pm.active_profiles, expected)
def test_handle_execution_error(self, execute_command): err = b'error message' execute_command.return_value = ('', err, 1) with LogCapture(level=logging.ERROR) as captured_log: batch.CommandBatch(self.globals, self.argv, self.checker) check_logs(captured_log, 'bac.batch', 'ERROR', ['An error occured: ', 'error message'])
def test_handle_exit_code(self, execute_command): execute_command.return_value = ('', '', 1) with LogCapture(level=logging.WARNING) as captured_log: batch.CommandBatch(self.globals, self.argv, self.checker) check_logs(captured_log, 'bac.batch', 'WARNING', [ 'Command', 'foo', 'ended with following non-zero exit code:', '1' ])
def test_handle_aws_completer_error(self, awscli_complete): awscli_complete.side_effect = Exception() with LogCapture(level=logging.ERROR) as captured_log: c = self.get_completions('aws s3ap') self.assertEqual(c, list()) check_logs(captured_log, 'bac.bac_completer', 'ERROR', 'Failed to complete aws command.')
def test_handle_timeout(self, execute_command): execute_command.side_effect = errors.TimeoutException() with LogCapture(level=logging.ERROR) as captured_log: batch.CommandBatch(self.globals, self.argv, self.checker) check_logs(captured_log, 'bac.batch', 'ERROR', [ 'Timeout of 30 seconds reached when' ' executing following command:\n', 'foo' ])
def test_handle_parse_error(self, parse): parse.side_effect = configparser.ParsingError(filename='foo') with LogCapture() as captured_log: with self.assertRaises(errors.NoProfilesError): profile_manager.ProfileManager() check_logs(captured_log, 'bac.profile_manager', 'ERROR', [ 'Failed to parse user profiles', 'error occured while parsing', 'Exiting BAC' ])
def test_handle_missing_config_file(self, captured_log): profile_manager.ProfileManager() check_logs(captured_log, 'bac.profile_manager', 'ERROR', ['Failed to parse role profiles', 'File not found'])
def test_handle_missing_credentials_file(self, captured_log): with self.assertRaises(errors.NoProfilesError): profile_manager.ProfileManager() check_logs( captured_log, 'bac.profile_manager', 'ERROR', ['Failed to parse user profiles', 'File not found', 'Exiting BAC'])
def test_handle_no_path(self, captured_log): self.argv[1] = '--bac-no-check' with captured_output() as (out, err): batch.CommandBatch(self.globals, self.argv, self.checker) check_logs(captured_log, 'bac.utils', 'ERROR', 'arguments')
def test_handle_no_commands(self, captured_log): self.argv = self.argv[:1] with captured_output() as (out, err): batch.CommandBatch(self.globals, self.argv, self.checker) check_logs(captured_log, 'bac.utils', 'ERROR', 'arguments')
def test_globals_parser_error(self, captured_log): parser = utils.GlobalsParser() with captured_output() as (out, err): parser.error('Error') check_logs(captured_log, 'bac.utils', 'WARNING', 'error: Error\n')