ScriptEvent_AddRemoveMethod_UpdatesInSC.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. class Tests():
  7. node_exists = ("Node found in Node Palette", "Node not found in Node Palette")
  8. method_removed = ("Method removed from scriptevent file", "Method not removed from scriptevent file")
  9. def ScriptEvent_AddRemoveMethod_UpdatesInSC():
  10. """
  11. Summary:
  12. Method can be added/removed to an existing .scriptevents file
  13. Expected Behavior:
  14. The Method is correctly added/removed to the asset, and Script Canvas nodes are updated accordingly.
  15. Test Steps:
  16. 1) Initialize Qt Test objects and open Asset Editor
  17. 2) Create new Script Event file and add two methods
  18. 3) Save the script event file to disk
  19. 4) Open script canvas editor and search the node palette for our new method
  20. 5) Delete one of the methods from script event
  21. 6) Search the node palette for the deleted method. Verify it's gone
  22. 7) close script canvas editor and asset editor
  23. Note:
  24. - This test file must be called from the Open 3D Engine Editor command terminal
  25. - Any passed and failed tests are written to the Editor.log file.
  26. Parsing the file or running a log_monitor are required to observe the test results.
  27. """
  28. # Preconditions
  29. import os
  30. import azlmbr.paths as paths
  31. from editor_python_test_tools.utils import Report
  32. import azlmbr.legacy.general as general
  33. from editor_python_test_tools.QtPy.QtPyO3DEEditor import QtPyO3DEEditor
  34. from consts.asset_editor import (SCRIPT_EVENT_UI, NODE_TEST_METHOD)
  35. general.idle_enable(True)
  36. # 1) Get a handle on our O3DE QtPy objects then initialize the Asset Editor object
  37. qtpy_o3de_editor = QtPyO3DEEditor()
  38. # Close and reopen Asset Editor to ensure we don't have any existing assets open
  39. qtpy_o3de_editor.close_asset_editor()
  40. qtpy_asset_editor = qtpy_o3de_editor.open_asset_editor()
  41. # 2) Create new Script Event file and add two methods
  42. qtpy_asset_editor.click_menu_bar_option(SCRIPT_EVENT_UI)
  43. qtpy_asset_editor.add_method_to_script_event(f"{NODE_TEST_METHOD}_0")
  44. qtpy_asset_editor.add_method_to_script_event(f"{NODE_TEST_METHOD}_1")
  45. # 3) Save the script event file to disk
  46. file_path = os.path.join(paths.projectroot, "TestAssets", "test_file.scriptevents")
  47. qtpy_asset_editor.save_script_event_file(file_path)
  48. # 4) Open script canvas editor and search the node palette for our new method
  49. qtpy_o3de_editor.open_script_canvas()
  50. node_exists = qtpy_o3de_editor.sc_editor.node_palette.search_for_node(f"{NODE_TEST_METHOD}_0") is not None
  51. Report.critical_result(Tests.node_exists, node_exists)
  52. # 5) Delete one of the methods from script event
  53. qtpy_asset_editor.delete_method_from_script_events()
  54. qtpy_asset_editor.save_script_event_file(file_path)
  55. # 6) Search the node palette for the deleted method. Verify it's gone
  56. node_does_not_exist = qtpy_o3de_editor.sc_editor.node_palette.search_for_node(f"{NODE_TEST_METHOD}_0") is None
  57. Report.critical_result(Tests.method_removed, node_does_not_exist)
  58. # 7) close script canvas editor and asset editor
  59. qtpy_o3de_editor.close_script_canvas()
  60. qtpy_o3de_editor.close_asset_editor()
  61. if __name__ == "__main__":
  62. import ImportPathHelper as imports
  63. imports.init()
  64. from editor_python_test_tools.utils import Report
  65. Report.start_test(ScriptEvent_AddRemoveMethod_UpdatesInSC)