Extend unittest coverage

This commit is contained in:
Markus Opolka 2020-03-15 10:26:46 +01:00
parent 1a9e1e9048
commit 2c98e840e8
2 changed files with 18 additions and 1 deletions

View File

@ -169,7 +169,7 @@ class JsonHelper:
if key.find(self.arrayOpener) != -1: if key.find(self.arrayOpener) != -1:
return self.getSubArrayElement(key, data) return self.getSubArrayElement(key, data)
else: else:
if key in data: if type(data) == dict and key in data:
return data[key] return data[key]
else: else:
return (None, 'not_found') return (None, 'not_found')

View File

@ -255,3 +255,20 @@ class UtilTest(unittest.TestCase):
# This should not throw a KeyError # This should not throw a KeyError
data = '{}' data = '{}'
self.check_data(rules.dash_q(['(0).Node,foobar', '(1).Node,missing']), data, WARNING_CODE) self.check_data(rules.dash_q(['(0).Node,foobar', '(1).Node,missing']), data, WARNING_CODE)
def test_subelem(self):
rules = RulesHelper()
data = '{"foo": {"foo": {"foo": "bar"}}}'
self.check_data(rules.dash_E(['foo.foo.foo.foo.foo']), data, CRITICAL_CODE)
def test_subarrayelem_missing_elem(self):
rules = RulesHelper()
data = '[{"capacity": {"value": 1000}},{"capacity": {"value": 2200}}]'
self.check_data(rules.dash_E(['(*).capacity.value']), data, OK_CODE)
self.check_data(rules.dash_E(['(*).capacity.value.too_deep']), data, CRITICAL_CODE)
# Should not throw keyerror
self.check_data(rules.dash_E(['foo']), data, CRITICAL_CODE)