2019-03-30 17:20:54 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from units.compat import unittest
|
2019-05-09 15:04:52 +02:00
|
|
|
from ansible.module_utils.hwc_utils import (HwcModuleException, navigate_value)
|
2019-03-30 17:20:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
class HwcUtilsTestCase(unittest.TestCase):
|
2019-05-09 15:04:52 +02:00
|
|
|
def test_navigate_value(self):
|
2019-03-30 17:20:54 +01:00
|
|
|
value = {
|
|
|
|
'foo': {
|
|
|
|
'quiet': {
|
2019-05-09 15:04:52 +02:00
|
|
|
'tree': 'test',
|
|
|
|
"trees": [0, 1]
|
2019-03-30 17:20:54 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 15:04:52 +02:00
|
|
|
self.assertEquals(navigate_value(value, ["foo", "quiet", "tree"]),
|
2019-03-30 17:20:54 +01:00
|
|
|
"test")
|
|
|
|
|
2019-05-09 15:04:52 +02:00
|
|
|
self.assertEquals(
|
|
|
|
navigate_value(value, ["foo", "quiet", "trees"],
|
|
|
|
{"foo.quiet.trees": 1}),
|
|
|
|
1)
|
2019-03-30 17:20:54 +01:00
|
|
|
|
2019-05-09 15:04:52 +02:00
|
|
|
self.assertRaisesRegexp(HwcModuleException,
|
|
|
|
r".* key\(q\) is not exist in dict",
|
|
|
|
navigate_value, value, ["foo", "q", "tree"])
|
2019-03-30 17:20:54 +01:00
|
|
|
|
2019-05-09 15:04:52 +02:00
|
|
|
self.assertRaisesRegexp(HwcModuleException,
|
|
|
|
r".* the index is out of list",
|
|
|
|
navigate_value, value,
|
|
|
|
["foo", "quiet", "trees"],
|
|
|
|
{"foo.quiet.trees": 2})
|