ansible/test/units/module_utils/hwc/test_hwc_utils.py
zengchen d8314e1a45 refactor moudule utils of hwc_utils.py (#55858)
* use navigate_value instead navigate_hash

* add async wait method

* update dict compare

* remove unuse methods

* not all modules have timeouts parameter

* navigate_value, the input data may be None
2019-05-09 09:04:51 -04:00

34 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
from units.compat import unittest
from ansible.module_utils.hwc_utils import (HwcModuleException, navigate_value)
class HwcUtilsTestCase(unittest.TestCase):
def test_navigate_value(self):
value = {
'foo': {
'quiet': {
'tree': 'test',
"trees": [0, 1]
},
}
}
self.assertEquals(navigate_value(value, ["foo", "quiet", "tree"]),
"test")
self.assertEquals(
navigate_value(value, ["foo", "quiet", "trees"],
{"foo.quiet.trees": 1}),
1)
self.assertRaisesRegexp(HwcModuleException,
r".* key\(q\) is not exist in dict",
navigate_value, value, ["foo", "q", "tree"])
self.assertRaisesRegexp(HwcModuleException,
r".* the index is out of list",
navigate_value, value,
["foo", "quiet", "trees"],
{"foo.quiet.trees": 2})