From: Daniel Arndt Date: Tue, 16 May 2023 19:23:56 +0000 (-0300) Subject: Use proper unittest assert methods, finish todos X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F83%2F13383%2F4;p=osm%2FLCM.git Use proper unittest assert methods, finish todos Change-Id: Ibc5cf20a17652547e86e54fc0510c3a0d08f3950 Signed-off-by: Daniel Arndt --- diff --git a/osm_lcm/tests/test_ns_workflows.py b/osm_lcm/tests/test_ns_workflows.py index a460b5e..082b155 100644 --- a/osm_lcm/tests/test_ns_workflows.py +++ b/osm_lcm/tests/test_ns_workflows.py @@ -126,18 +126,21 @@ class TestNsInstantiateWorkflow(asynctest.TestCase): task_queue=LCM_TASK_QUEUE, ) - 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 + self.assertEqual( + [ + 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.assert_lcm_op_states( self.mock_update_lcm_operation_state_tracker.call_args_list, [LcmOperationState.PROCESSING, LcmOperationState.COMPLETED], ) - assert_ns_states( + self.assert_ns_states( self.mock_update_ns_state_tracker.call_args_list, [NsState.INSTANTIATED] ) @@ -155,16 +158,16 @@ class TestNsInstantiateWorkflow(asynctest.TestCase): ], debug_mode=True, ): - # TODO: Check this WorkflowFailureError is caused by a TestException - with self.assertRaises(WorkflowFailureError): + with self.assertRaises(WorkflowFailureError) as e_info: await env.client.execute_workflow( NsInstantiateWorkflow, arg=self.input, id=self.input.nslcmop["nsInstanceId"], task_queue=LCM_TASK_QUEUE, ) + self.assertEqual(e_info.exception.cause.cause.type, "TestException") - assert_lcm_op_states( + self.assert_lcm_op_states( self.mock_update_lcm_operation_state_tracker.call_args_list, [LcmOperationState.PROCESSING, LcmOperationState.FAILED], ) @@ -183,24 +186,26 @@ class TestNsInstantiateWorkflow(asynctest.TestCase): ], debug_mode=True, ): - # TODO: Check this WorkflowFailureError is caused by a TestException - with self.assertRaises(WorkflowFailureError): + with self.assertRaises(WorkflowFailureError) as e_info: await env.client.execute_workflow( NsInstantiateWorkflow, arg=self.input, id=self.input.nslcmop["nsInstanceId"], task_queue=LCM_TASK_QUEUE, ) - assert_ns_states( + self.assertEqual(e_info.exception.cause.cause.type, "TestException") + self.assert_ns_states( self.mock_update_ns_state_tracker.call_args_list, [NsState.INSTANTIATED] ) + def assert_ns_states(self, call_args_list, expected_states): + """Asserts that the NS state was set to each of the expected states (in order).""" + self.assertEqual( + [call.args[0].state for call in call_args_list], expected_states + ) -def assert_ns_states(call_args_list, expected_states): - """Asserts that the NS state was set to each of the expected states (in order).""" - assert [call.args[0].state for call in call_args_list] == expected_states - - -def assert_lcm_op_states(call_args_list, expected_states): - """Asserts that the LCM operation was set to each of the exepcted states (in order).""" - assert [call.args[0].op_state for call in call_args_list] == expected_states + def assert_lcm_op_states(self, call_args_list, expected_states): + """Asserts that the LCM operation was set to each of the exepcted states (in order).""" + self.assertEqual( + [call.args[0].op_state for call in call_args_list], expected_states + )