Exemple #1
0
    def test_pre_copy_path(self):
        testcase = tcase.Testcase(self.testcase_yaml)
        testcase.testcase['validate']['pre_copy'] = {'key': 'value'}

        result = testcase.pre_copy_path('key')

        self.assertEqual('value', result)
Exemple #2
0
    def test_post_condition_exists(self):
        testcase = tcase.Testcase(self.testcase_yaml)
        testcase.testcase['validate']['post_condition'] = 'post_condition'

        result = testcase.post_condition()

        self.assertEqual('post_condition', result)
Exemple #3
0
    def test_sub_testcase_passed(self):
        testcase = tcase.Testcase(self.testcase_yaml)
        logger_obj = Mock()
        testcase.logger = logger_obj

        result = testcase.sub_testcase_passed('name', 'passed')

        self.assertEqual('passed', result)
Exemple #4
0
    def test_increase_retry(self):
        testcase = tcase.Testcase(self.testcase_yaml)
        tcase.Testcase.validate_testcase_list[
            'tempest_smoke_serial'] = {'retry': 0}

        for _ in range(0, 42):
            result = testcase.increase_retry()
        self.assertEquals(42, result)
Exemple #5
0
    def test_sub_testcase(self, mock_utils):
        testcase = tcase.Testcase(self.testcase_yaml)
        mock_utils.get_value_from_dict.return_value = 'value'

        result = testcase.sub_testcase()

        mock_utils.get_value_from_dict.assert_called_once_with(
            'report.sub_testcase_list', testcase.testcase)
        self.assertEqual('value', result)
Exemple #6
0
    def test_post_condition_not_exists(self, mock_post_condition):
        testcase = tcase.Testcase(self.testcase_yaml)
        logger_obj = Mock()
        testcase.logger = logger_obj
        mock_post_condition.return_value = False

        result = testcase.post_condition()

        mock_post_condition.assert_called_once_with('functest')
        logger_obj.debug.assert_called_once_with(
            'Test case: {} post_condition is empty.'.format(testcase.name()))
        self.assertEqual(False, result)
Exemple #7
0
    def test_run(self, mock_factory):
        testcase = tcase.Testcase(self.testcase_yaml)
        logger_obj = Mock()
        testcase.logger = logger_obj
        runner_obj = Mock()
        mock_factory.create.return_value = runner_obj
        error_msg = 'An error happened!'
        runner_obj.archive_logs.side_effect = AttributeError(error_msg)

        testcase.run()

        runner_obj.run.assert_called_once_with()
        runner_obj.archive_logs.assert_called_once_with()
        logger_obj.exception.assert_called_once_with(
            'Test case: {} Exception: {}'.format(testcase.name, error_msg))
Exemple #8
0
    def test_mk_src_file_exception(self, mock_sub_testcase, mock_config,
                                   mock_path, mock_open):
        testcase = tcase.Testcase(self.testcase_yaml)
        logger_obj = Mock()
        testcase.logger = logger_obj
        mock_config.dovetail_config = {'result_dir': 'value'}
        sub_test = 'sub_test'
        file_path = 'file_path'
        mock_path.join.return_value = file_path
        mock_sub_testcase.return_value = [sub_test]
        mock_open.return_value.__enter__.side_effect = Exception()

        result = testcase.mk_src_file()

        mock_path.join.assert_called_once_with('value', 'tempest_custom.txt')
        mock_open.assert_called_once_with(file_path, 'w+')
        logger_obj.exception('Failed to save: {}'.format(file_path))
        self.assertEqual(None, result)
Exemple #9
0
    def test_load(self, mock_constants, mock_factory, mock_os, mock_yaml,
                  mock_open):
        testcase = tcase.Testcase(self.testcase_yaml)
        mock_constants.TESTCASE_PATH = 'abs_path'
        mock_os.walk.return_value = [('root', ['dir'], ['file'])]
        mock_os.path.join.return_value = 'testcase_path'
        file_obj = Mock()
        mock_open.return_value.__enter__.return_value = file_obj
        yaml_dict = {'key': {'validate': {'type': 'value'}}}
        mock_yaml.safe_load.return_value = yaml_dict
        runner_obj = Mock()
        mock_factory.create.return_value = runner_obj

        testcase.load()

        mock_os.walk.assert_called_once_with('abs_path')
        mock_os.path.join.assert_called_with('root', 'file')
        mock_open.assert_called_once_with('testcase_path')
        mock_yaml.safe_load.assert_called_once_with(file_obj)
        mock_factory.create.assert_called_once_with('value', yaml_dict)
        self.assertEqual(runner_obj, tcase.Testcase.get('key'))
Exemple #10
0
    def test_mk_src_file(self, mock_sub_testcase, mock_config, mock_path,
                         mock_open):
        testcase = tcase.Testcase(self.testcase_yaml)
        logger_obj = Mock()
        testcase.logger = logger_obj
        mock_config.dovetail_config = {'result_dir': 'value'}
        sub_test = 'sub_test'
        file_path = 'file_path'
        mock_path.join.return_value = file_path
        mock_sub_testcase.return_value = [sub_test]
        file_obj = Mock()
        mock_open.return_value.__enter__.return_value = file_obj

        result = testcase.mk_src_file()

        mock_path.join.assert_called_once_with('value', 'tempest_custom.txt')
        mock_open.assert_called_once_with(file_path, 'w+')
        file_obj.write.assert_called_once_with(sub_test + '\n')
        logger_obj.debug.assert_called_once_with(
            'Save test cases to {}'.format(file_path))
        self.assertEqual(file_path, result)
Exemple #11
0
    def test_pre_copy_path_error(self):
        testcase = tcase.Testcase(self.testcase_yaml)

        result = testcase.pre_copy_path('key')

        self.assertEqual(None, result)
Exemple #12
0
    def test_set_get_results(self):
        testcase = tcase.Testcase(self.testcase_yaml)

        testcase.set_results('results')

        self.assertEqual('results', testcase.get_results())
Exemple #13
0
    def test_passed(self):
        testcase = tcase.Testcase(self.testcase_yaml)

        result = testcase.passed('passed')

        self.assertEqual('passed', result)
Exemple #14
0
    def test_portal_key_file(self):
        testcase = tcase.Testcase(self.testcase_yaml)

        result = testcase.portal_key_file()

        self.assertEqual('tempest_logs/tempest_smoke_serial.html', result)
Exemple #15
0
    def test_validate_testcase(self):
        testcase = tcase.Testcase(self.testcase_yaml)

        result = testcase.validate_testcase()

        self.assertEqual('tempest_smoke_serial', result)
Exemple #16
0
    def test_validate_type(self):
        testcase = tcase.Testcase(self.testcase_yaml)

        result = testcase.validate_type()

        self.assertEqual('functest', result)