summaryrefslogtreecommitdiff
path: root/src/tests/test_op_mode.py
diff options
context:
space:
mode:
authorcreate with ansible <daniil@vyos.io>2022-10-21 11:50:17 -0400
committercreate with ansible <daniil@vyos.io>2022-10-21 14:04:06 -0400
commitb6d2e0a4b08c81814cb2d9b5b611cbc3fc31dbeb (patch)
tree0a44f77e61874454b043371a76d962be95d73c58 /src/tests/test_op_mode.py
parentc8dbd6ce6cd466bd7903987e58b885f0e92d1691 (diff)
downloadvyos-1x-b6d2e0a4b08c81814cb2d9b5b611cbc3fc31dbeb.tar.gz
vyos-1x-b6d2e0a4b08c81814cb2d9b5b611cbc3fc31dbeb.zip
T4765: support list and primitives in op mode output normalization
Diffstat (limited to 'src/tests/test_op_mode.py')
-rw-r--r--src/tests/test_op_mode.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/tests/test_op_mode.py b/src/tests/test_op_mode.py
index 4786357c5..90963b3c5 100644
--- a/src/tests/test_op_mode.py
+++ b/src/tests/test_op_mode.py
@@ -37,8 +37,29 @@ class TestVyOSOpMode(TestCase):
with self.assertRaises(vyos.opmode.InternalError):
_normalize_field_names(data)
- def test_dict_fields_normalization(self):
+ def test_dict_fields_normalization_simple_dict(self):
from vyos.opmode import _normalize_field_names
- data = {"foo bar": True, "bar-baz": False}
+ data = {"foo bar": True, "Bar-Baz": False}
self.assertEqual(_normalize_field_names(data), {"foo_bar": True, "bar_baz": False})
+
+ def test_dict_fields_normalization_nested_dict(self):
+ from vyos.opmode import _normalize_field_names
+
+ data = {"foo bar": True, "bar-baz": {"baz-quux": {"quux-xyzzy": False}}}
+ self.assertEqual(_normalize_field_names(data),
+ {"foo_bar": True, "bar_baz": {"baz_quux": {"quux_xyzzy": False}}})
+
+ def test_dict_fields_normalization_mixed(self):
+ from vyos.opmode import _normalize_field_names
+
+ data = [{"foo bar": True, "bar-baz": [{"baz-quux": {"quux-xyzzy": [False]}}]}]
+ self.assertEqual(_normalize_field_names(data),
+ [{"foo_bar": True, "bar_baz": [{"baz_quux": {"quux_xyzzy": [False]}}]}])
+
+ def test_dict_fields_normalization_primitive(self):
+ from vyos.opmode import _normalize_field_names
+
+ data = [1, False, "foo"]
+ self.assertEqual(_normalize_field_names(data), [1, False, "foo"])
+