summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/ci/run_tests.py19
-rw-r--r--functest/tests/unit/ci/test_run_tests.py21
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py28
-rw-r--r--functest/utils/functest_utils.py23
4 files changed, 33 insertions, 58 deletions
diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py
index 89c74a975..9edf13477 100644
--- a/functest/ci/run_tests.py
+++ b/functest/ci/run_tests.py
@@ -25,10 +25,10 @@ import pkg_resources
import enum
import prettytable
+import yaml
import functest.ci.tier_builder as tb
import functest.core.testcase as testcase
-import functest.utils.functest_utils as ft_utils
from functest.utils.constants import CONST
# __name__ cannot be used here
@@ -114,10 +114,23 @@ class Runner(object):
setattr(CONST, key, value)
@staticmethod
+ def get_dict_by_test(testname):
+ # pylint: disable=bad-continuation,missing-docstring
+ with open(pkg_resources.resource_filename(
+ 'functest', 'ci/testcases.yaml')) as tyaml:
+ testcases_yaml = yaml.safe_load(tyaml)
+ for dic_tier in testcases_yaml.get("tiers"):
+ for dic_testcase in dic_tier['testcases']:
+ if dic_testcase['case_name'] == testname:
+ return dic_testcase
+ LOGGER.error('Project %s is not defined in testcases.yaml', testname)
+ return None
+
+ @staticmethod
def get_run_dict(testname):
"""Obtain the 'run' block of the testcase from testcases.yaml"""
try:
- dic_testcase = ft_utils.get_dict_by_test(testname)
+ dic_testcase = Runner.get_dict_by_test(testname)
if not dic_testcase:
LOGGER.error("Cannot get %s's config options", testname)
elif 'run' in dic_testcase:
@@ -139,7 +152,7 @@ class Runner(object):
try:
module = importlib.import_module(run_dict['module'])
cls = getattr(module, run_dict['class'])
- test_dict = ft_utils.get_dict_by_test(test.get_name())
+ test_dict = Runner.get_dict_by_test(test.get_name())
test_case = cls(**test_dict)
self.executed_test_cases[test.get_name()] = test_case
try:
diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py
index 0bb4315ee..0b89ce271 100644
--- a/functest/tests/unit/ci/test_run_tests.py
+++ b/functest/tests/unit/ci/test_run_tests.py
@@ -55,7 +55,7 @@ class RunTestsTesting(unittest.TestCase):
self.run_tests_parser = run_tests.RunTestsParser()
- @mock.patch('functest.ci.run_tests.ft_utils.get_dict_by_test')
+ @mock.patch('functest.ci.run_tests.Runner.get_dict_by_test')
def test_get_run_dict(self, *args):
retval = {'run': mock.Mock()}
args[0].return_value = retval
@@ -63,7 +63,7 @@ class RunTestsTesting(unittest.TestCase):
args[0].assert_called_once_with('test_name')
@mock.patch('functest.ci.run_tests.LOGGER.error')
- @mock.patch('functest.ci.run_tests.ft_utils.get_dict_by_test',
+ @mock.patch('functest.ci.run_tests.Runner.get_dict_by_test',
return_value=None)
def test_get_run_dict_config_ko(self, *args):
testname = 'test_name'
@@ -77,7 +77,7 @@ class RunTestsTesting(unittest.TestCase):
args[1].assert_has_calls(calls)
@mock.patch('functest.ci.run_tests.LOGGER.exception')
- @mock.patch('functest.ci.run_tests.ft_utils.get_dict_by_test',
+ @mock.patch('functest.ci.run_tests.Runner.get_dict_by_test',
side_effect=Exception)
def test_get_run_dict_exception(self, *args):
testname = 'test_name'
@@ -113,6 +113,19 @@ class RunTestsTesting(unittest.TestCase):
self._test_source_envfile(
'export "\'OS_TENANT_NAME\'" = "\'admin\'"')
+ def test_get_dict_by_test(self):
+ with mock.patch('six.moves.builtins.open', mock.mock_open()), \
+ mock.patch('yaml.safe_load') as mock_yaml:
+ mock_obj = mock.Mock()
+ testcase_dict = {'case_name': 'testname',
+ 'criteria': 50}
+ attrs = {'get.return_value': [{'testcases': [testcase_dict]}]}
+ mock_obj.configure_mock(**attrs)
+ mock_yaml.return_value = mock_obj
+ self.assertDictEqual(
+ run_tests.Runner.get_dict_by_test('testname'),
+ testcase_dict)
+
@mock.patch('functest.ci.run_tests.Runner.get_run_dict',
return_value=None)
def test_run_tests_import_exception(self, *args):
@@ -129,7 +142,7 @@ class RunTestsTesting(unittest.TestCase):
@mock.patch('importlib.import_module', name="module",
return_value=mock.Mock(test_class=mock.Mock(
side_effect=FakeModule)))
- @mock.patch('functest.utils.functest_utils.get_dict_by_test')
+ @mock.patch('functest.ci.run_tests.Runner.get_dict_by_test')
def test_run_tests_default(self, *args):
mock_test = mock.Mock()
kwargs = {'get_name.return_value': 'test_name',
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index 218d03c42..dd34c90dc 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -55,8 +55,6 @@ class FunctestUtilsTesting(unittest.TestCase):
self.cmd = 'test_cmd'
self.output_file = 'test_output_file'
self.testname = 'testname'
- self.testcase_dict = {'case_name': 'testname',
- 'criteria': self.criteria}
self.parameter = 'general.openstack.image_name'
self.config_yaml = pkg_resources.resource_filename(
'functest', 'ci/config_functest.yaml')
@@ -255,32 +253,6 @@ class FunctestUtilsTesting(unittest.TestCase):
def _get_functest_config(self, var):
return var
- @mock.patch('functest.utils.functest_utils.LOGGER.error')
- def test_get_dict_by_test(self, mock_logger_error):
- with mock.patch('six.moves.builtins.open', mock.mock_open()), \
- mock.patch('functest.utils.functest_utils.yaml.safe_load') \
- as mock_yaml:
- mock_obj = mock.Mock()
- attrs = {'get.return_value': [{'testcases': [self.testcase_dict]}]}
- mock_obj.configure_mock(**attrs)
-
- mock_yaml.return_value = mock_obj
-
- self.assertDictEqual(functest_utils.
- get_dict_by_test(self.testname),
- self.testcase_dict)
-
- @mock.patch('functest.utils.functest_utils.get_dict_by_test')
- def test_get_criteria_by_test_default(self, mock_get_dict_by_test):
- mock_get_dict_by_test.return_value = self.testcase_dict
- self.assertEqual(functest_utils.get_criteria_by_test(self.testname),
- self.criteria)
-
- @mock.patch('functest.utils.functest_utils.get_dict_by_test')
- def test_get_criteria_by_test_failed(self, mock_get_dict_by_test):
- mock_get_dict_by_test.return_value = None
- self.assertIsNone(functest_utils.get_criteria_by_test(self.testname))
-
def test_get_parameter_from_yaml_failed(self):
self.file_yaml['general'] = None
with mock.patch('six.moves.builtins.open', mock.mock_open()), \
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index c14918554..e84a2b426 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -17,7 +17,6 @@ import shutil
import subprocess
import sys
-import pkg_resources
import dns.resolver
from six.moves import urllib
import yaml
@@ -135,28 +134,6 @@ def execute_command(cmd, info=False, error_msg="",
return returncode
-def get_dict_by_test(testname):
- # pylint: disable=bad-continuation
- with open(pkg_resources.resource_filename(
- 'functest', 'ci/testcases.yaml')) as tyaml:
- testcases_yaml = yaml.safe_load(tyaml)
-
- for dic_tier in testcases_yaml.get("tiers"):
- for dic_testcase in dic_tier['testcases']:
- if dic_testcase['case_name'] == testname:
- return dic_testcase
-
- LOGGER.error('Project %s is not defined in testcases.yaml', testname)
- return None
-
-
-def get_criteria_by_test(testname):
- tdict = get_dict_by_test(testname)
- if tdict:
- return tdict['criteria']
- return None
-
-
# ----------------------------------------------------------
#
# YAML UTILS