From f941a54efd41b1d1e4752fb89d94714b19fd145c Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 21 Apr 2023 16:17:36 -0300 Subject: [PATCH] Test for child workflow in instantiate NS workflow Change-Id: Ifec8cdc0fc648784720d409d7f99af8d04a0307a Signed-off-by: Daniel Arndt --- osm_lcm/tests/test_ns_workflows.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/osm_lcm/tests/test_ns_workflows.py b/osm_lcm/tests/test_ns_workflows.py index 9885a16..a460b5e 100644 --- a/osm_lcm/tests/test_ns_workflows.py +++ b/osm_lcm/tests/test_ns_workflows.py @@ -18,6 +18,7 @@ from unittest.mock import Mock import asynctest +from mock import AsyncMock, patch from osm_common.dataclasses.temporal_dataclasses import ( GetVnfRecordIdsInput, GetVnfRecordIdsOutput, @@ -44,6 +45,11 @@ from temporalio.worker import Worker from osm_lcm.temporal.ns_workflows import NsInstantiateWorkflow +vnfr_ids = [ + "828d91ee-fa04-43bb-8471-f66ea74597e7", + "c4bbeb41-df7e-4daa-863d-c8fd29fac96d", +] + class TestException(Exception): pass @@ -58,12 +64,7 @@ async def mock_create_model(create_model_input: ModelInfo) -> None: async def mock_get_vnf_record_ids( get_vnf_record_ids_input: GetVnfRecordIdsInput, ) -> None: - return GetVnfRecordIdsOutput( - vnfr_ids=[ - "828d91ee-fa04-43bb-8471-f66ea74597e7", - "c4bbeb41-df7e-4daa-863d-c8fd29fac96d", - ] - ) + return GetVnfRecordIdsOutput(vnfr_ids=vnfr_ids) @activity.defn(name=ACTIVITY_CREATE_MODEL) @@ -103,7 +104,8 @@ class TestNsInstantiateWorkflow(asynctest.TestCase): self.mock_update_lcm_operation_state_tracker = Mock() self.mock_update_ns_state_tracker = Mock() - async def test_instantiate_workflow(self): + @patch("temporalio.workflow.execute_child_workflow") + async def test_instantiate_workflow(self, mock_execute_child_workflow: AsyncMock): async with self.env as env: async with Worker( env.client, @@ -124,11 +126,17 @@ class TestNsInstantiateWorkflow(asynctest.TestCase): task_queue=LCM_TASK_QUEUE, ) - assert self.mock_update_lcm_operation_state_tracker.call_count == 2 + assert [ + call.kwargs["workflow"] == WORKFLOW_VNF_INSTANTIATE + and call.kwargs["arg"].vnfr_uuid + for call in mock_execute_child_workflow.call_args_list + ] == vnfr_ids + assert_lcm_op_states( self.mock_update_lcm_operation_state_tracker.call_args_list, [LcmOperationState.PROCESSING, LcmOperationState.COMPLETED], ) + assert_ns_states( self.mock_update_ns_state_tracker.call_args_list, [NsState.INSTANTIATED] ) @@ -155,7 +163,7 @@ class TestNsInstantiateWorkflow(asynctest.TestCase): id=self.input.nslcmop["nsInstanceId"], task_queue=LCM_TASK_QUEUE, ) - assert self.mock_update_lcm_operation_state_tracker.call_count == 2 + assert_lcm_op_states( self.mock_update_lcm_operation_state_tracker.call_args_list, [LcmOperationState.PROCESSING, LcmOperationState.FAILED], @@ -183,7 +191,6 @@ class TestNsInstantiateWorkflow(asynctest.TestCase): id=self.input.nslcmop["nsInstanceId"], task_queue=LCM_TASK_QUEUE, ) - assert self.mock_update_ns_state_tracker.call_count == 1 assert_ns_states( self.mock_update_ns_state_tracker.call_args_list, [NsState.INSTANTIATED] ) -- 2.25.1