def test_archive_logs_src_file_exists(self, mock_os, mock_utils, mock_config): t_runner.FunctestRunner.create_log() mock_config.dovetail_config = {'result_dir': 'result_dir'} docker_runner = t_runner.FunctestRunner(self.testcase) mock_os.environ = {'DOVETAIL_HOME': 'dovetail_home'} mock_utils.get_value_from_dict.side_effect = [['src_file'], ['dst_file']] mock_os.path.join.side_effect = ['result_path', 'src_file_path', 'dest_file_path'] mock_os.path.isfile.return_value = True result = docker_runner.archive_logs() mock_os.path.join.assert_has_calls([ call('dovetail_home', 'results'), call('result_path', 'src_file'), call('result_path', 'dst_file')]) mock_utils.get_value_from_dict.assert_has_calls([ call('report.source_archive_files', self.testcase_dict), call('report.dest_archive_files', self.testcase_dict)]) mock_os.path.isfile.assert_has_calls([call('src_file_path')]) mock_os.renames.assert_called_once_with( 'src_file_path', 'dest_file_path') self.assertEqual(True, result)
def test_archive_logs_no_files(self, mock_os, mock_utils, mock_config): t_runner.FunctestRunner.create_log() mock_config.dovetail_config = {'result_dir': 'result_dir'} docker_runner = t_runner.FunctestRunner(self.testcase) mock_os.environ = {'DOVETAIL_HOME': 'dovetail_home'} mock_utils.get_value_from_dict.return_value = [] result = docker_runner.archive_logs() mock_os.path.join.assert_has_calls([call('dovetail_home', 'results')]) mock_utils.get_value_from_dict.assert_has_calls([ call('report.source_archive_files', self.testcase_dict), call('report.dest_archive_files', self.testcase_dict)]) self.assertEqual(True, result)
def test_archive_logs_difference_in_files(self, mock_os, mock_utils, mock_config): t_runner.FunctestRunner.create_log() mock_config.dovetail_config = {'result_dir': 'result_dir'} docker_runner = t_runner.FunctestRunner(self.testcase) mock_os.environ = {'DOVETAIL_HOME': 'dovetail_home'} mock_utils.get_value_from_dict.side_effect = [[], ['file']] result = docker_runner.archive_logs() mock_os.path.join.assert_has_calls([call('dovetail_home', 'results')]) mock_utils.get_value_from_dict.assert_has_calls([ call('report.source_archive_files', self.testcase_dict), call('report.dest_archive_files', self.testcase_dict)]) docker_runner.logger.error.assert_called_once_with( "Can't find corresponding 'result_dest_files' " "for 'result_source_files' with testcase {}" .format(self.testcase_name)) self.assertEqual(False, result)
def test_run__not_offline_prepare(self, mock_container, mock_config, mock_utils): t_runner.FunctestRunner.create_log() mock_config.dovetail_config = { 'offline': False, 'noclean': False, 'result_dir': 'result_dir' } docker_runner = t_runner.FunctestRunner(self.testcase) container_obj = Mock() docker_img_obj = Mock() container_obj.get_docker_image.return_value = docker_img_obj container_obj.pull_image.return_value = True container_id = '12345' container_msg = 'Successfully to create container.' container_obj.create.return_value = [container_id, container_msg] mock_container.return_value = container_obj self.testcase.pre_condition.return_value = ['cmd'] self.testcase.prepare_cmd.return_value = True self.testcase.post_condition.return_value = ['cmd'] self.testcase.cmds = ['cmd'] container_obj.exec_cmd.return_value = (1, 'error') docker_runner.run() mock_container.assert_called_once_with(self.testcase) container_obj.get_docker_image.assert_called_once_with() container_obj.pull_image.assert_called_once_with(docker_img_obj) container_obj.create.assert_called_once_with(docker_img_obj) docker_runner.logger.debug.assert_called_with( 'container id: {}'.format(container_id)) self.testcase.pre_condition.assert_called_once_with() container_obj.exec_cmd.assert_has_calls([ call('cmd'), call('cmd'), call('cmd')]) self.testcase.prepare_cmd.assert_called_once_with(self.testcase_type) self.testcase.post_condition.assert_called_once_with() docker_runner.logger.error.assert_has_calls([ call('Failed to exec all pre_condition cmds.'), call('Failed to exec {}, ret: {}, msg: {}' .format('cmd', 1, 'error'))]) container_obj.clean.assert_called_once_with()