aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/utils/test_decorators.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_decorators.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_decorators.py')
-rw-r--r--functest/tests/unit/utils/test_decorators.py19
1 files changed, 6 insertions, 13 deletions
diff --git a/functest/tests/unit/utils/test_decorators.py b/functest/tests/unit/utils/test_decorators.py
index 44448f238..82291fa2d 100644
--- a/functest/tests/unit/utils/test_decorators.py
+++ b/functest/tests/unit/utils/test_decorators.py
@@ -20,6 +20,7 @@ import mock
from functest.utils import decorators
from functest.utils import functest_utils
+from functest.utils.constants import CONST
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
@@ -65,34 +66,29 @@ class DecoratorsTesting(unittest.TestCase):
'details': {}, 'criteria': self._result}
return json.dumps(data, sort_keys=True)
- @mock.patch('{}.get_db_url'.format(functest_utils.__name__),
- return_value='http://127.0.0.1')
@mock.patch('{}.get_version'.format(functest_utils.__name__),
return_value=VERSION)
@mock.patch('requests.post')
def test_http_shema(self, *args):
+ CONST.__setattr__('results_test_db_url', 'http://127.0.0.1')
self.assertTrue(functest_utils.push_results_to_db(
self._project_name, self._case_name, self._start_time,
self._stop_time, self._result, {}))
args[1].assert_called_once_with()
- args[2].assert_called_once_with()
args[0].assert_called_once_with(
'http://127.0.0.1', data=self._get_json(),
headers={'Content-Type': 'application/json'})
- @mock.patch('{}.get_db_url'.format(functest_utils.__name__),
- return_value="/dev/null")
- def test_wrong_shema(self, mock_method=None):
+ def test_wrong_shema(self):
+ CONST.__setattr__('results_test_db_url', '/dev/null')
self.assertFalse(functest_utils.push_results_to_db(
self._project_name, self._case_name, self._start_time,
self._stop_time, self._result, {}))
- mock_method.assert_called_once_with()
@mock.patch('{}.get_version'.format(functest_utils.__name__),
return_value=VERSION)
- @mock.patch('{}.get_db_url'.format(functest_utils.__name__),
- return_value=URL)
def _test_dump(self, *args):
+ CONST.__setattr__('results_test_db_url', URL)
with mock.patch.object(decorators, 'open', mock.mock_open(),
create=True) as mock_open:
self.assertTrue(functest_utils.push_results_to_db(
@@ -104,7 +100,6 @@ class DecoratorsTesting(unittest.TestCase):
self.assertIn('POST', call_args[0])
self.assertIn(self._get_json(), call_args[0])
args[0].assert_called_once_with()
- args[1].assert_called_once_with()
@mock.patch('os.makedirs')
def test_default_dump(self, mock_method=None):
@@ -116,16 +111,14 @@ class DecoratorsTesting(unittest.TestCase):
self._test_dump()
mock_method.assert_called_once_with(DIR)
- @mock.patch('{}.get_db_url'.format(functest_utils.__name__),
- return_value=URL)
@mock.patch('os.makedirs', side_effect=OSError)
def test_makedirs_exc(self, *args):
+ CONST.__setattr__('results_test_db_url', URL)
self.assertFalse(
functest_utils.push_results_to_db(
self._project_name, self._case_name, self._start_time,
self._stop_time, self._result, {}))
args[0].assert_called_once_with(DIR)
- args[1].assert_called_once_with()
if __name__ == "__main__":