diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-03-23 18:39:36 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-03-23 18:41:51 +0100 |
commit | fbc1ce06eede24d34b339008f41dda70a0cb0ec7 (patch) | |
tree | 953fb3a67afe99813d082c9ddc5ddcd10ba8c3b8 /src/tests/test_dict_search.py | |
parent | 9f6f3197578792397f225e01b0379107f1c7ea32 (diff) | |
download | vyos-1x-fbc1ce06eede24d34b339008f41dda70a0cb0ec7.tar.gz vyos-1x-fbc1ce06eede24d34b339008f41dda70a0cb0ec7.zip |
vyos.util: dict_search() should not throw exception when inputs are None
Diffstat (limited to 'src/tests/test_dict_search.py')
-rw-r--r-- | src/tests/test_dict_search.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/tests/test_dict_search.py b/src/tests/test_dict_search.py index 6a0fc74ad..991722f0f 100644 --- a/src/tests/test_dict_search.py +++ b/src/tests/test_dict_search.py @@ -20,6 +20,7 @@ from vyos.util import dict_search data = { 'string': 'fooo', 'nested': {'string': 'bar', 'empty': '', 'list': ['foo', 'bar']}, + 'non': {}, 'list': ['bar', 'baz'], 'dict': {'key_1': {}, 'key_2': 'vyos'} } @@ -30,7 +31,8 @@ class TestDictSearch(TestCase): def test_non_existing_keys(self): # TestDictSearch: Return False when querying for non-existent key - self.assertFalse(dict_search('non_existing', data)) + self.assertEqual(dict_search('non_existing', data), None) + self.assertEqual(dict_search('non.existing.fancy.key', data), None) def test_string(self): # TestDictSearch: Return value when querying string @@ -50,8 +52,14 @@ class TestDictSearch(TestCase): def test_nested_dict_key_empty(self): # TestDictSearch: Return False when querying for a nested string whose last key is empty + self.assertEqual(dict_search('nested.empty', data), '') 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']) + + def test_invalid_input(self): + # TestDictSearch: Return list items when querying nested list + self.assertEqual(dict_search('nested.list', None), None) + self.assertEqual(dict_search(None, data), None) |