From 5dca475336148f15a636f2e17ee4eef07118caa8 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 16 May 2023 16:23:56 -0300 Subject: [PATCH] Use proper unittest assert methods, finish todos Change-Id: Ibc5cf20a17652547e86e54fc0510c3a0d08f3950 Signed-off-by: Daniel Arndt --- osm_lcm/tests/test_ns_workflows.py | 47 +++++++++++++++++------------- 1 file changed, 26 insertions(+), 21 deletions(-) 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 + ) -- 2.25.1