AddEntity_UnderChildEntityOfPrefab.py 3.0 KB

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