Browse Source

Adding new add_entity tests

Signed-off-by: dm-amzn <[email protected]>
dm-amzn 3 năm trước cách đây
mục cha
commit
8b3fe48fd1

+ 3 - 0
AutomatedTesting/Gem/PythonTests/Prefab/TestSuite_Main.py

@@ -63,6 +63,9 @@ class TestAutomationNoAutoTestMode(EditorTestSuite):
     class test_DeletePrefab_ContainingNestedEntitiesAndNestedPrefabs(EditorSharedTest):
         from .tests.delete_prefab import DeletePrefab_ContainingNestedEntitiesAndNestedPrefabs as test_module
 
+    class test_DeletePrefab_DuplicatedPrefabInstance(EditorSharedTest):
+        from .tests.delete_prefab import DeletePrefab_DuplicatedPrefabInstance as test_module
+
     class test_DuplicatePrefab_ContainingASingleEntity(EditorSharedTest):
         from .tests.duplicate_prefab import DuplicatePrefab_ContainingASingleEntity as test_module
 

+ 13 - 0
AutomatedTesting/Gem/PythonTests/Prefab/TestSuite_Periodic.py

@@ -18,6 +18,18 @@ class TestAutomationNoAutoTestMode(EditorTestSuite):
     # Enable only -BatchMode for these tests. Some tests cannot run in -autotest_mode due to UI interactions
     global_extra_cmdline_args = ["-BatchMode"]
 
+    class test_AddEntity_UnderLevelPrefab(EditorSharedTest):
+        from .tests.add_entity import AddEntity_UnderLevelPrefab as test_module
+
+    class test_AddEntity_UnderAnotherEntity(EditorSharedTest):
+       from .tests.add_entity import AddEntity_UnderAnotherEntity as test_module
+
+    class test_AddEntity_UnderContainerEntityOfPrefab(EditorSharedTest):
+        from .tests.add_entity import AddEntity_UnderContainerEntityOfPrefab as test_module
+
+    class test_AddEntity_UnderChildEntityOfPrefab(EditorSharedTest):
+        from .tests.add_entity import AddEntity_UnderChildEntityOfPrefab as test_module
+
     class test_DeletePrefab_DuplicatedPrefabInstance(EditorSharedTest):
         from .tests.delete_prefab import DeletePrefab_DuplicatedPrefabInstance as test_module
 
@@ -29,3 +41,4 @@ class TestAutomationNoAutoTestMode(EditorTestSuite):
 
     class test_DeleteEntity_UnderNestedEntityHierarchy(EditorSharedTest):
         from .tests.delete_entity import DeleteEntity_UnderNestedEntityHierarchy as test_module
+

+ 53 - 0
AutomatedTesting/Gem/PythonTests/Prefab/tests/add_entity/AddEntity_UnderAnotherEntity.py

@@ -0,0 +1,53 @@
+"""
+Copyright (c) Contributors to the Open 3D Engine Project.
+For complete copyright and license terms please see the LICENSE at the root of this distribution.
+
+SPDX-License-Identifier: Apache-2.0 OR MIT
+"""
+
+def AddEntity_UnderAnotherEntity():
+    """
+    Test description:
+    - Creates an entity at the root level
+    - Creates a child entity of the root entity
+    - Verifies Undo/Redo.
+    """
+
+    from editor_python_test_tools.editor_entity_utils import EditorEntity
+    from editor_python_test_tools.wait_utils import PrefabWaiter
+    import Prefab.tests.PrefabTestUtils as prefab_test_utils
+
+    prefab_test_utils.open_base_tests_level()
+
+    # Creates a new Entity at the root level
+    # Asserts if creation didn't succeed
+    parent_entity = EditorEntity.create_editor_entity_at((100.0, 100.0, 100.0))
+    assert parent_entity.id.IsValid(), "Couldn't create parent entity"
+
+
+    # Creates a new child Entity
+    # Asserts if creation didn't succeed
+    child_entity = EditorEntity.create_editor_entity(parent_id=parent_entity.id)
+    assert child_entity.id.IsValid(), "Couldn't create child entity"
+    assert parent_entity.get_children_ids()[0] == child_entity.id, "Couldn't create child entity of parent entity"
+
+    PrefabWaiter.wait_for_propagation()
+
+    # Test undo/redo on add child Entity
+    azlmbr.legacy.general.undo()
+    PrefabWaiter.wait_for_propagation()
+    child_entities_count = len(parent_entity.get_children_ids())
+    assert child_entities_count == 0, f"{child_entities_count} child entities " \
+                                                      f"found in level after Undo operation, when there should " \
+                                                      f"be 0 child entities"
+    azlmbr.legacy.general.redo()
+    PrefabWaiter.wait_for_propagation()
+    child_entities_count = len(parent_entity.get_children_ids())
+    assert child_entities_count == 1, f"{child_entities_count} entities " \
+                                                      f"found in level after Redo operation, when there should " \
+                                                      f"be 1 child entity"
+
+
+if __name__ == "__main__":
+    from editor_python_test_tools.utils import Report
+    Report.start_test(AddEntity_UnderAnotherEntity)

