salt/tests/unit/modules/mac_pkgutil_test.py

49 lines
1.4 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
# Import salt module
2016-01-23 00:20:25 +00:00
from salt.modules import mac_pkgutil
2015-01-21 02:25:49 +00:00
# Import Salt Testing libs
from salttesting import TestCase, skipIf
2016-03-21 23:47:34 +00:00
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, patch
2016-01-23 02:04:03 +00:00
mac_pkgutil.__salt__ = {}
@skipIf(NO_MOCK, NO_MOCK_REASON)
2016-03-21 21:03:31 +00:00
class MacPkgutilTestCase(TestCase):
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)
# 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)
# Then
self.assertEqual(_install_from_path.called, 0)