test_mac_softwareupdate.py 6.0 KB

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