DeleteEntity_UnderLevelPrefab.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_UnderLevelPrefab():
  7. """
  8. Test description:
  9. - Creates an entity.
  10. - Destroys the created entity.
  11. Checks that the entity is correctly destroyed.
  12. """
  13. from editor_python_test_tools.editor_entity_utils import EditorEntity
  14. from editor_python_test_tools.wait_utils import PrefabWaiter
  15. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  16. prefab_test_utils.open_base_tests_level()
  17. # Creates a new Entity at the root level
  18. # Asserts if creation didn't succeed
  19. entity = EditorEntity.create_editor_entity_at((100.0, 100.0, 100.0), name = "TestEntity")
  20. assert entity.id.IsValid(), "Couldn't create entity"
  21. level_container_entity = EditorEntity(entity.get_parent_id())
  22. entity.delete()
  23. # Wait till prefab propagation finishes before validating entity deletion.
  24. PrefabWaiter.wait_for_propagation()
  25. level_container_child_entities_count = len(level_container_entity.get_children_ids())
  26. assert level_container_child_entities_count == 0, f"The level still has {level_container_child_entities_count}" \
  27. f" children when it should have 0."
  28. # Test undo/redo on entity delete
  29. azlmbr.legacy.general.undo()
  30. PrefabWaiter.wait_for_propagation()
  31. level_container_child_entities_count = len(level_container_entity.get_children_ids())
  32. assert level_container_child_entities_count == 1, f"{level_container_child_entities_count} entities " \
  33. f"found in level after Undo operation, when there should " \
  34. f"be 1 entity"
  35. azlmbr.legacy.general.redo()
  36. PrefabWaiter.wait_for_propagation()
  37. level_container_child_entities_count = len(level_container_entity.get_children_ids())
  38. assert level_container_child_entities_count == 0, f"{level_container_child_entities_count} entities " \
  39. f"found in level after Redo operation, when there should " \
  40. f"be 0 entities"
  41. if __name__ == "__main__":
  42. from editor_python_test_tools.utils import Report
  43. Report.start_test(DeleteEntity_UnderLevelPrefab)