test_mac_pkgutil.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. import pytest
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import requires_system_grains
  10. from tests.support.runtests import RUNTIME_VARS
  11. TEST_PKG_URL = (
  12. "https://distfiles.macports.org/MacPorts/MacPorts-2.3.4-10.11-ElCapitan.pkg"
  13. )
  14. TEST_PKG_NAME = "org.macports.MacPorts"
  15. @pytest.mark.skip_if_not_root
  16. @pytest.mark.skip_unless_on_darwin
  17. @pytest.mark.skip_if_binaries_missing("pkgutil")
  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(
  25. RUNTIME_VARS.TMP, "MacPorts-2.3.4-10.11-ElCapitan.pkg"
  26. )
  27. @requires_system_grains
  28. def setUp(self, grains): # pylint: disable=arguments-differ
  29. """
  30. Get current settings
  31. """
  32. os_release = grains["osrelease"]
  33. self.pkg_name = "com.apple.pkg.BaseSystemResources"
  34. if int(os_release.split(".")[1]) >= 13:
  35. self.pkg_name = "com.apple.pkg.iTunesX"
  36. def tearDown(self):
  37. """
  38. Reset to original settings
  39. """
  40. self.run_function("pkgutil.forget", [TEST_PKG_NAME])
  41. self.run_function("file.remove", ["/opt/local"])
  42. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  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, self.run_function("pkgutil.list"))
  49. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  50. def test_is_installed(self):
  51. """
  52. Test pkgutil.is_installed
  53. """
  54. # Test Package is installed
  55. self.assertTrue(self.run_function("pkgutil.is_installed", [self.pkg_name]))
  56. # Test Package is not installed
  57. self.assertFalse(self.run_function("pkgutil.is_installed", ["spongebob"]))
  58. @pytest.mark.destructive_test
  59. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  60. def test_install_forget(self):
  61. """
  62. Test pkgutil.install
  63. Test pkgutil.forget
  64. """
  65. # Test if installed
  66. self.assertFalse(self.run_function("pkgutil.is_installed", [TEST_PKG_NAME]))
  67. # Download the package
  68. self.run_function("cp.get_url", [TEST_PKG_URL, self.test_pkg])
  69. # Test install
  70. self.assertTrue(
  71. self.run_function("pkgutil.install", [self.test_pkg, TEST_PKG_NAME])
  72. )
  73. self.assertIn(
  74. "Unsupported scheme",
  75. self.run_function("pkgutil.install", ["ftp://test", "spongebob"]),
  76. )
  77. # Test forget
  78. self.assertTrue(self.run_function("pkgutil.forget", [TEST_PKG_NAME]))