From 6ae0c5ad6c0871163c7118a4b1ede50e97dbcdcb Mon Sep 17 00:00:00 2001 From: twangboy Date: Fri, 23 Jun 2023 13:17:08 -0600 Subject: [PATCH] Add test --- tests/pytests/unit/modules/test_win_appx.py | 47 ++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/pytests/unit/modules/test_win_appx.py b/tests/pytests/unit/modules/test_win_appx.py index f37ca23be8e..425893f8b75 100644 --- a/tests/pytests/unit/modules/test_win_appx.py +++ b/tests/pytests/unit/modules/test_win_appx.py @@ -1,7 +1,7 @@ import pytest import salt.modules.win_appx as win_appx -from tests.support.mock import MagicMock, patch +from tests.support.mock import MagicMock, call, patch pytestmark = [ pytest.mark.windows_whitelisted, @@ -136,6 +136,51 @@ def test_remove(): mock_run_dict.assert_called_with(cmd) +def test_remove_duplicate(): + mock_run_dict = MagicMock() + mock_list_return_1 = [ + { + "Name": "Microsoft.BingWeather", + "PackageFullName": "Microsoft.BingWeather_full_name_1", + "IsBundle": False, + }, + { + "Name": "Microsoft.BingWeather", + "PackageFullName": "Microsoft.BingWeather_full_name_2", + "IsBundle": False, + }, + ] + mock_list_return_2 = [ + { + "Name": "Microsoft.BingWeather", + "PackageFullName": "Microsoft.BingWeather_full_name_1", + "IsBundle": True, + }, + { + "Name": "Microsoft.BingWeather", + "PackageFullName": "Microsoft.BingWeather_full_name_2", + "IsBundle": True, + }, + ] + mock_list_return_3 = [ + { + "Name": "Microsoft.BingWeather", + "PackageFullName": "Microsoft.BingWeather_full_name_2", + "IsBundle": True, + }, + ] + mock_list = MagicMock( + side_effect=[mock_list_return_1, mock_list_return_2, mock_list_return_3] + ) + with patch("salt.utils.win_pwsh.run_dict", mock_run_dict), patch.object( + win_appx, "list_", mock_list + ): + assert win_appx.remove("*bingweather*") is True + cmd_1 = "Remove-AppxPackage -AllUsers -Package Microsoft.BingWeather_full_name_1" + cmd_2 = "Remove-AppxPackage -AllUsers -Package Microsoft.BingWeather_full_name_2" + mock_run_dict.assert_has_calls([call(cmd_1), call(cmd_2)]) + + def test_remove_deprovision_only(): mock_run_dict = MagicMock() mock_list_return = {