diff options
author | John Estabrook <jestabro@vyos.io> | 2022-10-21 13:35:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 13:35:48 -0500 |
commit | f157aea8c7dddd159c9daecc528250370d560db2 (patch) | |
tree | de3cd73f58d8890a0bc8bdb4328f7af5d270ad58 /src/tests | |
parent | eeb7810f4240a2c1d1da0bcc6825ae9c75ca693e (diff) | |
parent | b6d2e0a4b08c81814cb2d9b5b611cbc3fc31dbeb (diff) | |
download | vyos-1x-f157aea8c7dddd159c9daecc528250370d560db2.tar.gz vyos-1x-f157aea8c7dddd159c9daecc528250370d560db2.zip |
Merge pull request #1611 from dmbaturin/field-normalization-2
T4765: support list and primitives in op mode output normalization
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_op_mode.py | 25 |
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"]) + |