test_mac_softwareupdate.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # -*- coding: utf-8 -*-
  2. """
  3. integration tests for mac_softwareupdate
  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. slowTest,
  13. )
  14. @skip_if_not_root
  15. @runs_on(kernel="Darwin")
  16. @skip_if_binaries_missing("softwareupdate")
  17. class MacSoftwareUpdateModuleTest(ModuleCase):
  18. """
  19. Validate the mac_softwareupdate module
  20. """
  21. IGNORED_LIST = []
  22. SCHEDULE = False
  23. CATALOG = ""
  24. def setUp(self):
  25. """
  26. Get current settings
  27. """
  28. self.IGNORED_LIST = self.run_function("softwareupdate.list_ignored")
  29. self.SCHEDULE = self.run_function("softwareupdate.schedule")
  30. self.CATALOG = self.run_function("softwareupdate.get_catalog")
  31. super(MacSoftwareUpdateModuleTest, self).setUp()
  32. def tearDown(self):
  33. """
  34. Reset to original settings
  35. """
  36. if self.IGNORED_LIST:
  37. for item in self.IGNORED_LIST:
  38. self.run_function("softwareupdate.ignore", [item])
  39. else:
  40. self.run_function("softwareupdate.reset_ignored")
  41. self.run_function("softwareupdate.schedule", [self.SCHEDULE])
  42. if self.CATALOG == "Default":
  43. self.run_function("softwareupdate.reset_catalog")
  44. else:
  45. self.run_function("softwareupdate.set_catalog", [self.CATALOG])
  46. super(MacSoftwareUpdateModuleTest, self).tearDown()
  47. @slowTest
  48. def test_list_available(self):
  49. """
  50. Test softwareupdate.list_available
  51. """
  52. # Can't predict what will be returned, so can only test that the return
  53. # is the correct type, dict
  54. self.assertIsInstance(self.run_function("softwareupdate.list_available"), dict)
  55. @destructiveTest
  56. @slowTest
  57. def test_ignore(self):
  58. """
  59. Test softwareupdate.ignore
  60. Test softwareupdate.list_ignored
  61. Test softwareupdate.reset_ignored
  62. """
  63. # Test reset_ignored
  64. self.assertTrue(self.run_function("softwareupdate.reset_ignored"))
  65. self.assertEqual(self.run_function("softwareupdate.list_ignored"), [])
  66. # Test ignore
  67. self.assertTrue(self.run_function("softwareupdate.ignore", ["spongebob"]))
  68. self.assertTrue(self.run_function("softwareupdate.ignore", ["squidward"]))
  69. # Test list_ignored and verify ignore
  70. self.assertIn("spongebob", self.run_function("softwareupdate.list_ignored"))
  71. self.assertIn("squidward", self.run_function("softwareupdate.list_ignored"))
  72. @destructiveTest
  73. @slowTest
  74. def test_schedule(self):
  75. """
  76. Test softwareupdate.schedule_enable
  77. Test softwareupdate.schedule_enabled
  78. """
  79. # Test enable
  80. self.assertTrue(self.run_function("softwareupdate.schedule_enable", [True]))
  81. self.assertTrue(self.run_function("softwareupdate.schedule_enabled"))
  82. # Test disable in case it was already enabled
  83. self.assertTrue(self.run_function("softwareupdate.schedule_enable", [False]))
  84. self.assertFalse(self.run_function("softwareupdate.schedule_enabled"))
  85. @destructiveTest
  86. @slowTest
  87. def test_update(self):
  88. """
  89. Test softwareupdate.update_all
  90. Test softwareupdate.update
  91. Test softwareupdate.update_available
  92. Need to know the names of updates that are available to properly test
  93. the update functions...
  94. """
  95. # There's no way to know what the dictionary will contain, so all we can
  96. # check is that the return is a dictionary
  97. self.assertIsInstance(self.run_function("softwareupdate.update_all"), dict)
  98. # Test update_available
  99. self.assertFalse(
  100. self.run_function("softwareupdate.update_available", ["spongebob"])
  101. )
  102. # Test update not available
  103. self.assertIn(
  104. "Update not available",
  105. self.run_function("softwareupdate.update", ["spongebob"]),
  106. )
  107. @slowTest
  108. def test_list_downloads(self):
  109. """
  110. Test softwareupdate.list_downloads
  111. """
  112. self.assertIsInstance(self.run_function("softwareupdate.list_downloads"), list)
  113. @destructiveTest
  114. @slowTest
  115. def test_download(self):
  116. """
  117. Test softwareupdate.download
  118. Need to know the names of updates that are available to properly test
  119. the download function
  120. """
  121. # Test update not available
  122. self.assertIn(
  123. "Update not available",
  124. self.run_function("softwareupdate.download", ["spongebob"]),
  125. )
  126. @destructiveTest
  127. @slowTest
  128. def test_download_all(self):
  129. """
  130. Test softwareupdate.download_all
  131. """
  132. self.assertIsInstance(self.run_function("softwareupdate.download_all"), list)
  133. @destructiveTest
  134. @slowTest
  135. def test_get_set_reset_catalog(self):
  136. """
  137. Test softwareupdate.download_all
  138. """
  139. # Reset the catalog
  140. self.assertTrue(self.run_function("softwareupdate.reset_catalog"))
  141. self.assertEqual(self.run_function("softwareupdate.get_catalog"), "Default")
  142. # Test setting and getting the catalog
  143. self.assertTrue(self.run_function("softwareupdate.set_catalog", ["spongebob"]))
  144. self.assertEqual(self.run_function("softwareupdate.get_catalog"), "spongebob")
  145. # Test reset the catalog
  146. self.assertTrue(self.run_function("softwareupdate.reset_catalog"))
  147. self.assertEqual(self.run_function("softwareupdate.get_catalog"), "Default")