test_win_update.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Libs
  5. import salt.utils.platform
  6. import salt.utils.win_update as win_update
  7. # Import Salt Testing Libs
  8. from tests.support.mock import MagicMock, patch
  9. from tests.support.unit import TestCase, skipIf
  10. @skipIf(not salt.utils.platform.is_windows(), "System is not Windows")
  11. class WinUpdateTestCase(TestCase):
  12. """
  13. Test cases for salt.utils.win_update
  14. """
  15. def test_installed_no_updates(self):
  16. """
  17. Test installed when there are no updates on the system
  18. """
  19. with patch("salt.utils.winapi.Com", autospec=True), patch(
  20. "win32com.client.Dispatch", autospec=True
  21. ), patch.object(win_update.WindowsUpdateAgent, "refresh", autospec=True):
  22. wua = win_update.WindowsUpdateAgent(online=False)
  23. wua._updates = []
  24. installed_updates = wua.installed()
  25. assert installed_updates.updates.Add.call_count == 0
  26. def test_installed_no_updates_installed(self):
  27. """
  28. Test installed when there are no Installed updates on the system
  29. """
  30. with patch("salt.utils.winapi.Com", autospec=True), patch(
  31. "win32com.client.Dispatch", autospec=True
  32. ), patch.object(win_update.WindowsUpdateAgent, "refresh", autospec=True):
  33. wua = win_update.WindowsUpdateAgent(online=False)
  34. wua._updates = [
  35. MagicMock(IsInstalled=False),
  36. MagicMock(IsInstalled=False),
  37. MagicMock(IsInstalled=False),
  38. ]
  39. installed_updates = wua.installed()
  40. assert installed_updates.updates.Add.call_count == 0
  41. def test_installed_updates_all_installed(self):
  42. """
  43. Test installed when all updates on the system are Installed
  44. """
  45. with patch("salt.utils.winapi.Com", autospec=True), patch(
  46. "win32com.client.Dispatch", autospec=True
  47. ), patch.object(win_update.WindowsUpdateAgent, "refresh", autospec=True):
  48. wua = win_update.WindowsUpdateAgent(online=False)
  49. wua._updates = [
  50. MagicMock(IsInstalled=True),
  51. MagicMock(IsInstalled=True),
  52. MagicMock(IsInstalled=True),
  53. ]
  54. installed_updates = wua.installed()
  55. assert installed_updates.updates.Add.call_count == 3
  56. def test_installed_updates_some_installed(self):
  57. """
  58. Test installed when some updates are installed on the system
  59. """
  60. with patch("salt.utils.winapi.Com", autospec=True), patch(
  61. "win32com.client.Dispatch", autospec=True
  62. ), patch.object(win_update.WindowsUpdateAgent, "refresh", autospec=True):
  63. wua = win_update.WindowsUpdateAgent(online=False)
  64. wua._updates = [
  65. MagicMock(IsInstalled=True),
  66. MagicMock(IsInstalled=False),
  67. MagicMock(IsInstalled=True),
  68. MagicMock(IsInstalled=False),
  69. MagicMock(IsInstalled=True),
  70. ]
  71. installed_updates = wua.installed()
  72. assert installed_updates.updates.Add.call_count == 3