AddEntity_UnderLevelPrefab.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_UnderLevelPrefab():
  7. """
  8. Test description:
  9. - Creates an entity under level container.
  10. - Verifies Undo/Redo.
  11. """
  12. from editor_python_test_tools.editor_entity_utils import EditorEntity
  13. from editor_python_test_tools.wait_utils import PrefabWaiter
  14. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  15. prefab_test_utils.open_base_tests_level()
  16. # Creates a new Entity at the root level
  17. # Asserts if creation didn't succeed
  18. entity = EditorEntity.create_editor_entity_at((100.0, 100.0, 100.0), name = "TestEntity")
  19. assert entity.id.IsValid(), "Couldn't create entity"
  20. level_container_entity = EditorEntity(entity.get_parent_id())
  21. # Test undo/redo on add entity
  22. azlmbr.legacy.general.undo()
  23. azlmbr.legacy.general.undo()
  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"{level_container_child_entities_count} entities " \
  27. f"found in level after Undo operation, when there should " \
  28. f"be 0 entities"
  29. azlmbr.legacy.general.redo()
  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 Redo operation, when there should " \
  34. f"be 1 entity"
  35. if __name__ == "__main__":
  36. from editor_python_test_tools.utils import Report
  37. Report.start_test(AddEntity_UnderLevelPrefab)