DeleteEntity_UnderAnotherPrefab.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 DeleteEntity_UnderAnotherPrefab():
  7. """
  8. Test description:
  9. - Creates an entity.
  10. - Creates a prefab out of the above entity.
  11. - Focuses on the created prefab and destroys the entity within.
  12. Checks that the entity is correctly destroyed.
  13. """
  14. from editor_python_test_tools.editor_entity_utils import EditorEntity
  15. from editor_python_test_tools.prefab_utils import Prefab
  16. from editor_python_test_tools.wait_utils import PrefabWaiter
  17. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  18. prefab_test_utils.open_base_tests_level()
  19. PREFAB_FILE_NAME = 'some_prefab'
  20. # Creates a new entity at the root level
  21. entity = EditorEntity.create_editor_entity()
  22. assert entity.id.IsValid(), "Couldn't create entity."
  23. # Asserts if prefab creation doesn't succeed
  24. child_prefab, child_instance = Prefab.create_prefab([entity], PREFAB_FILE_NAME)
  25. child_entity_ids_inside_prefab = child_instance.get_direct_child_entities()
  26. assert len(
  27. child_entity_ids_inside_prefab) == 1, f"{len(child_entity_ids_inside_prefab)} entities found inside prefab" \
  28. f" when there should have been just 1 entity"
  29. child_entity_inside_prefab = child_entity_ids_inside_prefab[0]
  30. child_entity_inside_prefab.focus_on_owning_prefab()
  31. child_entity_inside_prefab.delete()
  32. # Wait till prefab propagation finishes before validating entity deletion.
  33. PrefabWaiter.wait_for_propagation()
  34. child_entity_ids_inside_prefab = child_instance.get_direct_child_entities()
  35. assert len(
  36. child_entity_ids_inside_prefab) == 0, f"{len(child_entity_ids_inside_prefab)} entities found inside prefab" \
  37. f" when there should have been 0 entities"
  38. # Test undo/redo on entity delete
  39. azlmbr.legacy.general.undo()
  40. PrefabWaiter.wait_for_propagation()
  41. child_entity_ids_inside_prefab = child_instance.get_direct_child_entities()
  42. assert len(
  43. child_entity_ids_inside_prefab) == 1, f"{len(child_entity_ids_inside_prefab)} entities found inside prefab" \
  44. f" after Undo operation, when there should have been 1 entities"
  45. azlmbr.legacy.general.redo()
  46. PrefabWaiter.wait_for_propagation()
  47. child_entity_ids_inside_prefab = child_instance.get_direct_child_entities()
  48. assert len(
  49. child_entity_ids_inside_prefab) == 0, f"{len(child_entity_ids_inside_prefab)} entities found inside prefab" \
  50. f" after Redo operation, when there should have been 0 entities"
  51. if __name__ == "__main__":
  52. from editor_python_test_tools.utils import Report
  53. Report.start_test(DeleteEntity_UnderAnotherPrefab)