1
0

test_mac_pkgutil.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. '''
  3. integration tests for mac_pkgutil
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os
  8. # Import Salt Testing libs
  9. from tests.support.case import ModuleCase
  10. from tests.support.paths import TMP
  11. from tests.support.helpers import destructiveTest, skip_if_not_root
  12. # Import Salt libs
  13. import salt.utils.path
  14. import salt.utils.platform
  15. TEST_PKG_URL = 'https://distfiles.macports.org/MacPorts/MacPorts-2.3.4-10.11-ElCapitan.pkg'
  16. TEST_PKG_NAME = 'org.macports.MacPorts'
  17. TEST_PKG = os.path.join(TMP, 'MacPorts-2.3.4-10.11-ElCapitan.pkg')
  18. @skip_if_not_root
  19. class MacPkgutilModuleTest(ModuleCase):
  20. '''
  21. Validate the mac_pkgutil module
  22. '''
  23. def setUp(self):
  24. '''
  25. Get current settings
  26. '''
  27. if not salt.utils.platform.is_darwin():
  28. self.skipTest('Test only available on macOS')
  29. if not salt.utils.path.which('pkgutil'):
  30. self.skipTest('Test requires pkgutil binary')
  31. os_release = self.run_function('grains.get', ['osrelease'])
  32. self.pkg_name = 'com.apple.pkg.BaseSystemResources'
  33. if int(os_release.split('.')[1]) >= 13 and salt.utils.platform.is_darwin():
  34. self.pkg_name = 'com.apple.pkg.iTunesX'
  35. def tearDown(self):
  36. '''
  37. Reset to original settings
  38. '''
  39. self.run_function('pkgutil.forget', [TEST_PKG_NAME])
  40. self.run_function('file.remove', ['/opt/local'])
  41. def test_list(self):
  42. '''
  43. Test pkgutil.list
  44. '''
  45. self.assertIsInstance(self.run_function('pkgutil.list'), list)
  46. self.assertIn(self.pkg_name,
  47. self.run_function('pkgutil.list'))
  48. def test_is_installed(self):
  49. '''
  50. Test pkgutil.is_installed
  51. '''
  52. # Test Package is installed
  53. self.assertTrue(
  54. self.run_function('pkgutil.is_installed',
  55. [self.pkg_name]))
  56. # Test Package is not installed
  57. self.assertFalse(
  58. self.run_function('pkgutil.is_installed', ['spongebob']))
  59. @destructiveTest
  60. def test_install_forget(self):
  61. '''
  62. Test pkgutil.install
  63. Test pkgutil.forget
  64. '''
  65. # Test if installed
  66. self.assertFalse(
  67. self.run_function('pkgutil.is_installed', [TEST_PKG_NAME]))
  68. # Download the package
  69. self.run_function('cp.get_url', [TEST_PKG_URL, TEST_PKG])
  70. # Test install
  71. self.assertTrue(
  72. self.run_function('pkgutil.install', [TEST_PKG, TEST_PKG_NAME]))
  73. self.assertIn(
  74. 'Unsupported scheme',
  75. self.run_function('pkgutil.install', ['ftp://test', 'spongebob']))
  76. # Test forget
  77. self.assertTrue(self.run_function('pkgutil.forget', [TEST_PKG_NAME]))