DuplicateEntity_WithNestedEntities.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 DuplicateEntity_WithNestedEntities():
  7. """
  8. Test description:
  9. - Creates linear nested entities.
  10. - Duplicates the nested entity structure, and validates.
  11. - Validates Undo/Redo operations on the duplication.
  12. """
  13. import azlmbr.bus as bus
  14. import azlmbr.legacy.general as general
  15. import azlmbr.prefab as prefab
  16. from editor_python_test_tools.editor_entity_utils import EditorEntity
  17. from editor_python_test_tools.wait_utils import PrefabWaiter
  18. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  19. NESTED_ENTITIES_NAME_PREFIX = 'Entity_'
  20. CREATION_POSITION = azlmbr.math.Vector3(100.0, 100.0, 100.0)
  21. NUM_NESTED_ENTITIES_LEVELS = 3
  22. prefab_test_utils.open_base_tests_level()
  23. # Creates new nested entities at the root level
  24. # Asserts if creation didn't succeed
  25. nested_entities_root = prefab_test_utils.create_linear_nested_entities(
  26. NESTED_ENTITIES_NAME_PREFIX, NUM_NESTED_ENTITIES_LEVELS, CREATION_POSITION)
  27. prefab_test_utils.validate_linear_nested_entities(nested_entities_root, NUM_NESTED_ENTITIES_LEVELS,
  28. CREATION_POSITION)
  29. # Duplicates the entity hierarchy and validates
  30. duplicate_outcome = prefab.PrefabPublicRequestBus(bus.Broadcast, 'DuplicateEntitiesInInstance',
  31. [nested_entities_root.id])
  32. assert duplicate_outcome.IsSuccess(), \
  33. f"Failed to duplicate nested entities with root entity {nested_entities_root.get_name()}"
  34. PrefabWaiter.wait_for_propagation()
  35. root_entities = EditorEntity.find_editor_entities(["Entity_0"])
  36. assert len(root_entities) == 2, "Failed to find duplicated root entity"
  37. for root_entity in root_entities:
  38. prefab_test_utils.validate_linear_nested_entities(root_entity, NUM_NESTED_ENTITIES_LEVELS, CREATION_POSITION)
  39. # Test undo/redo on nested hierarchy duplication
  40. general.undo()
  41. PrefabWaiter.wait_for_propagation()
  42. root_entities = EditorEntity.find_editor_entities(["Entity_0"])
  43. assert len(root_entities) == 1, f"Undo Failed: Found {len(root_entities)}, when 1 should be present"
  44. general.redo()
  45. PrefabWaiter.wait_for_propagation()
  46. root_entities = EditorEntity.find_editor_entities(["Entity_0"])
  47. assert len(root_entities) == 2, f"Undo Failed: Found {len(root_entities)}, when 1 should be present"
  48. for root_entity in root_entities:
  49. prefab_test_utils.validate_linear_nested_entities(root_entity, NUM_NESTED_ENTITIES_LEVELS, CREATION_POSITION)
  50. if __name__ == "__main__":
  51. from editor_python_test_tools.utils import Report
  52. Report.start_test(DuplicateEntity_WithNestedEntities)