Add repack_state_returns to TestCase

This allows for a state return dict to be repacked so that the top level
keys are the IDs, making it much easier to analyze and craft asserts
against the results.
This commit is contained in:
Erik Johnson 2018-09-28 21:23:51 -05:00 committed by Ch3LL
parent 982e693ef6
commit ceb3f4d91f
No known key found for this signature in database
GPG key ID: 132B55A7C13EFA73

View file

@ -268,6 +268,19 @@ class TestCase(_TestCase):
)
# return _TestCase.assertNotAlmostEquals(self, *args, **kwargs)
def repack_state_returns(self, state_ret):
'''
Accepts a state return dict and returns it back with the top level key
names rewritten such that the ID declaration is the key instead of the
State's unique tag. For example: 'foo' instead of
'file_|-foo_|-/etc/foo.conf|-managed'
This makes it easier to work with state returns when crafting asserts
after running states.
'''
assert isinstance(state_ret, dict), state_ret
return {x.split('_|-')[1]: y for x, y in six.iteritems(state_ret)}
def failUnlessEqual(self, *args, **kwargs):
raise DeprecationWarning(
'The {0}() function is deprecated. Please start using {1}() '