test_mac_portspkg.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # -*- coding: utf-8 -*-
  2. """
  3. integration tests for mac_ports
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. from tests.support.case import ModuleCase
  7. from tests.support.helpers import (
  8. destructiveTest,
  9. runs_on,
  10. skip_if_binaries_missing,
  11. skip_if_not_root,
  12. )
  13. @skip_if_not_root
  14. @runs_on(kernel="Darwin")
  15. @skip_if_binaries_missing("port")
  16. class MacPortsModuleTest(ModuleCase):
  17. """
  18. Validate the mac_ports module
  19. """
  20. AGREE_INSTALLED = False
  21. def setUp(self):
  22. """
  23. Get current settings
  24. """
  25. self.AGREE_INSTALLED = "agree" in self.run_function("pkg.list_pkgs")
  26. self.run_function("pkg.refresh_db")
  27. def tearDown(self):
  28. """
  29. Reset to original settings
  30. """
  31. if not self.AGREE_INSTALLED:
  32. self.run_function("pkg.remove", ["agree"])
  33. @destructiveTest
  34. def test_list_pkgs(self):
  35. """
  36. Test pkg.list_pkgs
  37. """
  38. self.run_function("pkg.install", ["agree"])
  39. self.assertIsInstance(self.run_function("pkg.list_pkgs"), dict)
  40. self.assertIn("agree", self.run_function("pkg.list_pkgs"))
  41. @destructiveTest
  42. def test_latest_version(self):
  43. """
  44. Test pkg.latest_version
  45. """
  46. self.run_function("pkg.install", ["agree"])
  47. result = self.run_function("pkg.latest_version", ["agree"], refresh=False)
  48. self.assertIsInstance(result, dict)
  49. self.assertIn("agree", result)
  50. @destructiveTest
  51. def test_remove(self):
  52. """
  53. Test pkg.remove
  54. """
  55. self.run_function("pkg.install", ["agree"])
  56. removed = self.run_function("pkg.remove", ["agree"])
  57. self.assertIsInstance(removed, dict)
  58. self.assertIn("agree", removed)
  59. @destructiveTest
  60. def test_install(self):
  61. """
  62. Test pkg.install
  63. """
  64. self.run_function("pkg.remove", ["agree"])
  65. installed = self.run_function("pkg.install", ["agree"])
  66. self.assertIsInstance(installed, dict)
  67. self.assertIn("agree", installed)
  68. def test_list_upgrades(self):
  69. """
  70. Test pkg.list_upgrades
  71. """
  72. self.assertIsInstance(
  73. self.run_function("pkg.list_upgrades", refresh=False), dict
  74. )
  75. @destructiveTest
  76. def test_upgrade_available(self):
  77. """
  78. Test pkg.upgrade_available
  79. """
  80. self.run_function("pkg.install", ["agree"])
  81. self.assertFalse(
  82. self.run_function("pkg.upgrade_available", ["agree"], refresh=False)
  83. )
  84. def test_refresh_db(self):
  85. """
  86. Test pkg.refresh_db
  87. """
  88. self.assertTrue(self.run_function("pkg.refresh_db"))
  89. @destructiveTest
  90. def test_upgrade(self):
  91. """
  92. Test pkg.upgrade
  93. """
  94. results = self.run_function("pkg.upgrade", refresh=False)
  95. self.assertIsInstance(results, dict)
  96. self.assertTrue(results["result"])