2013-07-27 18:24:49 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
2013-09-16 16:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
tests.unit.modules.archive_test
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2013-07-27 18:24:49 +00:00
|
|
|
'''
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2013-07-27 18:24:49 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting import skipIf, TestCase
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
2015-03-23 21:43:45 +00:00
|
|
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
2013-07-27 18:24:49 +00:00
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
|
|
|
# Import salt libs
|
|
|
|
from salt.modules import archive
|
2013-07-29 22:29:58 +00:00
|
|
|
from salt.exceptions import CommandNotFoundError
|
2015-01-14 03:07:23 +00:00
|
|
|
from salt.utils import which_bin
|
2013-07-27 18:24:49 +00:00
|
|
|
|
|
|
|
|
2014-12-11 21:46:36 +00:00
|
|
|
class ZipFileMock(MagicMock):
|
2014-12-11 23:58:10 +00:00
|
|
|
def __init__(self, files=None, **kwargs): # pylint: disable=W0231
|
|
|
|
if files is None:
|
|
|
|
files = ['salt']
|
2014-12-11 21:46:36 +00:00
|
|
|
MagicMock.__init__(self, **kwargs)
|
|
|
|
self._files = files
|
|
|
|
|
|
|
|
def namelist(self):
|
|
|
|
return self._files
|
|
|
|
|
|
|
|
# Globals
|
|
|
|
archive.__salt__ = {}
|
|
|
|
archive.__pillar__ = {}
|
|
|
|
archive.__grains__ = {"id": "0"}
|
|
|
|
archive.__opts__ = {}
|
2013-07-27 18:24:49 +00:00
|
|
|
|
2014-12-11 23:58:10 +00:00
|
|
|
|
2013-08-26 09:45:22 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2013-07-27 18:24:49 +00:00
|
|
|
class ArchiveTestCase(TestCase):
|
2013-07-29 22:29:58 +00:00
|
|
|
|
|
|
|
@patch('salt.utils.which', lambda exe: exe)
|
2013-07-27 18:24:49 +00:00
|
|
|
def test_tar(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
2013-07-28 21:55:27 +00:00
|
|
|
ret = archive.tar(
|
2015-03-27 04:12:26 +00:00
|
|
|
'-zcvf', 'foo.tar',
|
2013-07-29 05:57:27 +00:00
|
|
|
['/tmp/something-to-compress-1',
|
|
|
|
'/tmp/something-to-compress-2'],
|
2014-12-09 15:36:30 +00:00
|
|
|
template=None
|
2013-07-29 05:57:27 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['tar', '-zcvf', 'foo.tar', '/tmp/something-to-compress-1',
|
|
|
|
'/tmp/something-to-compress-2'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template=None, cwd=None
|
2013-07-29 05:57:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
ret = archive.tar(
|
2015-03-27 04:12:26 +00:00
|
|
|
'-zcvf', 'foo.tar',
|
2013-07-29 05:57:27 +00:00
|
|
|
'/tmp/something-to-compress-1,/tmp/something-to-compress-2',
|
2014-12-09 15:36:30 +00:00
|
|
|
template=None
|
2013-07-28 21:55:27 +00:00
|
|
|
)
|
2013-07-27 18:24:49 +00:00
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['tar', '-zcvf', 'foo.tar', '/tmp/something-to-compress-1',
|
|
|
|
'/tmp/something-to-compress-2'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template=None, cwd=None
|
2013-07-27 18:24:49 +00:00
|
|
|
)
|
|
|
|
|
2013-07-29 22:29:58 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: None)
|
|
|
|
def test_tar_raises_exception_if_not_found(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandNotFoundError,
|
|
|
|
archive.tar,
|
|
|
|
'zxvf',
|
|
|
|
'foo.tar',
|
|
|
|
'/tmp/something-to-compress'
|
|
|
|
)
|
|
|
|
self.assertFalse(mock.called)
|
|
|
|
|
|
|
|
@patch('salt.utils.which', lambda exe: exe)
|
2013-07-28 11:50:05 +00:00
|
|
|
def test_gzip(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
ret = archive.gzip('/tmp/something-to-compress')
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['gzip', '/tmp/something-to-compress'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template=None
|
2013-07-28 11:50:05 +00:00
|
|
|
)
|
|
|
|
|
2013-07-29 22:29:58 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: None)
|
|
|
|
def test_gzip_raises_exception_if_not_found(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandNotFoundError,
|
|
|
|
archive.gzip, '/tmp/something-to-compress'
|
|
|
|
)
|
|
|
|
self.assertFalse(mock.called)
|
|
|
|
|
|
|
|
@patch('salt.utils.which', lambda exe: exe)
|
2013-07-28 11:51:13 +00:00
|
|
|
def test_gunzip(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
ret = archive.gunzip('/tmp/something-to-decompress.tar.gz')
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['gunzip', '/tmp/something-to-decompress.tar.gz'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template=None
|
2013-07-28 11:51:13 +00:00
|
|
|
)
|
|
|
|
|
2013-07-29 22:29:58 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: None)
|
|
|
|
def test_gunzip_raises_exception_if_not_found(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandNotFoundError,
|
|
|
|
archive.gunzip,
|
|
|
|
'/tmp/something-to-decompress.tar.gz'
|
|
|
|
)
|
|
|
|
self.assertFalse(mock.called)
|
|
|
|
|
2013-07-30 03:22:02 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: exe)
|
2014-12-11 21:46:36 +00:00
|
|
|
def test_cmd_zip(self):
|
2013-07-30 03:22:02 +00:00
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
2015-01-14 03:07:23 +00:00
|
|
|
ret = archive.cmd_zip(
|
2013-07-30 03:22:02 +00:00
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
|
|
|
template='jinja'
|
|
|
|
)
|
2013-07-30 04:01:39 +00:00
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-14 03:07:23 +00:00
|
|
|
['zip', '-r', '/tmp/salt.{{grains.id}}.zip',
|
2015-01-08 19:50:15 +00:00
|
|
|
'/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template='jinja', cwd=None
|
2013-07-30 04:01:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
2015-01-14 03:07:23 +00:00
|
|
|
ret = archive.cmd_zip(
|
2013-07-30 04:01:39 +00:00
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
2015-01-09 18:39:09 +00:00
|
|
|
template='jinja'
|
2013-07-30 04:01:39 +00:00
|
|
|
)
|
2013-07-30 03:22:02 +00:00
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-14 03:07:23 +00:00
|
|
|
['zip', '-r', '/tmp/salt.{{grains.id}}.zip',
|
2015-01-08 19:50:15 +00:00
|
|
|
'/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template='jinja', cwd=None
|
2013-07-30 03:22:02 +00:00
|
|
|
)
|
|
|
|
|
2014-12-11 21:46:36 +00:00
|
|
|
@patch('os.path.exists', MagicMock(return_value=True))
|
|
|
|
@patch('os.path.isdir', MagicMock(return_value=False))
|
|
|
|
@patch('zipfile.ZipFile', MagicMock())
|
|
|
|
def test_zip(self):
|
2014-12-11 23:58:10 +00:00
|
|
|
ret = archive.zip_(
|
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
|
|
|
template='jinja'
|
|
|
|
)
|
2015-01-14 03:07:23 +00:00
|
|
|
self.assertEqual(['tmp/tmpePe8yO', 'tmp/tmpLeSw1A'], ret)
|
2014-12-11 21:46:36 +00:00
|
|
|
|
2013-07-30 03:22:02 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: None)
|
|
|
|
def test_zip_raises_exception_if_not_found(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandNotFoundError,
|
2015-01-14 03:07:23 +00:00
|
|
|
archive.cmd_zip,
|
2013-07-30 03:22:02 +00:00
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
|
|
|
template='jinja',
|
|
|
|
)
|
|
|
|
self.assertFalse(mock.called)
|
|
|
|
|
2013-07-30 03:52:31 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: exe)
|
2014-12-11 21:46:36 +00:00
|
|
|
def test_cmd_unzip(self):
|
2013-07-30 03:52:31 +00:00
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
2015-01-14 03:07:23 +00:00
|
|
|
ret = archive.cmd_unzip(
|
2013-07-30 03:52:31 +00:00
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/dest',
|
|
|
|
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
2015-01-14 03:07:23 +00:00
|
|
|
template='jinja'
|
2013-07-30 03:52:31 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
|
|
|
|
'-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
2015-01-14 03:07:23 +00:00
|
|
|
runas=None, python_shell=False, template='jinja'
|
2013-07-30 03:52:31 +00:00
|
|
|
)
|
|
|
|
|
2013-07-30 04:00:58 +00:00
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
2015-01-14 03:07:23 +00:00
|
|
|
ret = archive.cmd_unzip(
|
2013-07-30 04:00:58 +00:00
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/dest',
|
|
|
|
excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
|
|
|
template='jinja'
|
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
|
|
|
|
'-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
2015-01-14 03:07:23 +00:00
|
|
|
runas=None, python_shell=False, template='jinja'
|
2013-07-30 04:00:58 +00:00
|
|
|
)
|
|
|
|
|
2014-01-28 08:41:45 +00:00
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
2015-01-14 03:07:23 +00:00
|
|
|
ret = archive.cmd_unzip(
|
2014-01-28 08:41:45 +00:00
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/dest',
|
|
|
|
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
|
|
|
template='jinja',
|
2015-03-27 04:12:26 +00:00
|
|
|
options='-fo'
|
2014-01-28 08:41:45 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
|
|
|
|
'/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
2015-01-14 03:07:23 +00:00
|
|
|
runas=None, python_shell=False, template='jinja'
|
2014-01-28 08:41:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
2015-01-14 03:07:23 +00:00
|
|
|
ret = archive.cmd_unzip(
|
2014-01-28 08:41:45 +00:00
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/dest',
|
|
|
|
excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
|
|
|
template='jinja',
|
2015-03-27 04:12:26 +00:00
|
|
|
options='-fo'
|
2014-01-28 08:41:45 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
|
|
|
|
'/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
|
2015-01-14 03:07:23 +00:00
|
|
|
runas=None, python_shell=False, template='jinja'
|
2014-01-28 08:41:45 +00:00
|
|
|
)
|
|
|
|
|
2014-12-11 21:46:36 +00:00
|
|
|
def test_unzip(self):
|
|
|
|
mock = ZipFileMock()
|
|
|
|
with patch('zipfile.ZipFile', mock):
|
|
|
|
ret = archive.unzip(
|
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/dest',
|
|
|
|
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
|
|
|
template='jinja'
|
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
|
2013-07-30 03:52:31 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: None)
|
|
|
|
def test_unzip_raises_exception_if_not_found(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandNotFoundError,
|
2015-01-14 03:07:23 +00:00
|
|
|
archive.cmd_unzip,
|
2013-07-30 03:52:31 +00:00
|
|
|
'/tmp/salt.{{grains.id}}.zip',
|
|
|
|
'/tmp/dest',
|
|
|
|
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
|
|
|
|
template='jinja',
|
|
|
|
)
|
|
|
|
self.assertFalse(mock.called)
|
|
|
|
|
2013-07-30 03:59:28 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: exe)
|
|
|
|
def test_rar(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
ret = archive.rar(
|
|
|
|
'/tmp/rarfile.rar',
|
|
|
|
'/tmp/sourcefile1,/tmp/sourcefile2'
|
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['rar', 'a', '-idp', '/tmp/rarfile.rar',
|
|
|
|
'/tmp/sourcefile1', '/tmp/sourcefile2'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template=None, cwd=None
|
2013-07-30 03:59:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
ret = archive.rar(
|
|
|
|
'/tmp/rarfile.rar',
|
|
|
|
['/tmp/sourcefile1', '/tmp/sourcefile2']
|
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['rar', 'a', '-idp', '/tmp/rarfile.rar',
|
|
|
|
'/tmp/sourcefile1', '/tmp/sourcefile2'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template=None, cwd=None
|
2013-07-30 03:59:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@patch('salt.utils.which', lambda exe: None)
|
|
|
|
def test_rar_raises_exception_if_not_found(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandNotFoundError,
|
|
|
|
archive.rar,
|
|
|
|
'/tmp/rarfile.rar',
|
|
|
|
'/tmp/sourcefile1,/tmp/sourcefile2'
|
|
|
|
)
|
|
|
|
self.assertFalse(mock.called)
|
|
|
|
|
2015-01-14 03:07:23 +00:00
|
|
|
@skipIf(which_bin(('unrar', 'rar')) is None, 'unrar not installed')
|
2015-04-09 23:20:53 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: exe[0] if isinstance(exe, (list, tuple)) else exe)
|
|
|
|
@patch('salt.utils.which_bin', lambda exe: exe[0] if isinstance(exe, (list, tuple)) else exe)
|
2013-07-30 04:36:19 +00:00
|
|
|
def test_unrar(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
ret = archive.unrar(
|
|
|
|
'/tmp/rarfile.rar',
|
|
|
|
'/home/strongbad/',
|
|
|
|
excludes='file_1,file_2'
|
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['unrar', 'x', '-idp', '/tmp/rarfile.rar',
|
|
|
|
'-x', 'file_1', '-x', 'file_2', '/home/strongbad/'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template=None
|
2013-07-30 04:36:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
ret = archive.unrar(
|
|
|
|
'/tmp/rarfile.rar',
|
|
|
|
'/home/strongbad/',
|
|
|
|
excludes=['file_1', 'file_2']
|
|
|
|
)
|
|
|
|
self.assertEqual(['salt'], ret)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-08 19:50:15 +00:00
|
|
|
['unrar', 'x', '-idp', '/tmp/rarfile.rar',
|
|
|
|
'-x', 'file_1', '-x', 'file_2', '/home/strongbad/'],
|
2015-01-09 18:39:09 +00:00
|
|
|
runas=None, python_shell=False, template=None
|
2013-07-30 04:36:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@patch('salt.utils.which_bin', lambda exe: None)
|
|
|
|
def test_unrar_raises_exception_if_not_found(self):
|
|
|
|
mock = MagicMock(return_value='salt')
|
|
|
|
with patch.dict(archive.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertRaises(
|
|
|
|
CommandNotFoundError,
|
|
|
|
archive.unrar,
|
|
|
|
'/tmp/rarfile.rar',
|
|
|
|
'/home/strongbad/',
|
|
|
|
)
|
|
|
|
self.assertFalse(mock.called)
|
|
|
|
|
2013-07-27 18:24:49 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(ArchiveTestCase, needs_daemon=False)
|