Test for child workflow in instantiate NS workflow 59/13259/3
authorDaniel Arndt <daniel.arndt@canonical.com>
Fri, 21 Apr 2023 19:17:36 +0000 (16:17 -0300)
committerbeierlm <mark.beierl@canonical.com>
Tue, 25 Apr 2023 09:37:20 +0000 (11:37 +0200)
Change-Id: Ifec8cdc0fc648784720d409d7f99af8d04a0307a
Signed-off-by: Daniel Arndt <daniel.arndt@canonical.com>
osm_lcm/tests/test_ns_workflows.py

index 9885a16..a460b5e 100644 (file)
@@ -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]
         )