aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/utils/test_functest_utils.py
diff options
context:
space:
mode:
authorLinda Wang <wangwulin@huawei.com>2017-03-31 02:46:48 +0000
committerLinda Wang <wangwulin@huawei.com>2017-06-01 10:55:45 +0000
commit8e6b5934deef23386b8047b2f30a481ce42d32b8 (patch)
tree73d8e69e49eba8efc7f7173c0b74f9c42bb79ae9 /functest/tests/unit/utils/test_functest_utils.py
parent86aee2dcf004361b1516f28b0137b7c3fedfe8a5 (diff)
Use CONST to retrieve db_url rather than getter function
1. Remove get_db_url() 2. If TEST_DB_URL declared in env, update test_db_url in config_functest.yaml file during env preparation 3. No matter TEST_DB_URL declared in env or not, Result_DB = CONST.__getattribute__("results_test_db_url") JIRA: FUNCTEST-763 Change-Id: I20da7ef98bbcc56731e0ff7061b05c1dde6cbfc3 Signed-off-by: Linda Wang <wangwulin@huawei.com>
Diffstat (limited to 'functest/tests/unit/utils/test_functest_utils.py')
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py70
1 files changed, 27 insertions, 43 deletions
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index 12604c1a..d84a3201 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -19,6 +19,7 @@ from six.moves import urllib
from functest.tests.unit import test_utils
from functest.utils import functest_utils
+from functest.utils.constants import CONST
class FunctestUtilsTesting(unittest.TestCase):
@@ -58,6 +59,7 @@ class FunctestUtilsTesting(unittest.TestCase):
self.config_yaml = os.path.normpath(os.path.join(os.path.dirname(
os.path.abspath(__file__)), '../../../ci/config_functest.yaml'))
self.db_url_env = 'http://foo/testdb'
+ self.testcases_yaml = "test_testcases_yaml"
self.file_yaml = {'general': {'openstack': {'image_name':
'test_image_name'}}}
@@ -208,23 +210,9 @@ class FunctestUtilsTesting(unittest.TestCase):
self.assertEqual(functest_utils.get_build_tag(),
self.build_tag)
- def test_get_db_url_env_var(self):
- with mock.patch.dict(os.environ,
- {'TEST_DB_URL': self.db_url_env,
- 'CONFIG_FUNCTEST_YAML':
- "./functest/ci/config_functest.yaml"},
- clear=True):
- self.assertEqual(functest_utils.get_db_url(),
- self.db_url_env)
-
- @mock.patch('functest.utils.functest_utils.get_functest_config')
- def test_get_db_url_default(self, mock_get_functest_config):
- mock_get_functest_config.return_value = self.db_url
- self.assertEqual(functest_utils.get_db_url(), self.db_url)
- mock_get_functest_config.assert_called_once_with('results.test_db_url')
-
@mock.patch('functest.utils.functest_utils.logger.info')
def test_logger_test_results(self, mock_logger_info):
+ CONST.__setattr__('results_test_db_url', self.db_url)
with mock.patch('functest.utils.functest_utils.get_pod_name',
return_value=self.node_name), \
mock.patch('functest.utils.functest_utils.get_scenario',
@@ -232,9 +220,7 @@ class FunctestUtilsTesting(unittest.TestCase):
mock.patch('functest.utils.functest_utils.get_version',
return_value=self.version), \
mock.patch('functest.utils.functest_utils.get_build_tag',
- return_value=self.build_tag), \
- mock.patch('functest.utils.functest_utils.get_db_url',
- return_value=self.db_url):
+ return_value=self.build_tag):
functest_utils.logger_test_results(self.project, self.case_name,
self.status, self.details)
mock_logger_info.assert_called_once_with(
@@ -251,7 +237,7 @@ class FunctestUtilsTesting(unittest.TestCase):
"details:\t%(d)s\n"
% {'p': self.project,
'n': self.case_name,
- 'db': self.db_url,
+ 'db': CONST.__getattribute__('results_test_db_url'),
'pod': self.node_name,
'v': self.version,
's': self.scenario,
@@ -269,11 +255,10 @@ class FunctestUtilsTesting(unittest.TestCase):
def _test_push_results_to_db_missing_env(self, env_var):
dic = self._get_env_dict(env_var)
- with mock.patch('functest.utils.functest_utils.get_db_url',
- return_value=self.db_url), \
- mock.patch.dict(os.environ,
- dic,
- clear=True), \
+ CONST.__setattr__('results_test_db_url', self.db_url)
+ with mock.patch.dict(os.environ,
+ dic,
+ clear=True), \
mock.patch('functest.utils.functest_utils.logger.error') \
as mock_logger_error:
functest_utils.push_results_to_db(self.project, self.case_name,
@@ -297,11 +282,10 @@ class FunctestUtilsTesting(unittest.TestCase):
def test_push_results_to_db_request_post_failed(self):
dic = self._get_env_dict(None)
- with mock.patch('functest.utils.functest_utils.get_db_url',
- return_value=self.db_url), \
- mock.patch.dict(os.environ,
- dic,
- clear=True), \
+ CONST.__setattr__('results_test_db_url', self.db_url)
+ with mock.patch.dict(os.environ,
+ dic,
+ clear=True), \
mock.patch('functest.utils.functest_utils.logger.error') \
as mock_logger_error, \
mock.patch('functest.utils.functest_utils.requests.post',
@@ -320,11 +304,10 @@ class FunctestUtilsTesting(unittest.TestCase):
def test_push_results_to_db_request_post_exception(self):
dic = self._get_env_dict(None)
- with mock.patch('functest.utils.functest_utils.get_db_url',
- return_value=self.db_url), \
- mock.patch.dict(os.environ,
- dic,
- clear=True), \
+ CONST.__setattr__('results_test_db_url', self.db_url)
+ with mock.patch.dict(os.environ,
+ dic,
+ clear=True), \
mock.patch('functest.utils.functest_utils.logger.error') \
as mock_logger_error, \
mock.patch('functest.utils.functest_utils.requests.post',
@@ -338,11 +321,10 @@ class FunctestUtilsTesting(unittest.TestCase):
def test_push_results_to_db_default(self):
dic = self._get_env_dict(None)
- with mock.patch('functest.utils.functest_utils.get_db_url',
- return_value=self.db_url), \
- mock.patch.dict(os.environ,
- dic,
- clear=True), \
+ CONST.__setattr__('results_test_db_url', self.db_url)
+ with mock.patch.dict(os.environ,
+ dic,
+ clear=True), \
mock.patch('functest.utils.functest_utils.requests.post'):
self.assertTrue(functest_utils.
push_results_to_db(self.project, self.case_name,
@@ -562,11 +544,13 @@ class FunctestUtilsTesting(unittest.TestCase):
# TODO: merge_dicts
- def test_get_testcases_file_dir(self):
+ @mock.patch('functest.utils.functest_utils.get_functest_config')
+ def test_get_testcases_file_dir(self, mock_get_functest_config):
+ mock_get_functest_config.return_value = self.testcases_yaml
resp = functest_utils.get_testcases_file_dir()
- self.assertEqual(resp,
- "/home/opnfv/repos/functest/"
- "functest/ci/testcases.yaml")
+ self.assertEqual(resp, self.testcases_yaml)
+ mock_get_functest_config.assert_called_once_with(
+ 'general.functest.testcases_yaml')
def test_get_functest_yaml(self):
with mock.patch('six.moves.builtins.open', mock.mock_open()), \