3
0

DeleteEntity_UnderImmediateInstance.py 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_UnderImmediateInstance():
  7. """
  8. Test description:
  9. - Deletes the "Tire_Entity" of the "First_Car" instance.
  10. - Checks that the "Tire_Entity" is deleted only in "First_Car" instance.
  11. - Checks undo/redo correctness.
  12. - Checks that the deleted "Tire_Entity" should re-appear after focusing on
  13. its owning instance (i.e. "First_Car").
  14. Hierarchy:
  15. - Level <-- focus on this prefab
  16. - First_Car
  17. - Tire_Entity <-- delete this entity as override
  18. - Second_Car
  19. - Tire_Entity <-- this entity is unchanged
  20. """
  21. from editor_python_test_tools.editor_entity_utils import EditorEntity
  22. from editor_python_test_tools.prefab_utils import Prefab
  23. from editor_python_test_tools.wait_utils import PrefabWaiter
  24. import azlmbr.legacy.general as general
  25. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  26. CAR_PREFAB_FILE_NAME = Path(__file__).stem + "_" + "car_prefab"
  27. FIRST_CAR_NAME = "First_Car"
  28. SECOND_CAR_NAME = "Second_Car"
  29. TIRE_ENTITY_NAME = "Tire_Entity"
  30. prefab_test_utils.open_base_tests_level()
  31. # Create a new entity at the root level.
  32. tire_entity = EditorEntity.create_editor_entity_at((100.0, 100.0, 100.0), TIRE_ENTITY_NAME)
  33. assert tire_entity.id.IsValid(), f"Failed to create new entity: {TIRE_ENTITY_NAME}."
  34. # Create a car prefab and the first car instance from the tire entity.
  35. car_prefab_entities = [tire_entity]
  36. car_prefab, car_instance_1 = Prefab.create_prefab(car_prefab_entities, CAR_PREFAB_FILE_NAME, FIRST_CAR_NAME)
  37. assert car_instance_1.is_valid(), f"Failed to instantiate instance: {FIRST_CAR_NAME}."
  38. # Create the second car instance.
  39. car_instance_2 = car_prefab.instantiate(name=SECOND_CAR_NAME)
  40. assert car_instance_2.is_valid(), f"Failed to instantiate instance: {SECOND_CAR_NAME}."
  41. # Delete the tire entity in the first car. Note: Level prefab is currently being focused by default during deletion.
  42. tire_entities_in_car_instance_1 = car_instance_1.get_direct_child_entities()
  43. tire_entity_in_car_instance_1 = tire_entities_in_car_instance_1[0]
  44. tire_entity_in_car_instance_1.delete()
  45. # Wait till prefab propagation finishes before validating deletion.
  46. PrefabWaiter.wait_for_propagation()
  47. # Validate after entity deletion.
  48. prefab_test_utils.validate_count_for_named_editor_entity(TIRE_ENTITY_NAME, 1)
  49. prefab_test_utils.check_entity_children_count(car_instance_1.container_entity.id, 0)
  50. prefab_test_utils.check_entity_children_count(car_instance_2.container_entity.id, 1)
  51. # Validate undo on entity deletion.
  52. general.undo()
  53. PrefabWaiter.wait_for_propagation()
  54. prefab_test_utils.validate_count_for_named_editor_entity(TIRE_ENTITY_NAME, 2)
  55. prefab_test_utils.check_entity_children_count(car_instance_1.container_entity.id, 1)
  56. prefab_test_utils.check_entity_children_count(car_instance_2.container_entity.id, 1)
  57. # Validate redo on entity deletion.
  58. general.redo()
  59. PrefabWaiter.wait_for_propagation()
  60. prefab_test_utils.validate_count_for_named_editor_entity(TIRE_ENTITY_NAME, 1)
  61. prefab_test_utils.check_entity_children_count(car_instance_1.container_entity.id, 0)
  62. prefab_test_utils.check_entity_children_count(car_instance_2.container_entity.id, 1)
  63. # Focus on the first car instance. Deleted tire entity should appear in Prefab Edit Mode.
  64. car_instance_1.container_entity.focus_on_owning_prefab()
  65. PrefabWaiter.wait_for_propagation() # propagate source template changes after focusing on
  66. prefab_test_utils.check_entity_children_count(car_instance_1.container_entity.id, 1)
  67. # Note: This should be 2 because the tire entity inside the second car is not deleted.
  68. prefab_test_utils.validate_count_for_named_editor_entity(TIRE_ENTITY_NAME, 2)
  69. if __name__ == "__main__":
  70. from editor_python_test_tools.utils import Report
  71. Report.start_test(DeleteEntity_UnderImmediateInstance)