diff options
author | 2017-07-03 14:13:24 +0000 | |
---|---|---|
committer | 2017-07-03 14:13:24 +0000 | |
commit | 3ccd401b18775cf152e883c44cc4937287f4e62d (patch) | |
tree | c69efd7884efd308338df311e1d754ee6a0c85b8 /functest/tests | |
parent | 8d6a21b56cc49573e9eb965dcc242acced0ba731 (diff) | |
parent | ff2e2227b28f18ebbc265eee6ee5a50cabacc075 (diff) |
Merge "Energy monitoring SDK update."
Diffstat (limited to 'functest/tests')
-rw-r--r-- | functest/tests/unit/energy/test_functest_energy.py | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/functest/tests/unit/energy/test_functest_energy.py b/functest/tests/unit/energy/test_functest_energy.py index 6387b97b..177788bc 100644 --- a/functest/tests/unit/energy/test_functest_energy.py +++ b/functest/tests/unit/energy/test_functest_energy.py @@ -1,5 +1,8 @@ #!/usr/bin/env python +# -*- coding: UTF-8 -*- +# Copyright (c) 2017 Orange and others. +# # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at @@ -16,8 +19,11 @@ from functest.energy.energy import EnergyRecorder import functest.energy.energy as energy -CASE_NAME = "UNIT_test_CASE" -STEP_NAME = "UNIT_test_STEP" +CASE_NAME = "UNIT_TEST_CASE" +STEP_NAME = "UNIT_TEST_STEP" + +PREVIOUS_SCENARIO = "previous_scenario" +PREVIOUS_STEP = "previous_step" class MockHttpResponse(object): # pylint: disable=too-few-public-methods @@ -197,6 +203,8 @@ class EnergyRecorderTest(unittest.TestCase): """Call with to energy recorder decorators.""" raise Exception(self.exception_message_to_preserve) + @mock.patch("functest.energy.energy.EnergyRecorder.get_current_scenario", + return_value=None) @mock.patch("functest.energy.energy.EnergyRecorder") @mock.patch("functest.utils.functest_utils.get_pod_name", return_value="MOCK_POD") @@ -205,13 +213,34 @@ class EnergyRecorderTest(unittest.TestCase): def test_decorators(self, loader_mock=None, pod_mock=None, - recorder_mock=None): + recorder_mock=None, + cur_scenario_mock=None): """Test energy module decorators.""" self.__decorated_method() calls = [mock.call.start(self.case_name), mock.call.stop()] recorder_mock.assert_has_calls(calls) + @mock.patch("functest.energy.energy.EnergyRecorder.get_current_scenario", + 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.""" + self.__decorated_method() + calls = [mock.call.start(self.case_name), + mock.call.submit_scenario(PREVIOUS_SCENARIO, + PREVIOUS_STEP)] + recorder_mock.assert_has_calls(calls) + def test_decorator_preserve_return(self): """Test that decorator preserve method returned value.""" self.test_load_config() @@ -270,6 +299,19 @@ class EnergyRecorderTest(unittest.TestCase): EnergyRecorder.load_config() self.assertEquals(EnergyRecorder.energy_recorder_api, None) + @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): + """Test get_current_scenario.""" + self.test_load_config() + scenario = EnergyRecorder.get_current_scenario() + self.assertTrue(scenario is not None) + if __name__ == "__main__": logging.disable(logging.CRITICAL) |