|
|
@ -15,11 +15,80 @@
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import os
|
|
|
|
from units.compat import unittest
|
|
|
|
import sys
|
|
|
|
from ansible.module_utils.gcp_utils import (GcpRequest,
|
|
|
|
|
|
|
|
navigate_hash,
|
|
|
|
|
|
|
|
remove_nones_from_dict,
|
|
|
|
|
|
|
|
replace_resource_dict)
|
|
|
|
|
|
|
|
|
|
|
|
from units.compat import mock, unittest
|
|
|
|
|
|
|
|
from ansible.module_utils.gcp_utils import GcpRequest
|
|
|
|
class ReplaceResourceDictTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_given_dict(self):
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
'selfLink': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertEquals(replace_resource_dict(value, 'selfLink'), value['selfLink'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_given_array(self):
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
'selfLink': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertEquals(replace_resource_dict([value] * 3, 'selfLink'), [value['selfLink']] * 3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NavigateHashTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_one_level(self):
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
'key': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertEquals(navigate_hash(value, ['key']), value['key'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_multilevel(self):
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
'key': {
|
|
|
|
|
|
|
|
'key2': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertEquals(navigate_hash(value, ['key', 'key2']), value['key']['key2'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_default(self):
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
'key': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
default = 'not found'
|
|
|
|
|
|
|
|
self.assertEquals(navigate_hash(value, ['key', 'key2'], default), default)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RemoveNonesFromDictTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_remove_nones(self):
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
'key': None,
|
|
|
|
|
|
|
|
'good': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
value_correct = {
|
|
|
|
|
|
|
|
'good': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertEquals(remove_nones_from_dict(value), value_correct)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_remove_empty_arrays(self):
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
'key': [],
|
|
|
|
|
|
|
|
'good': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
value_correct = {
|
|
|
|
|
|
|
|
'good': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertEquals(remove_nones_from_dict(value), value_correct)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_remove_empty_dicts(self):
|
|
|
|
|
|
|
|
value = {
|
|
|
|
|
|
|
|
'key': {},
|
|
|
|
|
|
|
|
'good': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
value_correct = {
|
|
|
|
|
|
|
|
'good': 'value'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertEquals(remove_nones_from_dict(value), value_correct)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GCPRequestDifferenceTestCase(unittest.TestCase):
|
|
|
|
class GCPRequestDifferenceTestCase(unittest.TestCase):
|
|
|
|