From fd4c5031c7afa66eb02411a180d36dbc6ee7102b Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 17 Apr 2019 11:19:59 -0400 Subject: [PATCH] Add test for dict_to_filter_params --- netbox/utilities/tests/test_utils.py | 39 ++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/netbox/utilities/tests/test_utils.py b/netbox/utilities/tests/test_utils.py index 4e0fec1ba..5d9a98ad5 100644 --- a/netbox/utilities/tests/test_utils.py +++ b/netbox/utilities/tests/test_utils.py @@ -1,13 +1,48 @@ from django.test import TestCase -from utilities.utils import deepmerge +from utilities.utils import deepmerge, dict_to_filter_params + + +class DictToFilterParamsTest(TestCase): + """ + Validate the operation of dict_to_filter_params(). + """ + def setUp(self): + return + + def test_dict_to_filter_params(self): + + input = { + 'a': True, + 'foo': { + 'bar': 123, + 'baz': 456, + }, + 'x': { + 'y': { + 'z': False + } + } + } + + output = { + 'a': True, + 'foo__bar': 123, + 'foo__baz': 456, + 'x__y__z': False, + } + + self.assertEqual(dict_to_filter_params(input), output) + + input['x']['y']['z'] = True + + self.assertNotEqual(dict_to_filter_params(input), output) class DeepMergeTest(TestCase): """ Validate the behavior of the deepmerge() utility. """ - def setUp(self): return