DeletePrefab_ContainingASingleEntity.py 1.9 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 DeletePrefab_ContainingASingleEntity():
  7. from pathlib import Path
  8. import azlmbr.legacy.general as general
  9. from editor_python_test_tools.editor_entity_utils import EditorEntity
  10. from editor_python_test_tools.prefab_utils import Prefab
  11. from editor_python_test_tools.wait_utils import PrefabWaiter
  12. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  13. CAR_PREFAB_FILE_NAME = Path(__file__).stem + 'car_prefab'
  14. prefab_test_utils.open_base_tests_level()
  15. # Creates a new entity at the root level
  16. car_entity = EditorEntity.create_editor_entity()
  17. car_prefab_entities = [car_entity]
  18. # Creates a prefab from the new entity
  19. _, car = Prefab.create_prefab(
  20. car_prefab_entities, CAR_PREFAB_FILE_NAME)
  21. # Get parent entity and container id for verifying successful Undo/Redo operations
  22. instance_parent_id = EditorEntity(car.container_entity.get_parent_id())
  23. instance_id = car.container_entity.id
  24. # Deletes the prefab instance
  25. Prefab.remove_prefabs([car])
  26. # Undo the prefab delete
  27. general.undo()
  28. PrefabWaiter.wait_for_propagation()
  29. child_ids = instance_parent_id.get_children_ids()
  30. assert instance_id in child_ids, \
  31. "Undo Failed: Failed to find restored prefab instance after Undo."
  32. # Redo the prefab delete
  33. general.redo()
  34. PrefabWaiter.wait_for_propagation()
  35. child_ids = instance_parent_id.get_children_ids()
  36. assert instance_id not in child_ids, \
  37. "Redo Failed: Instance was still found after redo of instance deletion."
  38. if __name__ == "__main__":
  39. from editor_python_test_tools.utils import Report
  40. Report.start_test(DeletePrefab_ContainingASingleEntity)