From 627d5ab0c9da9cecd6e68f0d56707d95070f323b Mon Sep 17 00:00:00 2001 From: twangboy Date: Thu, 9 Nov 2017 14:55:19 -0700 Subject: [PATCH] Mock `salt.utils.which` cmd.run return values are mocked --- tests/unit/modules/test_disk.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/unit/modules/test_disk.py b/tests/unit/modules/test_disk.py index 7060108ddf..78ff0815a1 100644 --- a/tests/unit/modules/test_disk.py +++ b/tests/unit/modules/test_disk.py @@ -141,18 +141,16 @@ class DiskTestCase(TestCase, LoaderModuleMockMixin): self.assertEqual(len(args[0].split()), 6) self.assertEqual(kwargs, {'python_shell': False}) - @skipIf(not salt.utils.which('sync'), 'sync not found') - @skipIf(not salt.utils.which('mkfs'), 'mkfs not found') def test_format(self): ''' unit tests for disk.format ''' device = '/dev/sdX1' mock = MagicMock(return_value=0) - with patch.dict(disk.__salt__, {'cmd.retcode': mock}): + with patch.dict(disk.__salt__, {'cmd.retcode': mock}),\ + patch('salt.utils.which', MagicMock(return_value=True)): self.assertEqual(disk.format_(device), True) - @skipIf(not salt.utils.which('lsblk'), 'lsblk not found') def test_fstype(self): ''' unit tests for disk.fstype @@ -160,17 +158,18 @@ class DiskTestCase(TestCase, LoaderModuleMockMixin): device = '/dev/sdX1' fs_type = 'ext4' mock = MagicMock(return_value='FSTYPE\n{0}'.format(fs_type)) - with patch.dict(disk.__grains__, {'kernel': 'Linux'}): - with patch.dict(disk.__salt__, {'cmd.run': mock}): - self.assertEqual(disk.fstype(device), fs_type) + with patch.dict(disk.__grains__, {'kernel': 'Linux'}), \ + patch.dict(disk.__salt__, {'cmd.run': mock}), \ + patch('salt.utils.which', MagicMock(return_value=True)): + self.assertEqual(disk.fstype(device), fs_type) - @skipIf(not salt.utils.which('resize2fs'), 'resize2fs not found') def test_resize2fs(self): ''' unit tests for disk.resize2fs ''' device = '/dev/sdX1' mock = MagicMock() - with patch.dict(disk.__salt__, {'cmd.run_all': mock}): + with patch.dict(disk.__salt__, {'cmd.run_all': mock}), \ + patch('salt.utils.which', MagicMock(return_value=True)): disk.resize2fs(device) mock.assert_called_once_with('resize2fs {0}'.format(device), python_shell=False)