1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

More GCP Utils Tests (#53568)

* navigate_hash tests

* remove_nones_from_dict tests

* replace_resource_dict tests
This commit is contained in:
Alex Stephen 2019-03-27 01:23:58 -07:00 committed by John R Barker
parent 8aaed4c856
commit a191ed7b58

View file

@ -15,11 +15,80 @@
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
from units.compat import unittest
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):