2014-12-19 17:53:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-01-21 02:25:49 +00:00
|
|
|
|
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import salt module
|
2016-01-23 00:20:25 +00:00
|
|
|
from salt.modules import mac_pkgutil
|
2014-12-17 17:58:35 +00:00
|
|
|
|
2015-01-21 02:25:49 +00:00
|
|
|
# Import Salt Testing libs
|
2014-12-17 17:58:35 +00:00
|
|
|
from salttesting import TestCase, skipIf
|
2016-03-21 23:47:34 +00:00
|
|
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, patch
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
|
2016-01-23 02:04:03 +00:00
|
|
|
mac_pkgutil.__salt__ = {}
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2016-03-21 21:03:31 +00:00
|
|
|
class MacPkgutilTestCase(TestCase):
|
2014-12-17 17:58:35 +00:00
|
|
|
|
|
|
|
def test_install(self):
|
|
|
|
# Given
|
|
|
|
source = "/foo/bar/fubar.pkg"
|
|
|
|
package_id = "com.foo.fubar.pkg"
|
|
|
|
|
|
|
|
# When
|
2016-01-23 02:09:08 +00:00
|
|
|
with patch("salt.modules.mac_pkgutil.is_installed",
|
2016-03-21 23:47:34 +00:00
|
|
|
return_value=False):
|
2016-01-23 02:09:08 +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
|
|
|
|
source = "/foo/bar/fubar.pkg"
|
|
|
|
package_id = "com.foo.fubar.pkg"
|
|
|
|
|
|
|
|
# When
|
2016-01-23 02:09:08 +00:00
|
|
|
with patch("salt.modules.mac_pkgutil.is_installed",
|
2016-03-21 23:47:34 +00:00
|
|
|
return_value=True):
|
2016-01-23 02:09:08 +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)
|