test_mac_pkgutil.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # -*- coding: utf-8 -*-
  2. """
  3. integration tests for mac_pkgutil
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import os
  7. from tests.support.case import ModuleCase
  8. from tests.support.helpers import (
  9. destructiveTest,
  10. requires_system_grains,
  11. runs_on,
  12. skip_if_binaries_missing,
  13. skip_if_not_root,
  14. slowTest,
  15. )
  16. from tests.support.runtests import RUNTIME_VARS
  17. TEST_PKG_URL = (
  18. "https://distfiles.macports.org/MacPorts/MacPorts-2.3.4-10.11-ElCapitan.pkg"
  19. )
  20. TEST_PKG_NAME = "org.macports.MacPorts"
  21. @runs_on(kernel="Darwin")
  22. @skip_if_not_root
  23. @skip_if_binaries_missing("pkgutil")
  24. class MacPkgutilModuleTest(ModuleCase):
  25. """
  26. Validate the mac_pkgutil module
  27. """
  28. @classmethod
  29. def setUpClass(cls):
  30. cls.test_pkg = os.path.join(
  31. RUNTIME_VARS.TMP, "MacPorts-2.3.4-10.11-ElCapitan.pkg"
  32. )
  33. @requires_system_grains
  34. def setUp(self, grains): # pylint: disable=arguments-differ
  35. """
  36. Get current settings
  37. """
  38. os_release = grains["osrelease"]
  39. self.pkg_name = "com.apple.pkg.BaseSystemResources"
  40. if int(os_release.split(".")[1]) >= 13:
  41. self.pkg_name = "com.apple.pkg.iTunesX"
  42. def tearDown(self):
  43. """
  44. Reset to original settings
  45. """
  46. self.run_function("pkgutil.forget", [TEST_PKG_NAME])
  47. self.run_function("file.remove", ["/opt/local"])
  48. @slowTest
  49. def test_list(self):
  50. """
  51. Test pkgutil.list
  52. """
  53. self.assertIsInstance(self.run_function("pkgutil.list"), list)
  54. self.assertIn(self.pkg_name, self.run_function("pkgutil.list"))
  55. @slowTest
  56. def test_is_installed(self):
  57. """
  58. Test pkgutil.is_installed
  59. """
  60. # Test Package is installed
  61. self.assertTrue(self.run_function("pkgutil.is_installed", [self.pkg_name]))
  62. # Test Package is not installed
  63. self.assertFalse(self.run_function("pkgutil.is_installed", ["spongebob"]))
  64. @destructiveTest
  65. @slowTest
  66. def test_install_forget(self):
  67. """
  68. Test pkgutil.install
  69. Test pkgutil.forget
  70. """
  71. # Test if installed
  72. self.assertFalse(self.run_function("pkgutil.is_installed", [TEST_PKG_NAME]))
  73. # Download the package
  74. self.run_function("cp.get_url", [TEST_PKG_URL, self.test_pkg])
  75. # Test install
  76. self.assertTrue(
  77. self.run_function("pkgutil.install", [self.test_pkg, TEST_PKG_NAME])
  78. )
  79. self.assertIn(
  80. "Unsupported scheme",
  81. self.run_function("pkgutil.install", ["ftp://test", "spongebob"]),
  82. )
  83. # Test forget
  84. self.assertTrue(self.run_function("pkgutil.forget", [TEST_PKG_NAME]))