salt/tests/integration/modules/test_mac_pkgutil.py

89 lines
2.5 KiB
Python
Raw Normal View History

2016-03-19 23:04:42 +00:00
# -*- coding: utf-8 -*-
'''
integration tests for mac_pkgutil
'''
# Import python libs
2016-03-21 21:50:19 +00:00
from __future__ import absolute_import
2016-03-21 21:43:30 +00:00
import os
2016-03-19 23:04:42 +00:00
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.paths import TMP
from tests.support.helpers import destructiveTest, skip_if_not_root
2016-03-19 23:04:42 +00:00
# Import salt libs
import salt.utils
2016-03-21 21:03:31 +00:00
TEST_PKG_URL = 'https://distfiles.macports.org/MacPorts/MacPorts-2.3.4-10.11-ElCapitan.pkg'
TEST_PKG_NAME = 'org.macports.MacPorts'
TEST_PKG = os.path.join(TMP, 'MacPorts-2.3.4-10.11-ElCapitan.pkg')
2016-03-21 18:10:28 +00:00
2016-03-19 23:04:42 +00:00
@skip_if_not_root
class MacPkgutilModuleTest(ModuleCase):
2016-03-19 23:04:42 +00:00
'''
Validate the mac_pkgutil module
'''
def setUp(self):
'''
Get current settings
'''
if not salt.utils.is_darwin():
self.skipTest('Test only available on macOS')
2016-03-19 23:04:42 +00:00
if not salt.utils.which('pkgutil'):
self.skipTest('Test requires pkgutil binary')
def tearDown(self):
'''
Reset to original settings
'''
2016-03-21 22:08:03 +00:00
self.run_function('pkgutil.forget', ['org.macports.MacPorts'])
self.run_function('file.remove', ['/opt/local'])
2016-03-19 23:04:42 +00:00
def test_list(self):
'''
2016-03-21 21:50:19 +00:00
Test pkgutil.list
2016-03-19 23:04:42 +00:00
'''
2016-03-21 21:03:31 +00:00
self.assertIsInstance(self.run_function('pkgutil.list'), list)
self.assertIn('com.apple.pkg.BaseSystemResources',
self.run_function('pkgutil.list'))
2016-03-19 23:04:42 +00:00
def test_is_installed(self):
'''
2016-03-21 21:50:19 +00:00
Test pkgutil.is_installed
2016-03-19 23:04:42 +00:00
'''
# Test Package is installed
self.assertTrue(
2016-03-21 21:03:31 +00:00
self.run_function('pkgutil.is_installed',
2016-03-21 18:10:28 +00:00
['com.apple.pkg.BaseSystemResources']))
2016-03-19 23:04:42 +00:00
# Test Package is not installed
self.assertFalse(
2016-03-21 21:03:31 +00:00
self.run_function('pkgutil.is_installed', ['spongebob']))
2016-03-19 23:04:42 +00:00
@destructiveTest
2016-03-21 22:45:29 +00:00
def test_install_forget(self):
2016-03-19 23:04:42 +00:00
'''
2016-03-21 21:03:31 +00:00
Test pkgutil.install
2016-03-21 22:45:29 +00:00
Test pkgutil.forget
2016-03-19 23:04:42 +00:00
'''
# Test if installed
self.assertFalse(
2016-03-21 21:03:31 +00:00
self.run_function('pkgutil.is_installed', [TEST_PKG_NAME]))
2016-03-19 23:04:42 +00:00
2016-03-21 23:33:25 +00:00
# Download the package
2016-03-21 21:03:31 +00:00
self.run_function('cp.get_url', [TEST_PKG_URL, TEST_PKG])
2016-03-19 23:04:42 +00:00
# Test install
2016-03-21 21:07:06 +00:00
self.assertTrue(
self.run_function('pkgutil.install', [TEST_PKG, TEST_PKG_NAME]))
2016-03-21 22:45:29 +00:00
self.assertIn(
'Unsupported scheme',
2016-03-21 22:51:48 +00:00
self.run_function('pkgutil.install', ['ftp://test', 'spongebob']))
2016-03-21 22:45:29 +00:00
# Test forget
self.assertTrue(self.run_function('pkgutil.forget', [TEST_PKG_NAME]))