TestPostProcessingPlugin.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (c) 2020 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os
  4. import sys
  5. from unittest.mock import patch, MagicMock
  6. from UM.PluginRegistry import PluginRegistry
  7. from UM.Resources import Resources
  8. from UM.Trust import Trust
  9. from ..PostProcessingPlugin import PostProcessingPlugin
  10. # not sure if needed
  11. sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
  12. """ In this file, community refers to regular Cura for makers."""
  13. mock_plugin_registry = MagicMock()
  14. mock_plugin_registry.getPluginPath = MagicMock(return_value = "mocked_plugin_path")
  15. # noinspection PyProtectedMember
  16. @patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)
  17. def test_community_user_script_allowed():
  18. assert PostProcessingPlugin._isScriptAllowed("blaat.py")
  19. # noinspection PyProtectedMember
  20. @patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)
  21. def test_community_bundled_script_allowed():
  22. assert PostProcessingPlugin._isScriptAllowed(_bundled_file_path())
  23. # noinspection PyProtectedMember
  24. @patch("cura.ApplicationMetadata.IsEnterpriseVersion", True)
  25. @patch.object(PluginRegistry, "getInstance", return_value=mock_plugin_registry)
  26. def test_enterprise_unsigned_user_script_not_allowed(plugin_registry):
  27. assert not PostProcessingPlugin._isScriptAllowed("blaat.py")
  28. # noinspection PyProtectedMember
  29. @patch("cura.ApplicationMetadata.IsEnterpriseVersion", True)
  30. @patch.object(PluginRegistry, "getInstance", return_value=mock_plugin_registry)
  31. def test_enterprise_signed_user_script_allowed(plugin_registry):
  32. mocked_trust = MagicMock()
  33. mocked_trust.signedFileCheck = MagicMock(return_value=True)
  34. plugin_registry.getPluginPath = MagicMock(return_value="mocked_plugin_path")
  35. with patch.object(Trust, "signatureFileExistsFor", return_value = True):
  36. with patch("UM.Trust.Trust.getInstanceOrNone", return_value=mocked_trust):
  37. assert PostProcessingPlugin._isScriptAllowed("mocked_plugin_path/scripts/blaat.py")
  38. # noinspection PyProtectedMember
  39. @patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)
  40. def test_enterprise_bundled_script_allowed():
  41. assert PostProcessingPlugin._isScriptAllowed(_bundled_file_path())
  42. def _bundled_file_path():
  43. return os.path.join(
  44. Resources.getStoragePath(Resources.Resources) + "scripts/blaat.py"
  45. )