salt/tests/unit/modules/test_mac_pkgutil.py

50 lines
1.5 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2015-01-21 02:25:49 +00:00
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
2015-01-21 02:25:49 +00:00
# Import salt module
import salt.modules.mac_pkgutil as mac_pkgutil
2015-01-21 02:25:49 +00:00
# Import Salt Testing libs
2017-03-22 16:42:17 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-22 16:42:17 +00:00
class MacPkgutilTestCase(TestCase, LoaderModuleMockMixin):
def setup_loader_modules(self):
return {mac_pkgutil: {}}
def test_install(self):
# Given
2017-03-22 16:42:17 +00:00
source = '/foo/bar/fubar.pkg'
package_id = 'com.foo.fubar.pkg'
# When
2017-03-22 16:42:17 +00:00
with patch('salt.modules.mac_pkgutil.is_installed',
2016-03-21 23:47:34 +00:00
return_value=False):
2017-03-22 16:42:17 +00:00
with patch('salt.modules.mac_pkgutil._install_from_path',
2016-03-21 23:33:25 +00:00
return_value=True) as _install_from_path:
2016-03-21 23:47:34 +00:00
mac_pkgutil.install(source, package_id)
# Then
_install_from_path.assert_called_with(source)
def test_install_already_there(self):
# Given
2017-03-22 16:42:17 +00:00
source = '/foo/bar/fubar.pkg'
package_id = 'com.foo.fubar.pkg'
# When
2017-03-22 16:42:17 +00:00
with patch('salt.modules.mac_pkgutil.is_installed',
2016-03-21 23:47:34 +00:00
return_value=True):
2017-03-22 16:42:17 +00:00
with patch('salt.modules.mac_pkgutil._install_from_path',
2016-03-21 23:47:34 +00:00
return_value=True) as _install_from_path:
mac_pkgutil.install(source, package_id)
# Then
self.assertEqual(_install_from_path.called, 0)