mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Fix archive tests
This fixes references to the badly-named legacy zip and unzip functions, as well as skipping the unrar test when neither unrar and rar are installed.
This commit is contained in:
parent
62b7e12415
commit
904f9b6c90
@ -16,6 +16,7 @@ ensure_in_syspath('../../')
|
|||||||
# Import salt libs
|
# Import salt libs
|
||||||
from salt.modules import archive
|
from salt.modules import archive
|
||||||
from salt.exceptions import CommandNotFoundError
|
from salt.exceptions import CommandNotFoundError
|
||||||
|
from salt.utils import which_bin
|
||||||
|
|
||||||
|
|
||||||
class ZipFileMock(MagicMock):
|
class ZipFileMock(MagicMock):
|
||||||
@ -129,28 +130,28 @@ class ArchiveTestCase(TestCase):
|
|||||||
def test_cmd_zip(self):
|
def test_cmd_zip(self):
|
||||||
mock = MagicMock(return_value='salt')
|
mock = MagicMock(return_value='salt')
|
||||||
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
||||||
ret = archive.cmd_zip_(
|
ret = archive.cmd_zip(
|
||||||
'/tmp/salt.{{grains.id}}.zip',
|
'/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
||||||
template='jinja'
|
template='jinja'
|
||||||
)
|
)
|
||||||
self.assertEqual(['salt'], ret)
|
self.assertEqual(['salt'], ret)
|
||||||
mock.assert_called_once_with(
|
mock.assert_called_once_with(
|
||||||
['zip', '/tmp/salt.{{grains.id}}.zip',
|
['zip', '-r', '/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
'/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
runas=None, python_shell=False, template='jinja', cwd=None
|
runas=None, python_shell=False, template='jinja', cwd=None
|
||||||
)
|
)
|
||||||
|
|
||||||
mock = MagicMock(return_value='salt')
|
mock = MagicMock(return_value='salt')
|
||||||
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
||||||
ret = archive.cmd_zip_(
|
ret = archive.cmd_zip(
|
||||||
'/tmp/salt.{{grains.id}}.zip',
|
'/tmp/salt.{{grains.id}}.zip',
|
||||||
['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
template='jinja'
|
template='jinja'
|
||||||
)
|
)
|
||||||
self.assertEqual(['salt'], ret)
|
self.assertEqual(['salt'], ret)
|
||||||
mock.assert_called_once_with(
|
mock.assert_called_once_with(
|
||||||
['zip', '/tmp/salt.{{grains.id}}.zip',
|
['zip', '-r', '/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
'/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
runas=None, python_shell=False, template='jinja', cwd=None
|
runas=None, python_shell=False, template='jinja', cwd=None
|
||||||
)
|
)
|
||||||
@ -164,7 +165,7 @@ class ArchiveTestCase(TestCase):
|
|||||||
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
||||||
template='jinja'
|
template='jinja'
|
||||||
)
|
)
|
||||||
self.assertEqual(['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'], ret)
|
self.assertEqual(['tmp/tmpePe8yO', 'tmp/tmpLeSw1A'], ret)
|
||||||
|
|
||||||
@patch('salt.utils.which', lambda exe: None)
|
@patch('salt.utils.which', lambda exe: None)
|
||||||
def test_zip_raises_exception_if_not_found(self):
|
def test_zip_raises_exception_if_not_found(self):
|
||||||
@ -172,7 +173,7 @@ class ArchiveTestCase(TestCase):
|
|||||||
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
CommandNotFoundError,
|
CommandNotFoundError,
|
||||||
archive.cmd_zip_,
|
archive.cmd_zip,
|
||||||
'/tmp/salt.{{grains.id}}.zip',
|
'/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
||||||
template='jinja',
|
template='jinja',
|
||||||
@ -183,22 +184,22 @@ class ArchiveTestCase(TestCase):
|
|||||||
def test_cmd_unzip(self):
|
def test_cmd_unzip(self):
|
||||||
mock = MagicMock(return_value='salt')
|
mock = MagicMock(return_value='salt')
|
||||||
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
||||||
ret = archive.cmd_unzip_(
|
ret = archive.cmd_unzip(
|
||||||
'/tmp/salt.{{grains.id}}.zip',
|
'/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/dest',
|
'/tmp/dest',
|
||||||
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
||||||
runas=None, template='jinja'
|
template='jinja'
|
||||||
)
|
)
|
||||||
self.assertEqual(['salt'], ret)
|
self.assertEqual(['salt'], ret)
|
||||||
mock.assert_called_once_with(
|
mock.assert_called_once_with(
|
||||||
['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
|
['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
|
||||||
'-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
'-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
python_shell=False, template='jinja'
|
runas=None, python_shell=False, template='jinja'
|
||||||
)
|
)
|
||||||
|
|
||||||
mock = MagicMock(return_value='salt')
|
mock = MagicMock(return_value='salt')
|
||||||
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
||||||
ret = archive.cmd_unzip_(
|
ret = archive.cmd_unzip(
|
||||||
'/tmp/salt.{{grains.id}}.zip',
|
'/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/dest',
|
'/tmp/dest',
|
||||||
excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
@ -208,12 +209,12 @@ class ArchiveTestCase(TestCase):
|
|||||||
mock.assert_called_once_with(
|
mock.assert_called_once_with(
|
||||||
['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
|
['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
|
||||||
'-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
'-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
python_shell=False, template='jinja'
|
runas=None, python_shell=False, template='jinja'
|
||||||
)
|
)
|
||||||
|
|
||||||
mock = MagicMock(return_value='salt')
|
mock = MagicMock(return_value='salt')
|
||||||
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
||||||
ret = archive.cmd_unzip_(
|
ret = archive.cmd_unzip(
|
||||||
'/tmp/salt.{{grains.id}}.zip',
|
'/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/dest',
|
'/tmp/dest',
|
||||||
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
||||||
@ -224,12 +225,12 @@ class ArchiveTestCase(TestCase):
|
|||||||
mock.assert_called_once_with(
|
mock.assert_called_once_with(
|
||||||
['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
|
['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
|
||||||
'/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
'/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
python_shell=False, template='jinja'
|
runas=None, python_shell=False, template='jinja'
|
||||||
)
|
)
|
||||||
|
|
||||||
mock = MagicMock(return_value='salt')
|
mock = MagicMock(return_value='salt')
|
||||||
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
||||||
ret = archive.cmd_unzip_(
|
ret = archive.cmd_unzip(
|
||||||
'/tmp/salt.{{grains.id}}.zip',
|
'/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/dest',
|
'/tmp/dest',
|
||||||
excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
@ -240,7 +241,7 @@ class ArchiveTestCase(TestCase):
|
|||||||
mock.assert_called_once_with(
|
mock.assert_called_once_with(
|
||||||
['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
|
['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
|
||||||
'/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
'/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
||||||
python_shell=False, template='jinja'
|
runas=None, python_shell=False, template='jinja'
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_unzip(self):
|
def test_unzip(self):
|
||||||
@ -260,7 +261,7 @@ class ArchiveTestCase(TestCase):
|
|||||||
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
CommandNotFoundError,
|
CommandNotFoundError,
|
||||||
archive.cmd_unzip_,
|
archive.cmd_unzip,
|
||||||
'/tmp/salt.{{grains.id}}.zip',
|
'/tmp/salt.{{grains.id}}.zip',
|
||||||
'/tmp/dest',
|
'/tmp/dest',
|
||||||
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
||||||
@ -308,6 +309,7 @@ class ArchiveTestCase(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertFalse(mock.called)
|
self.assertFalse(mock.called)
|
||||||
|
|
||||||
|
@skipIf(which_bin(('unrar', 'rar')) is None, 'unrar not installed')
|
||||||
@patch('salt.utils.which', lambda exe: exe)
|
@patch('salt.utils.which', lambda exe: exe)
|
||||||
@patch('salt.utils.which_bin', lambda exe: exe)
|
@patch('salt.utils.which_bin', lambda exe: exe)
|
||||||
def test_unrar(self):
|
def test_unrar(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user