From b98b240a4001a7928d89facc9303aa9e20453568 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Thu, 20 Jan 2022 18:16:51 -0800 Subject: [PATCH 1/5] Entity Reference P1 initial tests Signed-off-by: Scott Murray --- .../Atom/atom_utils/atom_constants.py | 2 + ...omEditorComponents_EntityReferenceAdded.py | 101 ++++++++++++++++-- 2 files changed, 92 insertions(+), 11 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/Atom/atom_utils/atom_constants.py b/AutomatedTesting/Gem/PythonTests/Atom/atom_utils/atom_constants.py index e6d6ac7fb1..c3404c1e94 100644 --- a/AutomatedTesting/Gem/PythonTests/Atom/atom_utils/atom_constants.py +++ b/AutomatedTesting/Gem/PythonTests/Atom/atom_utils/atom_constants.py @@ -195,11 +195,13 @@ class AtomComponentProperties: def entity_reference(property: str = 'name') -> str: """ Entity Reference component properties. + - 'EntityIdReferences' component container of entityId references. Initially empty. :param property: From the last element of the property tree path. Default 'name' for component name string. :return: Full property path OR component name if no property specified. """ properties = { 'name': 'Entity Reference', + 'EntityIdReferences': 'Controller|Configuration|EntityIdReferences', } return properties[property] diff --git a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py index dddcca64fa..9dc4869f66 100644 --- a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py +++ b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py @@ -9,37 +9,55 @@ SPDX-License-Identifier: Apache-2.0 OR MIT class Tests: creation_undo = ( "UNDO Entity creation success", - "UNDO Entity creation failed") + "P0: UNDO Entity creation failed") creation_redo = ( "REDO Entity creation success", - "REDO Entity creation failed") + "P0: REDO Entity creation failed") entity_reference_creation = ( "Entity Reference Entity successfully created", - "Entity Reference Entity failed to be created") + "P0: Entity Reference Entity failed to be created") entity_reference_component = ( "Entity has an Entity Reference component", - "Entity failed to find Entity Reference component") + "P0: Entity failed to find Entity Reference component") enter_game_mode = ( "Entered game mode", - "Failed to enter game mode") + "P0: Failed to enter game mode") exit_game_mode = ( "Exited game mode", - "Couldn't exit game mode") + "P0: Couldn't exit game mode") is_visible = ( "Entity is visible", - "Entity was not visible") + "P0: Entity was not visible") is_hidden = ( "Entity is hidden", - "Entity was not hidden") + "P0: Entity was not hidden") entity_deleted = ( "Entity deleted", - "Entity was not deleted") + "P0: Entity was not deleted") deletion_undo = ( "UNDO deletion success", - "UNDO deletion failed") + "P0: UNDO deletion failed") deletion_redo = ( "REDO deletion success", - "REDO deletion failed") + "P0: REDO deletion failed") + entity_id_references_is_container = ( + "EntityIdReferences is a container property", + "P1: EntityIdReferences is NOT a container property") + container_append = ( + "EntityIdReferences append succeeded", + "P1: EntityIdReferences append did not succeed") + container_add = ( + "EntityIdReferences add succeeded", + "P1: EntityIdReferences add did not succeed") + container_update = ( + "EntityIdReferences update succeeded", + "P1: EntityIdReferences update did not succeed") + container_remove = ( + "EntityIdReferences remove succeeded", + "P1: EntityIdReferences remove did not succeed") + container_reset = ( + "EntityIdReferences reset succeeded", + "P1: EntityIdReferences reset did not succeed") def AtomEditorComponents_EntityReference_AddedToEntity(): @@ -119,6 +137,67 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): general.idle_wait_frames(1) Report.result(Tests.creation_redo, entity_reference_entity.exists()) + # Entities for EntityIdReferences tests + test_1 = EditorEntity.create_editor_entity('test_1') + test_2 = EditorEntity.create_editor_entity('test_2') + test_3 = EditorEntity.create_editor_entity('test_3') + + # is container property + Report.result( + Tests.entity_id_references_is_container, + entity_reference_component.is_property_container( + AtomComponentProperties.entity_reference('EntityIdReferences'))) + + # Append entity reference to container + entity_reference_component.append_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), + test_1.id) + Report.result( + Tests.container_append, + entity_reference_component.get_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), 0) == test_1.id) + + # Add entity reference to container + entity_reference_component.add_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), + 1, test_1.id) + Report.result( + Tests.container_add, + entity_reference_component.get_container_count( + AtomComponentProperties.entity_reference('EntityIdReferences')) == 2 + ) + + # Update entity reference + entity_reference_component.update_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), + 1, test_2.id) + Report.result( + Tests.container_update, + entity_reference_component.get_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), 1) == test_2.id) + + # Remove entity reference + entity_reference_component.append_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), + test_3.id) + count_before = entity_reference_component.get_container_count( + AtomComponentProperties.entity_reference('EntityIdReferences')) + entity_reference_component.remove_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), + 1) + count_after = entity_reference_component.get_container_count( + AtomComponentProperties.entity_reference('EntityIdReferences')) + remove_count = (count_before == 3) and (count_after == 2) + Report.result( + Tests.container_remove, + ((count_before == 3) and (count_after == 2) and + (entity_reference_component.get_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), 1) == test_3.id)) + ) + + # Reset + entity_reference_component.reset_container(AtomComponentProperties.entity_reference('EntityIdReferences')) + Report.result( + Tests.container_reset, + entity_reference_component.get_container_count( + AtomComponentProperties.entity_reference('EntityIdReferences')) == 0 + ) + # 5. Enter/Exit game mode. TestHelper.enter_game_mode(Tests.enter_game_mode) general.idle_wait_frames(1) From f93a22cdcc0853df6ebfc77b9c912d438be799b3 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Fri, 21 Jan 2022 11:11:39 -0800 Subject: [PATCH 2/5] EntityReference P1 case udpates Signed-off-by: Scott Murray --- ...omEditorComponents_EntityReferenceAdded.py | 71 +++++++++++++------ 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py index 9dc4869f66..464f2a1892 100644 --- a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py +++ b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py @@ -58,6 +58,9 @@ class Tests: container_reset = ( "EntityIdReferences reset succeeded", "P1: EntityIdReferences reset did not succeed") + entity_reference_component_removed = ( + "Entity Reference component removed from entity", + "P1: Entity Reference component NOT removed from entity") def AtomEditorComponents_EntityReference_AddedToEntity(): @@ -78,13 +81,21 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): 2) Add Entity Reference component to Entity Reference entity. 3) UNDO the entity creation and component addition. 4) REDO the entity creation and component addition. - 5) Enter/Exit game mode. - 6) Test IsHidden. - 7) Test IsVisible. - 8) Delete Entity Reference entity. - 9) UNDO deletion. - 10) REDO deletion. - 11) Look for errors. + 5) 'EntityIdReferences' is a container property + 6) Append item to 'EntityIdReferences' + 7) Add item to 'EntityIdReferences' + 8) Update item in 'EntityIdReferences' + 9) Remove item from 'EntityIdReferences' + 10) Rest the container property then put one entity reference back for further tests + 11) Remove component + 12) Undo component remove + 13) Enter/Exit game mode. + 14) Test IsHidden. + 15) Test IsVisible. + 16) Delete Entity Reference entity. + 17) UNDO deletion. + 18) REDO deletion. + 19) Look for errors. :return: None """ @@ -142,13 +153,13 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): test_2 = EditorEntity.create_editor_entity('test_2') test_3 = EditorEntity.create_editor_entity('test_3') - # is container property + # 5. 'EntityIdReferences' is a container property Report.result( Tests.entity_id_references_is_container, entity_reference_component.is_property_container( AtomComponentProperties.entity_reference('EntityIdReferences'))) - # Append entity reference to container + # 6. Append item to 'EntityIdReferences' entity_reference_component.append_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), test_1.id) Report.result( @@ -156,7 +167,7 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): entity_reference_component.get_container_item( AtomComponentProperties.entity_reference('EntityIdReferences'), 0) == test_1.id) - # Add entity reference to container + # 7. Add item to 'EntityIdReferences' entity_reference_component.add_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), 1, test_1.id) Report.result( @@ -165,7 +176,7 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): AtomComponentProperties.entity_reference('EntityIdReferences')) == 2 ) - # Update entity reference + # 8. Update item in 'EntityIdReferences' entity_reference_component.update_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), 1, test_2.id) Report.result( @@ -173,7 +184,7 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): entity_reference_component.get_container_item( AtomComponentProperties.entity_reference('EntityIdReferences'), 1) == test_2.id) - # Remove entity reference + # 9. Remove item from 'EntityIdReferences' entity_reference_component.append_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), test_3.id) count_before = entity_reference_component.get_container_count( @@ -190,41 +201,57 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): AtomComponentProperties.entity_reference('EntityIdReferences'), 1) == test_3.id)) ) - # Reset + # 10. Rest the container property then put one entity reference back for further tests entity_reference_component.reset_container(AtomComponentProperties.entity_reference('EntityIdReferences')) + general.idle_wait_frames(1) Report.result( Tests.container_reset, entity_reference_component.get_container_count( - AtomComponentProperties.entity_reference('EntityIdReferences')) == 0 - ) + AtomComponentProperties.entity_reference('EntityIdReferences')) == 0) + entity_reference_component.append_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), + test_1.id) - # 5. Enter/Exit game mode. + # 11. Remove component + entity_reference_entity.remove_component(AtomComponentProperties.entity_reference()) + general.idle_wait_frames(1) + Report.result(Tests.entity_reference_component_removed, not entity_reference_entity.has_component( + AtomComponentProperties.entity_reference())) + + # 12. Undo component remove + general.undo() + general.idle_wait_frames(1) + Report.result(Tests.entity_reference_component, entity_reference_entity.has_component( + AtomComponentProperties.entity_reference())) + + # 13. Enter/Exit game mode. TestHelper.enter_game_mode(Tests.enter_game_mode) general.idle_wait_frames(1) TestHelper.exit_game_mode(Tests.exit_game_mode) - # 6. Test IsHidden. + # 14. Test IsHidden. entity_reference_entity.set_visibility_state(False) Report.result(Tests.is_hidden, entity_reference_entity.is_hidden() is True) - # 7. Test IsVisible. + # 15. Test IsVisible. entity_reference_entity.set_visibility_state(True) general.idle_wait_frames(1) Report.result(Tests.is_visible, entity_reference_entity.is_visible() is True) - # 8. Delete Entity Reference entity. + # 16. Delete Entity Reference entity. entity_reference_entity.delete() Report.result(Tests.entity_deleted, not entity_reference_entity.exists()) - # 9. UNDO deletion. + # 17. UNDO deletion. general.undo() + general.idle_wait_frames(1) Report.result(Tests.deletion_undo, entity_reference_entity.exists()) - # 10. REDO deletion. + # 18. REDO deletion. general.redo() + general.idle_wait_frames(1) Report.result(Tests.deletion_redo, not entity_reference_entity.exists()) - # 11. Look for errors and asserts. + # 19. Look for errors and asserts. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0) for error_info in error_tracer.errors: Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}") From 529c342ecac86479b08ce6b14cbb10ff46d2ba43 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Fri, 21 Jan 2022 14:53:11 -0800 Subject: [PATCH 3/5] fixing remove_components Signed-off-by: Scott Murray --- .../editor_python_test_tools/editor_entity_utils.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py index c3398406ab..f19bf540a9 100644 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py +++ b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py @@ -473,12 +473,11 @@ class EditorEntity: :param component_names: List of component names to remove :return: None """ - type_ids = EditorComponent.get_type_ids(component_names, EditorEntityType.GAME) - for type_id in type_ids: - remove_outcome = editor.EditorComponentAPIBus(bus.Broadcast, "RemoveComponents", self.id, [type_id]) - assert ( - remove_outcome.IsSuccess() - ), f"Failure: could not remove component from '{self.get_name()}'" + component_ids = [component.id for component in self.get_components_of_type(component_names)] + remove_success = editor.EditorComponentAPIBus(bus.Broadcast, "RemoveComponents", component_ids) + assert ( + remove_success + ), f"Failure: could not remove component from '{self.get_name()}'" def get_components_of_type(self, component_names: list) -> List[EditorComponent]: """ From 44cbc7659fd172d7e4f98ad9c8dda54f35ccc761 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Fri, 21 Jan 2022 15:00:36 -0800 Subject: [PATCH 4/5] removing unused line Signed-off-by: Scott Murray --- .../tests/hydra_AtomEditorComponents_EntityReferenceAdded.py | 1 - 1 file changed, 1 deletion(-) diff --git a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py index 464f2a1892..7f15702199 100644 --- a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py +++ b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py @@ -193,7 +193,6 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): 1) count_after = entity_reference_component.get_container_count( AtomComponentProperties.entity_reference('EntityIdReferences')) - remove_count = (count_before == 3) and (count_after == 2) Report.result( Tests.container_remove, ((count_before == 3) and (count_after == 2) and From 6481b147fc8136a889fefc4c60838c2f6a6d42f5 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Fri, 21 Jan 2022 16:03:39 -0800 Subject: [PATCH 5/5] style and other fixes Signed-off-by: Scott Murray --- ...omEditorComponents_EntityReferenceAdded.py | 38 +++++++++---------- .../editor_entity_utils.py | 2 +- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py index 7f15702199..66efab9e01 100644 --- a/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py +++ b/AutomatedTesting/Gem/PythonTests/Atom/tests/hydra_AtomEditorComponents_EntityReferenceAdded.py @@ -86,9 +86,9 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): 7) Add item to 'EntityIdReferences' 8) Update item in 'EntityIdReferences' 9) Remove item from 'EntityIdReferences' - 10) Rest the container property then put one entity reference back for further tests + 10) Reset the container property then put one entity reference back for further tests 11) Remove component - 12) Undo component remove + 12) UNDO component remove 13) Enter/Exit game mode. 14) Test IsHidden. 15) Test IsVisible. @@ -160,55 +160,53 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): AtomComponentProperties.entity_reference('EntityIdReferences'))) # 6. Append item to 'EntityIdReferences' - entity_reference_component.append_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), - test_1.id) + entity_reference_component.append_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), test_1.id) Report.result( Tests.container_append, entity_reference_component.get_container_item( AtomComponentProperties.entity_reference('EntityIdReferences'), 0) == test_1.id) # 7. Add item to 'EntityIdReferences' - entity_reference_component.add_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), - 1, test_1.id) + entity_reference_component.add_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), 1, test_1.id) Report.result( Tests.container_add, entity_reference_component.get_container_count( - AtomComponentProperties.entity_reference('EntityIdReferences')) == 2 - ) + AtomComponentProperties.entity_reference('EntityIdReferences')) == 2) # 8. Update item in 'EntityIdReferences' - entity_reference_component.update_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), - 1, test_2.id) + entity_reference_component.update_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), 1, test_2.id) Report.result( Tests.container_update, entity_reference_component.get_container_item( AtomComponentProperties.entity_reference('EntityIdReferences'), 1) == test_2.id) # 9. Remove item from 'EntityIdReferences' - entity_reference_component.append_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), - test_3.id) + entity_reference_component.append_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), test_3.id) count_before = entity_reference_component.get_container_count( AtomComponentProperties.entity_reference('EntityIdReferences')) - entity_reference_component.remove_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), - 1) + entity_reference_component.remove_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), 1) count_after = entity_reference_component.get_container_count( AtomComponentProperties.entity_reference('EntityIdReferences')) Report.result( Tests.container_remove, ((count_before == 3) and (count_after == 2) and (entity_reference_component.get_container_item( - AtomComponentProperties.entity_reference('EntityIdReferences'), 1) == test_3.id)) - ) + AtomComponentProperties.entity_reference('EntityIdReferences'), 1) == test_3.id))) - # 10. Rest the container property then put one entity reference back for further tests + # 10. Reset the container property then put one entity reference back for further tests entity_reference_component.reset_container(AtomComponentProperties.entity_reference('EntityIdReferences')) general.idle_wait_frames(1) Report.result( Tests.container_reset, entity_reference_component.get_container_count( AtomComponentProperties.entity_reference('EntityIdReferences')) == 0) - entity_reference_component.append_container_item(AtomComponentProperties.entity_reference('EntityIdReferences'), - test_1.id) + entity_reference_component.append_container_item( + AtomComponentProperties.entity_reference('EntityIdReferences'), test_1.id) # 11. Remove component entity_reference_entity.remove_component(AtomComponentProperties.entity_reference()) @@ -216,7 +214,7 @@ def AtomEditorComponents_EntityReference_AddedToEntity(): Report.result(Tests.entity_reference_component_removed, not entity_reference_entity.has_component( AtomComponentProperties.entity_reference())) - # 12. Undo component remove + # 12. UNDO component remove general.undo() general.idle_wait_frames(1) Report.result(Tests.entity_reference_component, entity_reference_entity.has_component( diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py index f19bf540a9..d8d4a77a65 100644 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py +++ b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/editor_entity_utils.py @@ -477,7 +477,7 @@ class EditorEntity: remove_success = editor.EditorComponentAPIBus(bus.Broadcast, "RemoveComponents", component_ids) assert ( remove_success - ), f"Failure: could not remove component from '{self.get_name()}'" + ), f"Failure: could not remove component from entity '{self.get_name()}'" def get_components_of_type(self, component_names: list) -> List[EditorComponent]: """