mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
More code reuse in SaltReturnAssertsMixIn
.
The methods `assertSaltTrueReturn`, `assertSaltFalseReturn` and `assertSaltNoneReturn` now reuse the code from `__getWithinSaltReturn` making `__assertReturn` obsolete and for that removed.
This commit is contained in:
parent
b9e72e7c3c
commit
952779aa26
@ -853,56 +853,20 @@ class SaltReturnAssertsMixIn(object):
|
|||||||
'{} is equal to {}. Salt returned an empty dictionary.'
|
'{} is equal to {}. Salt returned an empty dictionary.'
|
||||||
)
|
)
|
||||||
|
|
||||||
def __assertReturn(self, ret, which_case):
|
|
||||||
self.assertReturnNonEmptySaltType(ret)
|
|
||||||
|
|
||||||
for part in ret.itervalues():
|
|
||||||
self.assertReturnNonEmptySaltType(part)
|
|
||||||
try:
|
|
||||||
self.assertTrue(isinstance(part, dict))
|
|
||||||
except AssertionError:
|
|
||||||
raise AssertionError(
|
|
||||||
'{0} is not dict. Salt returned: {1}'.format(
|
|
||||||
type(part), part
|
|
||||||
)
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
if which_case is True:
|
|
||||||
self.assertTrue(part['result'])
|
|
||||||
elif which_case is False:
|
|
||||||
self.assertFalse(part['result'])
|
|
||||||
elif which_case is None:
|
|
||||||
self.assertIsNone(part['result'])
|
|
||||||
except AssertionError:
|
|
||||||
raise AssertionError(
|
|
||||||
'{result} is not {0}. Salt Comment:\n{comment}'.format(
|
|
||||||
which_case, **part
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def assertSaltTrueReturn(self, ret):
|
|
||||||
self.__assertReturn(ret, True)
|
|
||||||
|
|
||||||
def assertSaltFalseReturn(self, ret):
|
|
||||||
self.__assertReturn(ret, False)
|
|
||||||
|
|
||||||
def assertSaltNoneReturn(self, ret):
|
|
||||||
self.__assertReturn(ret, None)
|
|
||||||
|
|
||||||
def __return_valid_keys(self, keys):
|
def __return_valid_keys(self, keys):
|
||||||
if keys and isinstance(keys, tuple):
|
if isinstance(keys, tuple):
|
||||||
# If it's a tuple, turn it into a list
|
# If it's a tuple, turn it into a list
|
||||||
keys = list(keys)
|
keys = list(keys)
|
||||||
elif keys and isinstance(keys, basestring):
|
elif isinstance(keys, basestring):
|
||||||
# If it's a basestring , make it a one item list
|
# If it's a basestring , make it a one item list
|
||||||
keys = [keys]
|
keys = [keys]
|
||||||
elif keys and not isinstance(keys, list):
|
elif not isinstance(keys, list):
|
||||||
# If we've reached here, it's a bad type passed to keys
|
# If we've reached here, it's a bad type passed to keys
|
||||||
raise RuntimeError('The passed keys need to be a list')
|
raise RuntimeError('The passed keys need to be a list')
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
def __getWithinSaltReturn(self, ret, keys):
|
def __getWithinSaltReturn(self, ret, keys):
|
||||||
self.assertReturnSaltType(ret)
|
self.assertReturnNonEmptySaltType(ret)
|
||||||
keys = self.__return_valid_keys(keys)
|
keys = self.__return_valid_keys(keys)
|
||||||
okeys = keys[:]
|
okeys = keys[:]
|
||||||
for part in ret.itervalues():
|
for part in ret.itervalues():
|
||||||
@ -925,6 +889,36 @@ class SaltReturnAssertsMixIn(object):
|
|||||||
)
|
)
|
||||||
return ret_item
|
return ret_item
|
||||||
|
|
||||||
|
def assertSaltTrueReturn(self, ret):
|
||||||
|
try:
|
||||||
|
self.assertTrue(self.__getWithinSaltReturn(ret, 'result'))
|
||||||
|
except AssertionError:
|
||||||
|
raise AssertionError(
|
||||||
|
'{result} is not True. Salt Comment:\n{comment}'.format(
|
||||||
|
**(ret.values()[0])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def assertSaltFalseReturn(self, ret):
|
||||||
|
try:
|
||||||
|
self.assertFalse(self.__getWithinSaltReturn(ret, 'result'))
|
||||||
|
except AssertionError:
|
||||||
|
raise AssertionError(
|
||||||
|
'{result} is not False. Salt Comment:\n{comment}'.format(
|
||||||
|
**(ret.values()[0])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def assertSaltNoneReturn(self, ret):
|
||||||
|
try:
|
||||||
|
self.assertIsNone(self.__getWithinSaltReturn(ret, 'result'))
|
||||||
|
except AssertionError:
|
||||||
|
raise AssertionError(
|
||||||
|
'{result} is not None. Salt Comment:\n{comment}'.format(
|
||||||
|
**(ret.values()[0])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def assertInSaltComment(self, ret, in_comment):
|
def assertInSaltComment(self, ret, in_comment):
|
||||||
return self.assertIn(
|
return self.assertIn(
|
||||||
in_comment, self.__getWithinSaltReturn(ret, 'comment')
|
in_comment, self.__getWithinSaltReturn(ret, 'comment')
|
||||||
|
Loading…
Reference in New Issue
Block a user