From c92c49a9031602030f0f4d4fe2f99a9054eabaee Mon Sep 17 00:00:00 2001 From: Stamatis Katsaounis Date: Thu, 8 Nov 2018 16:58:09 +0200 Subject: Add missing unit tests for utils files JIRA: DOVETAIL-724 This patch adds unit tests which were missing from dovetail code base. Furthermore it updates the test_parser existing unit test. Finally, it fixes some minor issues in dovetail_utils itself. Change-Id: I8fd7cd4f6b1ede11664914746d2279f062511639 Signed-off-by: Stamatis Katsaounis --- dovetail/tests/unit/utils/test_dovetail_config.py | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 dovetail/tests/unit/utils/test_dovetail_config.py (limited to 'dovetail/tests/unit/utils/test_dovetail_config.py') diff --git a/dovetail/tests/unit/utils/test_dovetail_config.py b/dovetail/tests/unit/utils/test_dovetail_config.py new file mode 100644 index 00000000..c7ac5b96 --- /dev/null +++ b/dovetail/tests/unit/utils/test_dovetail_config.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# +# Copyright (c) 2018 mokats@intracom-telecom.com 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 +# http://www.apache.org/licenses/LICENSE-2.0 +## + +import unittest +from mock import patch + +from dovetail.utils.dovetail_config import DovetailConfig + +__author__ = 'Stamatis Katsaounis ' + + +class DovetailConfigTesting(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + @patch.object(DovetailConfig, 'update_non_envs') + def test_update_config(self, mock_non_envs): + config_dict = {'key': {'path': ['aa / bb/ cc'], 'value': 'val'}} + dovetail_cfg = DovetailConfig() + + dovetail_cfg.update_config(config_dict) + + mock_non_envs.assert_called_once_with(['aa', 'bb', 'cc'], 'val') + + def test_set_leaf_dict(self): + dict_to_test = {} + dovetail_cfg = DovetailConfig() + + dovetail_cfg.set_leaf_dict(dict_to_test, ['aa', 'bb', 'cc'], 'val') + + self.assertEquals({'aa': {'bb': {'cc': 'val'}}}, dict_to_test) + + @patch.object(DovetailConfig, 'set_leaf_dict') + @patch.object(DovetailConfig, 'dovetail_config') + def test_update_non_envs(self, mock_cfg, mock_set_leaf): + path = ['aa', 'bb', 'cc'] + value = 'val' + dovetail_cfg = DovetailConfig() + + dovetail_cfg.update_non_envs(path, value) + + mock_set_leaf.assert_called_once_with(mock_cfg, path, value) -- cgit 1.2.3-korg