def test_uptodate_no_updates(self): """ Test uptodate function with no updates found. """ expected = { "name": "NA", "changes": {}, "result": True, "comment": "No updates found", } class NoUpdates(Updates): @staticmethod def updates(): # pylint: disable=method-hidden return UPDATES_LIST_NONE @staticmethod def count(): return len(UPDATES_LIST_NONE) patch_winapi_com = patch("salt.utils.winapi.Com", autospec=True) patch_win32com = patch("win32com.client.Dispatch", autospec=True) patch_win_update_agent = patch.object( salt.utils.win_update.WindowsUpdateAgent, "refresh", autospec=True) patch_win_update = patch.object(salt.utils.win_update, "Updates", autospec=True, return_value=NoUpdates()) with patch_winapi_com, patch_win32com, patch_win_update_agent, patch_win_update: result = win_wua.uptodate(name="NA") self.assertDictEqual(result, expected)
def test_uptodate_test_mode(self): """ Test uptodate function in test=true mode. """ expected = { "name": "NA", "changes": {}, "result": None, "comment": "Updates will be installed:", } patch_winapi_com = patch("salt.utils.winapi.Com", autospec=True) patch_win32com = patch("win32com.client.Dispatch", autospec=True) patch_win_update_agent = patch.object( salt.utils.win_update.WindowsUpdateAgent, "refresh", autospec=True) patch_opts = patch.dict(win_wua.__opts__, {"test": True}) with patch_winapi_com, patch_win32com, patch_win_update_agent, patch_opts: wua = win_update.WindowsUpdateAgent(online=False) wua._updates = [MagicMock(IsInstalled=False, IsDownloaded=False)] result = win_wua.uptodate(name="NA") self.assertDictEqual(result, expected)
def test_uptodate(self): """ Test uptodate function with some updates found. """ expected = { "name": "NA", "changes": { "failed": { "eac02b09-d745-4891-b80f-400e0e5e4b6d": { "Title": "Blank...", "KBs": ["KB4052623"], } } }, "result": False, "comment": "Updates failed", } updates_not_installed = { "afda9e11-44a0-4602-9e9b-423af11ecaed": { "KBs": ["KB4541329"], "Installed": False, "Title": "Blank", }, "a0f997b1-1abe-4a46-941f-b37f732f9fbd": { "KBs": ["KB3193497"], "Installed": False, "Title": "Blank", }, "eac02b09-d745-4891-b80f-400e0e5e4b6d": { "KBs": ["KB4052623"], "Installed": False, "Title": "Blank", }, "eac02c07-d744-4892-b80f-312d045e4ccc": { "KBs": ["KB4052444"], "Installed": False, "Title": "Blank", }, } fake_wua = MagicMock() fake_updates = MagicMock() fake_updates.list.return_value = updates_not_installed fake_wua_updates = MagicMock() fake_wua_updates.list.return_value = UPDATES_LIST fake_wua.updates.return_value = fake_wua_updates patch_winapi_com = patch("salt.utils.winapi.Com", autospec=True) patch_win32 = patch("win32com.client.Dispatch", autospec=True) patch_wua = patch( "salt.utils.win_update.WindowsUpdateAgent", autospec=True, return_value=fake_wua, ) patch_win_wua_update = patch("salt.utils.win_update.Updates", autospec=True, return_value=fake_updates) patch_opts = patch.dict(win_wua.__opts__, {"test": False}) with patch_winapi_com, patch_win32, patch_wua, patch_win_wua_update, patch_opts: wua = win_update.WindowsUpdateAgent(online=False) result = win_wua.uptodate(name="NA") self.assertDictEqual(result, expected)
def test_uptodate(updates_list): """ Test uptodate function with some updates found. """ expected = { "name": "NA", "changes": { "failed": { "a0f997b1-1abe-4a46-941f-b37f732f9fbd": { "KBs": ["KB3193497"], "Title": "Blank", }, "afda9e11-44a0-4602-9e9b-423af11ecaed": { "KBs": ["KB4541329"], "Title": "Blank", }, "eac02b09-d745-4891-b80f-400e0e5e4b6d": { "KBs": ["KB4052623"], "Title": "KB4052623: Really long title that exceeds 40 characters", }, }, "superseded": { "eac02c07-d744-4892-b80f-312d045e4ccc": { "KBs": ["KB4052444"], "Title": "Superseded Update", } }, }, "result": False, "comment": "Some updates failed to install\nSome updates were superseded", } updates_not_installed = { "afda9e11-44a0-4602-9e9b-423af11ecaed": { "KBs": ["KB4541329"], "Installed": False, "Title": "Blank", }, "a0f997b1-1abe-4a46-941f-b37f732f9fbd": { "KBs": ["KB3193497"], "Installed": False, "Title": "Blank", }, "eac02b09-d745-4891-b80f-400e0e5e4b6d": { "KBs": ["KB4052623"], "Installed": False, "Title": "KB4052623: Really long title that exceeds 40 characters", }, "eac02c07-d744-4892-b80f-312d045e4ccc": { "KBs": ["KB4052444"], "Installed": False, "Title": "Superseded Update", }, } fake_updates = MagicMock() fake_updates.list.return_value = updates_not_installed patch_win_wua_update = patch( "salt.utils.win_update.Updates", autospec=True, return_value=fake_updates, ) fake_wua_updates = MagicMock() fake_wua_updates.list.return_value = updates_list fake_wua = MagicMock() fake_wua.updates.return_value = fake_wua_updates patch_wua = patch( "salt.utils.win_update.WindowsUpdateAgent", autospec=True, return_value=fake_wua, ) patch_winapi_com = patch("salt.utils.winapi.Com", autospec=True) patch_win32 = patch("win32com.client.Dispatch", autospec=True) patch_opts = patch.dict(win_wua.__opts__, {"test": False}) with patch_winapi_com, patch_win32, patch_wua, patch_win_wua_update, patch_opts: result = win_wua.uptodate(name="NA") assert result == expected