from unittest.mock import Mock
import asynctest
+from mock import AsyncMock, patch
from osm_common.dataclasses.temporal_dataclasses import (
GetVnfRecordIdsInput,
GetVnfRecordIdsOutput,
from osm_lcm.temporal.ns_workflows import NsInstantiateWorkflow
+vnfr_ids = [
+ "828d91ee-fa04-43bb-8471-f66ea74597e7",
+ "c4bbeb41-df7e-4daa-863d-c8fd29fac96d",
+]
+
class TestException(Exception):
pass
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)
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,
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]
)
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],
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]
)