1
0

test_mac_pkgutil.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.runtests import RUNTIME_VARS
  10. from tests.support.case import ModuleCase
  11. import pytest
  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. @pytest.mark.skip_if_not_root
  18. class MacPkgutilModuleTest(ModuleCase):
  19. '''
  20. Validate the mac_pkgutil module
  21. '''
  22. @classmethod
  23. def setUpClass(cls):
  24. cls.test_pkg = os.path.join(RUNTIME_VARS.TMP, 'MacPorts-2.3.4-10.11-ElCapitan.pkg')
  25. def setUp(self):
  26. '''
  27. Get current settings
  28. '''
  29. if not salt.utils.platform.is_darwin():
  30. self.skipTest('Test only available on macOS')
  31. if not salt.utils.path.which('pkgutil'):
  32. self.skipTest('Test requires pkgutil binary')
  33. os_release = self.run_function('grains.get', ['osrelease'])
  34. self.pkg_name = 'com.apple.pkg.BaseSystemResources'
  35. if int(os_release.split('.')[1]) >= 13 and salt.utils.platform.is_darwin():
  36. self.pkg_name = 'com.apple.pkg.iTunesX'
  37. def tearDown(self):
  38. '''
  39. Reset to original settings
  40. '''
  41. self.run_function('pkgutil.forget', [TEST_PKG_NAME])
  42. self.run_function('file.remove', ['/opt/local'])
  43. def test_list(self):
  44. '''
  45. Test pkgutil.list
  46. '''
  47. self.assertIsInstance(self.run_function('pkgutil.list'), list)
  48. self.assertIn(self.pkg_name,
  49. self.run_function('pkgutil.list'))
  50. def test_is_installed(self):
  51. '''
  52. Test pkgutil.is_installed
  53. '''
  54. # Test Package is installed
  55. self.assertTrue(
  56. self.run_function('pkgutil.is_installed',
  57. [self.pkg_name]))
  58. # Test Package is not installed
  59. self.assertFalse(
  60. self.run_function('pkgutil.is_installed', ['spongebob']))
  61. @pytest.mark.destructive_test
  62. def test_install_forget(self):
  63. '''
  64. Test pkgutil.install
  65. Test pkgutil.forget
  66. '''
  67. # Test if installed
  68. self.assertFalse(
  69. self.run_function('pkgutil.is_installed', [TEST_PKG_NAME]))
  70. # Download the package
  71. self.run_function('cp.get_url', [TEST_PKG_URL, self.test_pkg])
  72. # Test install
  73. self.assertTrue(
  74. self.run_function('pkgutil.install', [self.test_pkg, TEST_PKG_NAME]))
  75. self.assertIn(
  76. 'Unsupported scheme',
  77. self.run_function('pkgutil.install', ['ftp://test', 'spongebob']))
  78. # Test forget
  79. self.assertTrue(self.run_function('pkgutil.forget', [TEST_PKG_NAME]))