Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More GCP Utils Tests #53568

Merged
merged 3 commits into from Mar 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 73 additions & 4 deletions test/units/module_utils/gcp/test_gcp_utils.py
Expand Up @@ -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):
Expand Down