From dec68002bcebc06f79d4075412f1abc0624e66b1 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 25 Mar 2020 12:35:15 +0100 Subject: [PATCH] Use patch.object to temporarily replace mock a function call CURA-7319 --- .../tests/TestPostProcessingPlugin.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/PostProcessingPlugin/tests/TestPostProcessingPlugin.py b/plugins/PostProcessingPlugin/tests/TestPostProcessingPlugin.py index a5ef9e47c9..2c9a25fcac 100644 --- a/plugins/PostProcessingPlugin/tests/TestPostProcessingPlugin.py +++ b/plugins/PostProcessingPlugin/tests/TestPostProcessingPlugin.py @@ -18,30 +18,29 @@ sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) def test_community_user_script_allowed(): assert PostProcessingPlugin._isScriptAllowed("blaat.py") + # noinspection PyProtectedMember @patch("cura.ApplicationMetadata.IsEnterpriseVersion", False) def test_community_bundled_script_allowed(): assert PostProcessingPlugin._isScriptAllowed(_bundled_file_path()) + # noinspection PyProtectedMember @patch("cura.ApplicationMetadata.IsEnterpriseVersion", True) def test_enterprise_unsigned_user_script_not_allowed(): assert not PostProcessingPlugin._isScriptAllowed("blaat.py") + # noinspection PyProtectedMember @patch("cura.ApplicationMetadata.IsEnterpriseVersion", True) def test_enterprise_signed_user_script_allowed(): mocked_trust = MagicMock() mocked_trust.signedFileCheck = MagicMock(return_value=True) - realSignatureFileExistsFor = Trust.signatureFileExistsFor - Trust.signatureFileExistsFor = MagicMock(return_value=True) + with patch.object(Trust, "signatureFileExistsFor", return_value = True): + with patch("UM.Trust.Trust.getInstanceOrNone", return_value=mocked_trust): + assert PostProcessingPlugin._isScriptAllowed("blaat.py") - with patch("UM.Trust.Trust.getInstanceOrNone", return_value=mocked_trust): - assert PostProcessingPlugin._isScriptAllowed("blaat.py") - - # cleanup - Trust.signatureFileExistsFor = realSignatureFileExistsFor # noinspection PyProtectedMember @patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)