aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests
diff options
context:
space:
mode:
authorLinda Wang <wangwulin@huawei.com>2017-08-17 11:39:37 +0000
committerLinda Wang <wangwulin@huawei.com>2017-08-17 11:39:37 +0000
commit3900d3c3efa75e0a382183154c534e67b199152c (patch)
treedebb844e6dc73663415b908aa0f7e199ff635364 /functest/tests
parentc582427bd2586347fd21bcee3b28a2f7e75faf3d (diff)
Obtain pod_name by CONST instead of get function
JIRA: FUNCTEST-763 Change-Id: Id334745a1eac8b933d77f9cb36a506a02366d760 Signed-off-by: Linda Wang <wangwulin@huawei.com>
Diffstat (limited to 'functest/tests')
-rw-r--r--functest/tests/unit/energy/test_functest_energy.py36
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py26
2 files changed, 15 insertions, 47 deletions
diff --git a/functest/tests/unit/energy/test_functest_energy.py b/functest/tests/unit/energy/test_functest_energy.py
index a576e2c3..5e2254ad 100644
--- a/functest/tests/unit/energy/test_functest_energy.py
+++ b/functest/tests/unit/energy/test_functest_energy.py
@@ -17,7 +17,7 @@ import mock
from functest.energy.energy import EnergyRecorder
import functest.energy.energy as energy
-
+from functest.utils.constants import CONST
CASE_NAME = "UNIT_TEST_CASE"
STEP_NAME = "UNIT_TEST_STEP"
@@ -237,16 +237,14 @@ class EnergyRecorderTest(unittest.TestCase):
return_value={"scenario": PREVIOUS_SCENARIO,
"step": PREVIOUS_STEP})
@mock.patch("functest.energy.energy.EnergyRecorder")
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.utils.functest_utils.get_functest_config",
side_effect=config_loader_mock)
def test_decorators_with_previous(self,
loader_mock=None,
- pod_mock=None,
recorder_mock=None,
cur_scenario_mock=None):
"""Test energy module decorators."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
self.__decorated_method()
calls = [mock.call.start(self.case_name),
mock.call.submit_scenario(PREVIOUS_SCENARIO,
@@ -274,13 +272,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
side_effect=config_loader_mock)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
- def test_load_config(self, loader_mock=None, pod_mock=None,
- get_mock=None):
+ def test_load_config(self, loader_mock=None, get_mock=None):
"""Test load config."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
@@ -295,13 +291,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
side_effect=config_loader_mock_no_creds)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
- def test_load_config_no_creds(self, loader_mock=None, pod_mock=None,
- get_mock=None):
+ def test_load_config_no_creds(self, loader_mock=None, get_mock=None):
"""Test load config without creds."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
self.assertEquals(EnergyRecorder.energy_recorder_api["auth"], None)
@@ -312,13 +306,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
return_value=None)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
- def test_load_config_ex(self, loader_mock=None, pod_mock=None,
- get_mock=None):
+ def test_load_config_ex(self, loader_mock=None, get_mock=None):
"""Test load config with exception."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
with self.assertRaises(AssertionError):
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
@@ -326,13 +318,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
side_effect=config_loader_mock)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.energy.energy.requests.get",
return_value=API_KO)
- def test_load_config_api_ko(self, loader_mock=None, pod_mock=None,
- get_mock=None):
+ def test_load_config_api_ko(self, loader_mock=None, get_mock=None):
"""Test load config with API unavailable."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
self.assertEquals(EnergyRecorder.energy_recorder_api["available"],
@@ -340,13 +330,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
return_value=None)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch('functest.energy.energy.requests.get',
return_value=RECORDER_OK)
- def test_get_current_scenario(self, loader_mock=None,
- pod_mock=None, get_mock=None):
+ def test_get_current_scenario(self, loader_mock=None, get_mock=None):
"""Test get_current_scenario."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
self.test_load_config()
scenario = EnergyRecorder.get_current_scenario()
self.assertTrue(scenario is not None)
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index b4cc5b73..cd3693c7 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -150,32 +150,12 @@ class FunctestUtilsTesting(unittest.TestCase):
self.assertEqual(functest_utils.get_version(), "unknown")
@mock.patch('functest.utils.functest_utils.logger.info')
- def test_get_pod_name_failed(self, mock_logger_info):
- with mock.patch.dict(os.environ,
- {},
- clear=True):
- self.assertEqual(functest_utils.get_pod_name(),
- "unknown-pod")
- mock_logger_info.assert_called_once_with("Unable to retrieve "
- "the POD name from "
- "environment. Using "
- "pod name 'unknown-pod'")
-
- def test_get_pod_name_default(self):
- with mock.patch.dict(os.environ,
- {'NODE_NAME': 'test_node_name'},
- clear=True):
- self.assertEqual(functest_utils.get_pod_name(),
- self.node_name)
-
- @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)
CONST.__setattr__('BUILD_TAG', self.build_tag)
- with mock.patch('functest.utils.functest_utils.get_pod_name',
- return_value=self.node_name), \
- mock.patch('functest.utils.functest_utils.get_scenario',
- return_value=self.scenario), \
+ CONST.__setattr__('NODE_NAME', self.node_name)
+ with mock.patch('functest.utils.functest_utils.get_scenario',
+ return_value=self.scenario), \
mock.patch('functest.utils.functest_utils.get_version',
return_value=self.version):
functest_utils.logger_test_results(self.project, self.case_name,