mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 04:40:22 -07:00
cloud: huawei: Add new module hwc_network_vpc (#54102)
This commit is contained in:
parent
51f41a2298
commit
5599b0484f
9 changed files with 1314 additions and 0 deletions
109
test/units/module_utils/hwc/test_hwc_utils.py
Normal file
109
test/units/module_utils/hwc/test_hwc_utils.py
Normal file
|
@ -0,0 +1,109 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from units.compat import unittest
|
||||
from ansible.module_utils.hwc_utils import (navigate_hash,
|
||||
remove_empty_from_dict,
|
||||
remove_nones_from_dict,
|
||||
replace_resource_dict)
|
||||
|
||||
|
||||
class HwcUtilsTestCase(unittest.TestCase):
|
||||
def test_navigate_hash(self):
|
||||
value = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test'
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
self.assertEquals(navigate_hash(value, ["foo", "quiet", "tree"]),
|
||||
"test")
|
||||
|
||||
self.assertEquals(navigate_hash(value, ["foo", "q", "tree"], 123),
|
||||
123)
|
||||
|
||||
self.assertIsNone(navigate_hash(value, [], 123))
|
||||
|
||||
def test_remove_empty_from_dict(self):
|
||||
value = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test',
|
||||
'tree1': [
|
||||
None,
|
||||
{},
|
||||
[],
|
||||
'test'
|
||||
],
|
||||
'tree2': {},
|
||||
'tree3': []
|
||||
},
|
||||
},
|
||||
'foo1': [],
|
||||
'foo2': {},
|
||||
'foo3': None,
|
||||
}
|
||||
|
||||
expect = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test',
|
||||
'tree1': [
|
||||
'test'
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
self.assertEqual(remove_empty_from_dict(value), expect)
|
||||
|
||||
def test_remove_nones_from_dict(self):
|
||||
value = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test',
|
||||
'tree1': [
|
||||
None,
|
||||
{},
|
||||
[],
|
||||
'test'
|
||||
],
|
||||
'tree2': {},
|
||||
'tree3': []
|
||||
},
|
||||
},
|
||||
'foo1': [],
|
||||
'foo2': {},
|
||||
'foo3': None,
|
||||
}
|
||||
|
||||
expect = {
|
||||
'foo': {
|
||||
'quiet': {
|
||||
'tree': 'test',
|
||||
'tree1': [
|
||||
{},
|
||||
[],
|
||||
'test'
|
||||
],
|
||||
'tree2': {},
|
||||
'tree3': []
|
||||
},
|
||||
},
|
||||
'foo1': [],
|
||||
'foo2': {},
|
||||
}
|
||||
|
||||
self.assertEqual(remove_nones_from_dict(value), expect)
|
||||
|
||||
def test_replace_resource_dict(self):
|
||||
self.assertEqual(replace_resource_dict({'foo': 'quiet'}, 'foo'), 'quiet')
|
||||
|
||||
self.assertEqual(replace_resource_dict({}, 'foo'), {})
|
||||
|
||||
self.assertEqual(replace_resource_dict([[{'foo': 'quiet'}]], 'foo'),
|
||||
[['quiet']])
|
Loading…
Add table
Add a link
Reference in a new issue