2014-12-19 17:53:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-01-21 02:25:49 +00:00
|
|
|
|
|
|
|
# Import Python libs
|
2018-01-18 16:55:07 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2015-01-21 02:25:49 +00:00
|
|
|
|
|
|
|
# Import salt module
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.mac_pkgutil as mac_pkgutil
|
2014-12-17 17:58:35 +00:00
|
|
|
|
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
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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: {}}
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
def test_install(self):
|
|
|
|
# Given
|
2017-03-22 16:42:17 +00:00
|
|
|
source = '/foo/bar/fubar.pkg'
|
|
|
|
package_id = 'com.foo.fubar.pkg'
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
# 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)
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
# 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'
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
# 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)
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
# Then
|
|
|
|
self.assertEqual(_install_from_path.called, 0)
|