+ 64 - 0
AutomatedTesting/Gem/PythonTests/Prefab/tests/add_entity/AddEntity_UnderChildEntityOfPrefab.py

@@ -0,0 +1,64 @@
+"""
+Copyright (c) Contributors to the Open 3D Engine Project.
+For complete copyright and license terms please see the LICENSE at the root of this distribution.
+
+SPDX-License-Identifier: Apache-2.0 OR MIT
+"""
+
+def AddEntity_UnderChildEntityOfPrefab():
+    """
+    Test description:
+    - Creates an entity.
+    - Creates a prefab out of the above entity.
+    - Focuses on the created prefab and adds a new child entity.
+    - Creates a child entity under the above child entity of the created prefab.
+    - Checks that the entity is correctly added.
+    """
+
+    from editor_python_test_tools.editor_entity_utils import EditorEntity
+    from editor_python_test_tools.prefab_utils import Prefab
+    from editor_python_test_tools.wait_utils import PrefabWaiter
+
+    import Prefab.tests.PrefabTestUtils as prefab_test_utils
+
+    prefab_test_utils.open_base_tests_level()
+
+    from pathlib import Path
+    PREFAB_FILE_NAME = Path(__file__).stem + '_' + 'some_prefab'
+
+    # Creates a new entity at the root level
+    entity = EditorEntity.create_editor_entity()
+    assert entity.id.IsValid(), "Couldn't create entity."
+
+    # Creates a new Prefab, gets focus, and adds a child entity
+    # Asserts if prefab creation doesn't succeed
+    child_prefab, child_instance = Prefab.create_prefab([entity], PREFAB_FILE_NAME)
+    child_entity_ids_inside_prefab_instance = child_instance.get_direct_child_entities()
+    assert len(child_entity_ids_inside_prefab_instance) == 1, f"{len(child_entity_ids_inside_prefab_instance)} entities found inside prefab" \
+                                              f" when there should have been just 1 entity"
+
+    child_entity_inside_prefab = child_entity_ids_inside_prefab_instance[0]
+    child_entity_inside_prefab.focus_on_owning_prefab()
+
+    second_child_entity = child_entity_inside_prefab.create_editor_entity(parent_id=child_entity_inside_prefab.id)
+
+    # Wait till prefab propagation finishes before validating add second child entity
+    PrefabWaiter.wait_for_propagation()
+    assert second_child_entity.id.IsValid(), "Couldn't add second child entity"
+
+    # Test undo/redo on add second child entity
+    azlmbr.legacy.general.undo()
+    PrefabWaiter.wait_for_propagation()
+    child_entity_ids_inside_prefab = child_entity_inside_prefab.get_children()
+    assert len(child_entity_ids_inside_prefab) == 0, f"{len(child_entity_ids_inside_prefab)} child entities found inside prefab" \
+                                              f" after Undo operation, when there should have been 0 child entities"
+    azlmbr.legacy.general.redo()
+    PrefabWaiter.wait_for_propagation()
+    child_entity_ids_inside_prefab = child_entity_inside_prefab.get_children()
+    assert len(child_entity_ids_inside_prefab) == 1, f"{len(child_entity_ids_inside_prefab)} child entities found inside prefab" \
+                                              f" after Redo operation, when there should have been 1 child entity"
+
+
+if __name__ == "__main__":
+    from editor_python_test_tools.utils import Report
+    Report.start_test(AddEntity_UnderChildEntityOfPrefab)

+ 65 - 0
AutomatedTesting/Gem/PythonTests/Prefab/tests/add_entity/AddEntity_UnderContainerEntityOfPrefab.py

