From 605a15e8d226b7ecb663ca9a088e544b58060d06 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Mon, 14 Aug 2017 20:30:39 -0700 Subject: deepgetitem: try string index before int Change-Id: I3b353c5887db0ebbe33e37db505e72b85167b54e Signed-off-by: Ross Brattain --- tests/unit/network_services/vnf_generic/test_vnfdgen.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/unit/network_services') diff --git a/tests/unit/network_services/vnf_generic/test_vnfdgen.py b/tests/unit/network_services/vnf_generic/test_vnfdgen.py index be51e4a43..44d9058dc 100644 --- a/tests/unit/network_services/vnf_generic/test_vnfdgen.py +++ b/tests/unit/network_services/vnf_generic/test_vnfdgen.py @@ -193,6 +193,14 @@ class TestVnfdGen(unittest.TestCase): d = {'a': 1, 'b': 2} self.assertEqual(vnfdgen.deepgetitem(d, "a"), 1) + def test_dict_flatten_str_int_key_first(self): + d = {'0': 1, 0: 24, 'b': 2} + self.assertEqual(vnfdgen.deepgetitem(d, "0"), 1) + + def test_dict_flatten_int_key_fallback(self): + d = {0: 1, 'b': 2} + self.assertEqual(vnfdgen.deepgetitem(d, "0"), 1) + def test_dict_flatten_list(self): d = {'a': 1, 'b': list(range(2))} self.assertEqual(vnfdgen.deepgetitem(d, "b.0"), 0) @@ -201,6 +209,11 @@ class TestVnfdGen(unittest.TestCase): d = {'a': 1, 'b': {x: x for x in list(range(2))}} self.assertEqual(vnfdgen.deepgetitem(d, "b.0"), 0) + def test_dict_flatten_only_str_key(self): + d = {'0': 1, 0: 24, 'b': 2} + self.assertRaises(AttributeError, vnfdgen.deepgetitem, d, 0) + + def test_generate_tp_single_var(self): """ Function to verify traffic profile generation with imix """ -- cgit 1.2.3-korg