mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Use patch.object to temporarily replace mock a function call
CURA-7319
This commit is contained in:
parent
d5b58cf3b4
commit
dec68002bc
1 changed files with 6 additions and 7 deletions
|
@ -18,30 +18,29 @@ sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
|
||||||
def test_community_user_script_allowed():
|
def test_community_user_script_allowed():
|
||||||
assert PostProcessingPlugin._isScriptAllowed("blaat.py")
|
assert PostProcessingPlugin._isScriptAllowed("blaat.py")
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)
|
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)
|
||||||
def test_community_bundled_script_allowed():
|
def test_community_bundled_script_allowed():
|
||||||
assert PostProcessingPlugin._isScriptAllowed(_bundled_file_path())
|
assert PostProcessingPlugin._isScriptAllowed(_bundled_file_path())
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", True)
|
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", True)
|
||||||
def test_enterprise_unsigned_user_script_not_allowed():
|
def test_enterprise_unsigned_user_script_not_allowed():
|
||||||
assert not PostProcessingPlugin._isScriptAllowed("blaat.py")
|
assert not PostProcessingPlugin._isScriptAllowed("blaat.py")
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", True)
|
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", True)
|
||||||
def test_enterprise_signed_user_script_allowed():
|
def test_enterprise_signed_user_script_allowed():
|
||||||
mocked_trust = MagicMock()
|
mocked_trust = MagicMock()
|
||||||
mocked_trust.signedFileCheck = MagicMock(return_value=True)
|
mocked_trust.signedFileCheck = MagicMock(return_value=True)
|
||||||
|
|
||||||
realSignatureFileExistsFor = Trust.signatureFileExistsFor
|
with patch.object(Trust, "signatureFileExistsFor", return_value = True):
|
||||||
Trust.signatureFileExistsFor = MagicMock(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
|
# noinspection PyProtectedMember
|
||||||
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)
|
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue