1
0

test_mac_softwareupdate.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # -*- coding: utf-8 -*-
  2. '''
  3. integration tests for mac_softwareupdate
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing libs
  8. from tests.support.unit import skipIf
  9. from tests.support.case import ModuleCase
  10. from tests.support.helpers import destructiveTest, skip_if_not_root
  11. # Import Salt libs
  12. import salt.utils.path
  13. import salt.utils.platform
  14. @skip_if_not_root
  15. @skipIf(not salt.utils.platform.is_darwin(), 'Test only available on macOS')
  16. @skipIf(not salt.utils.path.which('softwareupdate'), '\'softwareupdate\' binary not found in $PATH')
  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. def test_list_available(self):
  48. '''
  49. Test softwareupdate.list_available
  50. '''
  51. # Can't predict what will be returned, so can only test that the return
  52. # is the correct type, dict
  53. self.assertIsInstance(
  54. self.run_function('softwareupdate.list_available'), dict)
  55. @destructiveTest
  56. def test_ignore(self):
  57. '''
  58. Test softwareupdate.ignore
  59. Test softwareupdate.list_ignored
  60. Test softwareupdate.reset_ignored
  61. '''
  62. # Test reset_ignored
  63. self.assertTrue(self.run_function('softwareupdate.reset_ignored'))
  64. self.assertEqual(self.run_function('softwareupdate.list_ignored'), [])
  65. # Test ignore
  66. self.assertTrue(
  67. self.run_function('softwareupdate.ignore', ['spongebob']))
  68. self.assertTrue(
  69. self.run_function('softwareupdate.ignore', ['squidward']))
  70. # Test list_ignored and verify ignore
  71. self.assertIn(
  72. 'spongebob',
  73. self.run_function('softwareupdate.list_ignored'))
  74. self.assertIn(
  75. 'squidward',
  76. self.run_function('softwareupdate.list_ignored'))
  77. @destructiveTest
  78. def test_schedule(self):
  79. '''
  80. Test softwareupdate.schedule_enable
  81. Test softwareupdate.schedule_enabled
  82. '''
  83. # Test enable
  84. self.assertTrue(
  85. self.run_function('softwareupdate.schedule_enable', [True]))
  86. self.assertTrue(self.run_function('softwareupdate.schedule_enabled'))
  87. # Test disable in case it was already enabled
  88. self.assertTrue(
  89. self.run_function('softwareupdate.schedule_enable', [False]))
  90. self.assertFalse(self.run_function('softwareupdate.schedule_enabled'))
  91. @destructiveTest
  92. def test_update(self):
  93. '''
  94. Test softwareupdate.update_all
  95. Test softwareupdate.update
  96. Test softwareupdate.update_available
  97. Need to know the names of updates that are available to properly test
  98. the update functions...
  99. '''
  100. # There's no way to know what the dictionary will contain, so all we can
  101. # check is that the return is a dictionary
  102. self.assertIsInstance(
  103. self.run_function('softwareupdate.update_all'), dict)
  104. # Test update_available
  105. self.assertFalse(
  106. self.run_function('softwareupdate.update_available', ['spongebob']))
  107. # Test update not available
  108. self.assertIn(
  109. 'Update not available',
  110. self.run_function('softwareupdate.update', ['spongebob']))
  111. def test_list_downloads(self):
  112. '''
  113. Test softwareupdate.list_downloads
  114. '''
  115. self.assertIsInstance(
  116. self.run_function('softwareupdate.list_downloads'), list)
  117. @destructiveTest
  118. def test_download(self):
  119. '''
  120. Test softwareupdate.download
  121. Need to know the names of updates that are available to properly test
  122. the download function
  123. '''
  124. # Test update not available
  125. self.assertIn(
  126. 'Update not available',
  127. self.run_function('softwareupdate.download', ['spongebob']))
  128. @destructiveTest
  129. def test_download_all(self):
  130. '''
  131. Test softwareupdate.download_all
  132. '''
  133. self.assertIsInstance(
  134. self.run_function('softwareupdate.download_all'), list)
  135. @destructiveTest
  136. def test_get_set_reset_catalog(self):
  137. '''
  138. Test softwareupdate.download_all
  139. '''
  140. # Reset the catalog
  141. self.assertTrue(self.run_function('softwareupdate.reset_catalog'))
  142. self.assertEqual(self.run_function('softwareupdate.get_catalog'),
  143. 'Default')
  144. # Test setting and getting the catalog
  145. self.assertTrue(
  146. self.run_function('softwareupdate.set_catalog', ['spongebob']))
  147. self.assertEqual(
  148. self.run_function('softwareupdate.get_catalog'), 'spongebob')
  149. # Test reset the catalog
  150. self.assertTrue(self.run_function('softwareupdate.reset_catalog'))
  151. self.assertEqual(self.run_function('softwareupdate.get_catalog'),
  152. 'Default')