@@ -0,0 +1,65 @@
+"""
+Copyright (c) Contributors to the Open 3D Engine Project.
+For complete copyright and license terms please see the LICENSE at the root of this distribution.
+
+SPDX-License-Identifier: Apache-2.0 OR MIT
+"""
+
+def AddEntity_UnderContainerEntityOfPrefab():
+    """
+    Test description:
+    - Creates an entity.
+    - Creates a prefab out of the above entity.
+    - Focuses on the created prefab.
+    - Creates a second entity under the created prefab.
+    - Checks that the entity is correctly added.
+    """
+
+    from editor_python_test_tools.editor_entity_utils import EditorEntity
+    from editor_python_test_tools.prefab_utils import Prefab
+    from editor_python_test_tools.wait_utils import PrefabWaiter
+
+    import Prefab.tests.PrefabTestUtils as prefab_test_utils
+
+    prefab_test_utils.open_base_tests_level()
+
+    from pathlib import Path
+    PREFAB_FILE_NAME = Path(__file__).stem + '_' + 'some_prefab'
+
+    # Creates a new entity at the root level
+    entity = EditorEntity.create_editor_entity()
+    assert entity.id.IsValid(), "Couldn't create entity."
+
+    # Creates a new Prefab, gets focus, and adds a child entity
+    # Asserts if prefab creation doesn't succeed
+    child_prefab, child_instance = Prefab.create_prefab([entity], PREFAB_FILE_NAME)
+    child_entity_ids_inside_prefab_instance = child_instance.get_direct_child_entities()
+    assert len(
+        child_entity_ids_inside_prefab_instance) == 1, f"{len(child_entity_ids_inside_prefab_instance)} entities found inside prefab" \
+                                                       f" when there should have been just 1 entity"
+
+    child_entity_inside_prefab = child_entity_ids_inside_prefab_instance[0]
+    child_entity_inside_prefab.focus_on_owning_prefab()
+
+    second_entity = child_entity_inside_prefab.create_editor_entity(parent_id=child_instance.container_entity.id)
+
+    # Wait till prefab propagation finishes before validating add second child entity
+    PrefabWaiter.wait_for_propagation()
+    assert second_entity.id.IsValid(), "Couldn't add second child entity"
+
+    # Test undo/redo on add second entity
+    azlmbr.legacy.general.undo()
+    PrefabWaiter.wait_for_propagation()
+    child_entity_ids_inside_prefab = child_instance.container_entity.get_children()
+    assert len(child_entity_ids_inside_prefab) == 1, f"{len(child_entity_ids_inside_prefab)} entities found inside prefab" \
+                                              f" after Undo operation, when there should have been 1 entity"
+    azlmbr.legacy.general.redo()
+    PrefabWaiter.wait_for_propagation()
+    child_entity_ids_inside_prefab = child_instance.container_entity.get_children()
+    assert len(child_entity_ids_inside_prefab) == 2, f"{len(child_entity_ids_inside_prefab)} entities found inside prefab" \
+                                              f" after Redo operation, when there should have been 2 entities"
+
+
+if __name__ == "__main__":
+    from editor_python_test_tools.utils import Report
+    Report.start_test(AddEntity_UnderContainerEntityOfPrefab)

+ 47 - 0
AutomatedTesting/Gem/PythonTests/Prefab/tests/add_entity/AddEntity_UnderLevelPrefab.py

@@ -0,0 +1,47 @@
+"""
+Copyright (c) Contributors to the Open 3D Engine Project.
+For complete copyright and license terms please see the LICENSE at the root of this distribution.
+
+SPDX-License-Identifier: Apache-2.0 OR MIT
+"""
+
+def AddEntity_UnderLevelPrefab():
+    """
+    Test description:
+    - Creates an entity under level container.
+    - Verifies Undo/Redo.
+    """
+
+    from editor_python_test_tools.editor_entity_utils import EditorEntity
+    from editor_python_test_tools.wait_utils import PrefabWaiter
+    import Prefab.tests.PrefabTestUtils as prefab_test_utils
+
+    prefab_test_utils.open_base_tests_level()
+
+    # Creates a new Entity at the root level
+    # Asserts if creation didn't succeed
+    entity = EditorEntity.create_editor_entity_at((100.0, 100.0, 100.0), name = "TestEntity")
+    assert entity.id.IsValid(), "Couldn't create entity"
+
+    level_container_entity = EditorEntity(entity.get_parent_id())
+
+    # Test undo/redo on add entity
+    azlmbr.legacy.general.undo()
+    azlmbr.legacy.general.undo()
+    PrefabWaiter.wait_for_propagation()
+    level_container_child_entities_count = len(level_container_entity.get_children_ids())
+    assert level_container_child_entities_count == 0, f"{level_container_child_entities_count} entities " \
+                                                      f"found in level after Undo operation, when there should " \
+                                                      f"be 0 entities"
+
+    azlmbr.legacy.general.redo()
+    PrefabWaiter.wait_for_propagation()
+    level_container_child_entities_count = len(level_container_entity.get_children_ids())
+    assert level_container_child_entities_count == 1, f"{level_container_child_entities_count} entities " \
+                                                      f"found in level after Redo operation, when there should " \
+                                                      f"be 1 entity"
+
+
+if __name__ == "__main__":
+    from editor_python_test_tools.utils import Report
+    Report.start_test(AddEntity_UnderLevelPrefab)