InstantiatePrefab_LevelPrefab.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. def InstantiatePrefab_LevelPrefab():
  7. """
  8. Test description:
  9. - Opens a simple level.
  10. - Instantiates a different level.prefab into the level, and validates its structure.
  11. - Validates Undo/Redo operations on the prefab instantiation.
  12. """
  13. import os
  14. import azlmbr.legacy.general as general
  15. from editor_python_test_tools.prefab_utils import Prefab
  16. from editor_python_test_tools.wait_utils import PrefabWaiter
  17. from editor_python_test_tools.editor_entity_utils import EditorEntity
  18. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  19. prefab_test_utils.open_base_tests_level()
  20. # Find and instantiate an existing level.prefab
  21. test_level_prefab_path = os.path.join("Levels", "Prefab", "QuitOnSuccessfulSpawn", "QuitOnSuccessfulSpawn.prefab")
  22. test_level_prefab = Prefab.get_prefab(test_level_prefab_path)
  23. test_level_prefab_instance = test_level_prefab.instantiate()
  24. parent_entity = EditorEntity(test_level_prefab_instance.container_entity.get_parent_id())
  25. # Validate that the expected prefab is now present with the proper entity/component in our test level
  26. spawner_child_entity = test_level_prefab_instance.get_direct_child_entity_by_name("SC_Spawner")
  27. assert spawner_child_entity.has_component("Script Canvas"), \
  28. "Failed to find expected child entity with the proper component"
  29. # Validate Undo/Redo properly removes and re-instantiates the level.prefab
  30. general.undo()
  31. PrefabWaiter.wait_for_propagation()
  32. child_entities = parent_entity.get_children_ids()
  33. assert test_level_prefab_instance.container_entity.id not in child_entities, \
  34. "Undo Failed: Unexpectedly still found the prefab instance after Undo"
  35. general.redo()
  36. PrefabWaiter.wait_for_propagation()
  37. child_entities = parent_entity.get_children_ids()
  38. assert test_level_prefab_instance.container_entity.id in child_entities, \
  39. "Redo Failed: Failed to find prefab instance in the level after Redo"
  40. if __name__ == "__main__":
  41. from editor_python_test_tools.utils import Report
  42. Report.start_test(InstantiatePrefab_LevelPrefab)