mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-05 02:10:27 -07:00
parent
226ec3dd3f
commit
30c2bbd84e
2 changed files with 34 additions and 3 deletions
|
@ -362,7 +362,7 @@ class GcpRequest(object):
|
|||
def _compare_dicts(self, req_dict, resp_dict):
|
||||
difference = {}
|
||||
for key in req_dict:
|
||||
if resp_dict.get(key):
|
||||
if resp_dict.get(key) is not None:
|
||||
difference[key] = self._compare_value(req_dict.get(key), resp_dict.get(key))
|
||||
|
||||
# Remove all empty values from difference.
|
||||
|
@ -408,7 +408,7 @@ class GcpRequest(object):
|
|||
diff = None
|
||||
# If a None is found, a difference does not exist.
|
||||
# Only differing values matter.
|
||||
if not resp_value:
|
||||
if resp_value is None:
|
||||
return None
|
||||
|
||||
# Can assume non-None types at this point.
|
||||
|
@ -444,7 +444,7 @@ class GcpRequest(object):
|
|||
# Value1 False, resp_value 'false'
|
||||
if not req_value and to_text(resp_value) == 'false':
|
||||
return None
|
||||
return resp_value
|
||||
return True
|
||||
|
||||
# to_text may throw UnicodeErrors.
|
||||
# These errors shouldn't crash Ansible and should be hidden.
|
||||
|
|
|
@ -143,3 +143,34 @@ class GCPRequestDifferenceTestCase(unittest.TestCase):
|
|||
request2 = GcpRequest(value2)
|
||||
self.assertNotEquals(request1, request2)
|
||||
self.assertEqual(request1.difference(request2), difference)
|
||||
|
||||
def test_dicts_boolean_with_difference(self):
|
||||
value1 = {
|
||||
"foo": True,
|
||||
"bar": False,
|
||||
"baz": True,
|
||||
"qux": False,
|
||||
}
|
||||
|
||||
value2 = {
|
||||
"foo": True,
|
||||
"bar": False,
|
||||
"baz": False,
|
||||
"qux": True,
|
||||
}
|
||||
|
||||
value2 = {
|
||||
"foo": True,
|
||||
"bar": False,
|
||||
"baz": False,
|
||||
"qux": True,
|
||||
}
|
||||
|
||||
difference = {
|
||||
"baz": True,
|
||||
"qux": True,
|
||||
}
|
||||
request1 = GcpRequest(value1)
|
||||
request2 = GcpRequest(value2)
|
||||
self.assertNotEquals(request1, request2)
|
||||
self.assertEqual(request1.difference(request2), difference)
|
||||
|
|
Loading…
Add table
Reference in a new issue