AddEntity_UnderAnotherEntity.py 2.2 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 AddEntity_UnderAnotherEntity():
  7. """
  8. Test description:
  9. - Creates an entity at the root level
  10. - Creates a child entity of the root entity
  11. - Verifies Undo/Redo.
  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. parent_entity = EditorEntity.create_editor_entity_at((100.0, 100.0, 100.0))
  20. assert parent_entity.id.IsValid(), "Couldn't create parent entity"
  21. # Creates a new child Entity
  22. # Asserts if creation didn't succeed
  23. child_entity = EditorEntity.create_editor_entity(parent_id=parent_entity.id)
  24. assert child_entity.id.IsValid(), "Couldn't create child entity"
  25. assert parent_entity.get_children_ids()[0] == child_entity.id, "Couldn't create child entity of parent entity"
  26. PrefabWaiter.wait_for_propagation()
  27. # Test undo/redo on add child Entity
  28. azlmbr.legacy.general.undo()
  29. PrefabWaiter.wait_for_propagation()
  30. child_entities_count = len(parent_entity.get_children_ids())
  31. assert child_entities_count == 0, f"{child_entities_count} child entities " \
  32. f"found in level after Undo operation, when there should " \
  33. f"be 0 child entities"
  34. azlmbr.legacy.general.redo()
  35. PrefabWaiter.wait_for_propagation()
  36. child_entities_count = len(parent_entity.get_children_ids())
  37. assert child_entities_count == 1, f"{child_entities_count} entities " \
  38. f"found in level after Redo operation, when there should " \
  39. f"be 1 child entity"
  40. if __name__ == "__main__":
  41. from editor_python_test_tools.utils import Report
  42. Report.start_test(AddEntity_UnderAnotherEntity)