mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Migrated test.integration.states.pip
to use SaltReturnAssertsMixIn
.
* Added `assertSaltCommentRegexpMatches()` to `SaltReturnAssertsMixIn` to add the ability to match salt comments using regular expressions.
This commit is contained in:
parent
156ce07bde
commit
fc3b272809
@ -939,6 +939,16 @@ class SaltReturnAssertsMixIn(object):
|
||||
)
|
||||
return True
|
||||
|
||||
def assertSaltCommentRegexpMatches(self, ret, pattern):
|
||||
self.assertReturnSaltType(ret)
|
||||
for part in ret.itervalues():
|
||||
if 'comment' in part:
|
||||
return self.assertRegexpMatches(part['comment'], pattern)
|
||||
else:
|
||||
raise AssertionError(
|
||||
'There\'s no comment key in any of salt\'s return parts'
|
||||
)
|
||||
|
||||
def __assertSaltStateChanges(self, ret, keys=()):
|
||||
self.assertSaltTrueReturn(ret)
|
||||
if keys and isinstance(keys, tuple):
|
||||
|
@ -12,7 +12,7 @@ import shutil
|
||||
import integration
|
||||
|
||||
|
||||
class PipStateTest(integration.ModuleCase):
|
||||
class PipStateTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
||||
|
||||
def setUp(self):
|
||||
super(PipStateTest, self).setUp()
|
||||
@ -28,16 +28,12 @@ class PipStateTest(integration.ModuleCase):
|
||||
# Since we don't have the virtualenv created, pip.installed will
|
||||
# thrown and error.
|
||||
ret = self.run_function('state.sls', mods='pip-installed-errors')
|
||||
self.assertTrue(isinstance(ret, dict))
|
||||
self.assertNotEqual(ret, {})
|
||||
|
||||
for key in ret.keys():
|
||||
self.assertFalse(ret[key]['result'])
|
||||
self.assertRegexpMatches(
|
||||
ret[key]['comment'],
|
||||
'Error installing \'supervisor\': .* '
|
||||
'[nN]o such file or directory'
|
||||
)
|
||||
self.assertSaltFalseReturn(ret)
|
||||
self.assertSaltCommentRegexpMatches(
|
||||
ret,
|
||||
'Error installing \'supervisor\': .* '
|
||||
'[nN]o such file or directory'
|
||||
)
|
||||
|
||||
# We now create the missing virtualenv
|
||||
ret = self.run_function('virtualenv.create', [venv_dir])
|
||||
@ -45,11 +41,7 @@ class PipStateTest(integration.ModuleCase):
|
||||
|
||||
# The state should not have any issues running now
|
||||
ret = self.run_function('state.sls', mods='pip-installed-errors')
|
||||
self.assertTrue(isinstance(ret, dict))
|
||||
self.assertNotEqual(ret, {})
|
||||
|
||||
for key in ret.keys():
|
||||
self.assertTrue(ret[key]['result'])
|
||||
self.assertSaltTrueReturn(ret)
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
@ -82,9 +74,10 @@ class PipStateTest(integration.ModuleCase):
|
||||
ret = self.run_function(
|
||||
'state.sls', mods='pip-installed-weird-install'
|
||||
)
|
||||
self.assertTrue(isinstance(ret, dict))
|
||||
self.assertNotEqual(ret, {})
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
# We cannot use assertInSaltComment here because we need to skip
|
||||
# some of the state return parts
|
||||
for key in ret.keys():
|
||||
self.assertTrue(ret[key]['result'])
|
||||
if ret[key]['comment'] == 'Created new virtualenv':
|
||||
@ -108,12 +101,7 @@ class PipStateTest(integration.ModuleCase):
|
||||
)
|
||||
|
||||
try:
|
||||
self.assertTrue(isinstance(ret, dict)), ret
|
||||
self.assertNotEqual(ret, {})
|
||||
|
||||
for key in ret.iterkeys():
|
||||
self.assertTrue(ret[key]['result'])
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
self.assertTrue(
|
||||
os.path.isfile(os.path.join(venv_dir, 'bin', 'supervisord'))
|
||||
)
|
||||
@ -127,11 +115,9 @@ class PipStateTest(integration.ModuleCase):
|
||||
)
|
||||
|
||||
try:
|
||||
# XXX: Once state.template_str is fixed, consider not using a file
|
||||
# for this test.
|
||||
|
||||
# Let's create the testing virtualenv
|
||||
self.run_function('virtualenv.create', [venv_dir])
|
||||
ret = self.run_function('virtualenv.create', [venv_dir])
|
||||
self.assertEqual(ret['retcode'], 0)
|
||||
|
||||
# Let's remove the pip binary
|
||||
pip_bin = os.path.join(venv_dir, 'bin', 'pip')
|
||||
@ -143,9 +129,9 @@ class PipStateTest(integration.ModuleCase):
|
||||
|
||||
# Let's run the state which should fail because pip is missing
|
||||
ret = self.run_function('state.sls', mods='issue-2087-missing-pip')
|
||||
self.assertFalse(ret.values()[0]['result'])
|
||||
self.assertEqual(
|
||||
ret.values()[0]['comment'],
|
||||
self.assertSaltFalseReturn(ret)
|
||||
self.assertInSaltComment(
|
||||
ret,
|
||||
'Error installing \'pep8\': Could not find a `pip` binary'
|
||||
)
|
||||
finally:
|
||||
|
Loading…
Reference in New Issue
Block a user