diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-11-01 10:57:48 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-11-01 13:51:06 +0100 |
commit | 68c97eed91204904b7b2314dd9b357069db4eda5 (patch) | |
tree | 3ff5ff7ead3307da9abf11c9f75226beddad2f8b /src/tests/test_dict_search.py | |
parent | 793f25bfb801a85a217d7ff181fc462ffb560709 (diff) | |
download | vyos-1x-68c97eed91204904b7b2314dd9b357069db4eda5.tar.gz vyos-1x-68c97eed91204904b7b2314dd9b357069db4eda5.zip |
test: adjust testcase name for vyos.util.dict_search()
After renaming the function in commit 25551c5a ("vyos.util: T2995: rename
vyos_dict_search() -> dict_search()"), the test case should be renamed, too.
Diffstat (limited to 'src/tests/test_dict_search.py')
-rw-r--r-- | src/tests/test_dict_search.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/tests/test_dict_search.py b/src/tests/test_dict_search.py new file mode 100644 index 000000000..6a0fc74ad --- /dev/null +++ b/src/tests/test_dict_search.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from unittest import TestCase +from vyos.util import dict_search + +data = { + 'string': 'fooo', + 'nested': {'string': 'bar', 'empty': '', 'list': ['foo', 'bar']}, + 'list': ['bar', 'baz'], + 'dict': {'key_1': {}, 'key_2': 'vyos'} +} + +class TestDictSearch(TestCase): + def setUp(self): + pass + + def test_non_existing_keys(self): + # TestDictSearch: Return False when querying for non-existent key + self.assertFalse(dict_search('non_existing', data)) + + def test_string(self): + # TestDictSearch: Return value when querying string + self.assertEqual(dict_search('string', data), data['string']) + + def test_list(self): + # TestDictSearch: Return list items when querying list + self.assertEqual(dict_search('list', data), data['list']) + + def test_dict_key_value(self): + # TestDictSearch: Return dictionary keys value when value is present + self.assertEqual(dict_search('dict.key_2', data), data['dict']['key_2']) + + def test_nested_dict_key_value(self): + # TestDictSearch: Return string value of last key when querying for a nested string + self.assertEqual(dict_search('nested.string', data), data['nested']['string']) + + def test_nested_dict_key_empty(self): + # TestDictSearch: Return False when querying for a nested string whose last key is empty + self.assertFalse(dict_search('nested.empty', data)) + + def test_nested_list(self): + # TestDictSearch: Return list items when querying nested list + self.assertEqual(dict_search('nested.list', data), data['nested']['list']) |