mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Improve documentation and testing for conditions
This commit is contained in:
@@ -64,7 +64,11 @@ class Condition:
|
||||
"""
|
||||
Evaluate the provided data to determine whether it matches the condition.
|
||||
"""
|
||||
value = functools.reduce(dict.get, self.attr.split('.'), data)
|
||||
try:
|
||||
value = functools.reduce(dict.get, self.attr.split('.'), data)
|
||||
except TypeError:
|
||||
# Invalid key path
|
||||
value = None
|
||||
result = self.eval_func(value)
|
||||
|
||||
if self.negate:
|
||||
|
@@ -35,6 +35,16 @@ class ConditionTestCase(TestCase):
|
||||
# 'gt' supports only numeric values
|
||||
Condition('x', 'foo', 'gt')
|
||||
|
||||
#
|
||||
# Nested attrs tests
|
||||
#
|
||||
|
||||
def test_nested(self):
|
||||
c = Condition('x.y.z', 1)
|
||||
self.assertTrue(c.eval({'x': {'y': {'z': 1}}}))
|
||||
self.assertFalse(c.eval({'x': {'y': {'z': 2}}}))
|
||||
self.assertFalse(c.eval({'a': {'b': {'c': 1}}}))
|
||||
|
||||
#
|
||||
# Operator tests
|
||||
#
|
||||
|
Reference in New Issue
Block a user