Merge pull request #41580 from garethgreenaway/develop_changes_from_41569

Update to mixins for Salt tests
This commit is contained in:
Nicole Thomas 2017-06-09 08:44:01 -06:00 committed by GitHub
commit b58a8ac2a1

View File

@ -514,9 +514,10 @@ class SaltReturnAssertsMixin(object):
def __getWithinSaltReturn(self, ret, keys): def __getWithinSaltReturn(self, ret, keys):
self.assertReturnNonEmptySaltType(ret) self.assertReturnNonEmptySaltType(ret)
keys = self.__return_valid_keys(keys) ret_data = []
okeys = keys[:]
for part in six.itervalues(ret): for part in six.itervalues(ret):
keys = self.__return_valid_keys(keys)
okeys = keys[:]
try: try:
ret_item = part[okeys.pop(0)] ret_item = part[okeys.pop(0)]
except (KeyError, TypeError): except (KeyError, TypeError):
@ -534,11 +535,13 @@ class SaltReturnAssertsMixin(object):
''.join(['[\'{0}\']'.format(k) for k in keys]), part ''.join(['[\'{0}\']'.format(k) for k in keys]), part
) )
) )
return ret_item ret_data.append(ret_item)
return ret_data
def assertSaltTrueReturn(self, ret): def assertSaltTrueReturn(self, ret):
try: try:
self.assertTrue(self.__getWithinSaltReturn(ret, 'result')) for saltret in self.__getWithinSaltReturn(ret, 'result'):
self.assertTrue(saltret)
except AssertionError: except AssertionError:
log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret))) log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret)))
try: try:
@ -556,7 +559,8 @@ class SaltReturnAssertsMixin(object):
def assertSaltFalseReturn(self, ret): def assertSaltFalseReturn(self, ret):
try: try:
self.assertFalse(self.__getWithinSaltReturn(ret, 'result')) for saltret in self.__getWithinSaltReturn(ret, 'result'):
self.assertFalse(saltret)
except AssertionError: except AssertionError:
log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret))) log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret)))
try: try:
@ -572,7 +576,8 @@ class SaltReturnAssertsMixin(object):
def assertSaltNoneReturn(self, ret): def assertSaltNoneReturn(self, ret):
try: try:
self.assertIsNone(self.__getWithinSaltReturn(ret, 'result')) for saltret in self.__getWithinSaltReturn(ret, 'result'):
self.assertIsNone(saltret)
except AssertionError: except AssertionError:
log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret))) log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret)))
try: try:
@ -587,54 +592,45 @@ class SaltReturnAssertsMixin(object):
) )
def assertInSaltComment(self, in_comment, ret): def assertInSaltComment(self, in_comment, ret):
return self.assertIn( for saltret in self.__getWithinSaltReturn(ret, 'comment'):
in_comment, self.__getWithinSaltReturn(ret, 'comment') self.assertIn(in_comment, saltret)
)
def assertNotInSaltComment(self, not_in_comment, ret): def assertNotInSaltComment(self, not_in_comment, ret):
return self.assertNotIn( for saltret in self.__getWithinSaltReturn(ret, 'comment'):
not_in_comment, self.__getWithinSaltReturn(ret, 'comment') self.assertNotIn(not_in_comment, saltret)
)
def assertSaltCommentRegexpMatches(self, ret, pattern): def assertSaltCommentRegexpMatches(self, ret, pattern):
return self.assertInSaltReturnRegexpMatches(ret, pattern, 'comment') return self.assertInSaltReturnRegexpMatches(ret, pattern, 'comment')
def assertInSaltStateWarning(self, in_comment, ret): def assertInSaltStateWarning(self, in_comment, ret):
return self.assertIn( for saltret in self.__getWithinSaltReturn(ret, 'warnings'):
in_comment, self.__getWithinSaltReturn(ret, 'warnings') self.assertIn(in_comment, saltret)
)
def assertNotInSaltStateWarning(self, not_in_comment, ret): def assertNotInSaltStateWarning(self, not_in_comment, ret):
return self.assertNotIn( for saltret in self.__getWithinSaltReturn(ret, 'warnings'):
not_in_comment, self.__getWithinSaltReturn(ret, 'warnings') self.assertNotIn(not_in_comment, saltret)
)
def assertInSaltReturn(self, item_to_check, ret, keys): def assertInSaltReturn(self, item_to_check, ret, keys):
return self.assertIn( for saltret in self.__getWithinSaltReturn(ret, keys):
item_to_check, self.__getWithinSaltReturn(ret, keys) self.assertIn(item_to_check, saltret)
)
def assertNotInSaltReturn(self, item_to_check, ret, keys): def assertNotInSaltReturn(self, item_to_check, ret, keys):
return self.assertNotIn( for saltret in self.__getWithinSaltReturn(ret, keys):
item_to_check, self.__getWithinSaltReturn(ret, keys) self.assertNotIn(item_to_check, saltret)
)
def assertInSaltReturnRegexpMatches(self, ret, pattern, keys=()): def assertInSaltReturnRegexpMatches(self, ret, pattern, keys=()):
return self.assertRegex( for saltret in self.__getWithinSaltReturn(ret, keys):
self.__getWithinSaltReturn(ret, keys), pattern self.assertRegex(saltret, pattern)
)
def assertSaltStateChangesEqual(self, ret, comparison, keys=()): def assertSaltStateChangesEqual(self, ret, comparison, keys=()):
keys = ['changes'] + self.__return_valid_keys(keys) keys = ['changes'] + self.__return_valid_keys(keys)
return self.assertEqual( for saltret in self.__getWithinSaltReturn(ret, keys):
self.__getWithinSaltReturn(ret, keys), comparison self.assertEqual(saltret, comparison)
)
def assertSaltStateChangesNotEqual(self, ret, comparison, keys=()): def assertSaltStateChangesNotEqual(self, ret, comparison, keys=()):
keys = ['changes'] + self.__return_valid_keys(keys) keys = ['changes'] + self.__return_valid_keys(keys)
return self.assertNotEqual( for saltret in self.__getWithinSaltReturn(ret, keys):
self.__getWithinSaltReturn(ret, keys), comparison self.assertNotEqual(saltret, comparison)
)
class SaltMinionEventAssertsMixin(object): class SaltMinionEventAssertsMixin(object):