From 900a1aa78ef37404a38fbd2f140007aeaf2446b0 Mon Sep 17 00:00:00 2001 From: Manpreet Kaur Date: Thu, 25 Mar 2021 18:02:53 +0530 Subject: [PATCH] Fix failing UT in TestListVnfLcmOp The unit test 'tackerclient.tests.unit.osc.v1.test_vnflcm_op_occs. TestListVnfLcmOp.test_take_action_with_filter' is failing with below error message, DEBUG: TypeError: Object of type 'FormatComplexDataColumn' is not JSON serializable Background: In class TestListVnfLcmOp definition, "create_vnflcm_op_occs" function is called and list of fake vnflcm op occs dictionary is store in vnflcm_op_occs_obj. Now this dictionary is used in two unit test cases "test_take_action" and "test_take_action_with_filter". In order to evaluate test results, in "test_take_action" test case, "get_vnflcm_op_occ_data" function is called using "vnflcm_op_occs_obj" which appends the data in dictionary. Later this dictionary "vnflcm_op_occs_obj" is again used in "test_take_action_with_filter". Implementation: This patch creates a separate list of fake vnflcm op occs dictionary for both the test cases. This issue has been impacting below reviews as well, [1] https://review.opendev.org/c/openstack/python-tackerclient/+/636893 [2] https://review.opendev.org/c/openstack/python-tackerclient/+/781314 Co-Authored: Yasufumi Ogawa Closes-Bug: #1919350 Change-Id: I0d62f77cf5d1e9ec0b0a7c404abab83f97b708ba --- .../tests/unit/osc/v1/test_vnflcm_op_occs.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tackerclient/tests/unit/osc/v1/test_vnflcm_op_occs.py b/tackerclient/tests/unit/osc/v1/test_vnflcm_op_occs.py index cc97288a..0c9ba77a 100644 --- a/tackerclient/tests/unit/osc/v1/test_vnflcm_op_occs.py +++ b/tackerclient/tests/unit/osc/v1/test_vnflcm_op_occs.py @@ -340,19 +340,19 @@ class TestRetryVnfLcmOp(TestVnfLcm): class TestListVnfLcmOp(TestVnfLcm): - vnflcm_op_occs_obj = vnflcm_op_occs_fakes.create_vnflcm_op_occs(count=3) - def setUp(self): super(TestListVnfLcmOp, self).setUp() self.list_vnflcm_op_occ = vnflcm_op_occs.ListVnfLcmOp( self.app, self.app_args, cmd_name='vnflcm op list') def test_take_action(self): + vnflcm_op_occs_obj = vnflcm_op_occs_fakes.create_vnflcm_op_occs( + count=3) parsed_args = self.check_parser(self.list_vnflcm_op_occ, [], []) self.requests_mock.register_uri( 'GET', os.path.join(self.url, 'vnflcm/v1/vnf_lcm_op_occs'), - json=self.vnflcm_op_occs_obj, headers=self.header) + json=vnflcm_op_occs_obj, headers=self.header) actual_columns, data = self.list_vnflcm_op_occ.take_action(parsed_args) @@ -360,15 +360,17 @@ class TestListVnfLcmOp(TestVnfLcm): self.list_vnflcm_op_occ.get_attributes(), long_listing=True) expected_data = [] - for vnflcm_op_occ_obj in self.vnflcm_op_occs_obj: + for vnflcm_op_occ_obj_idx in vnflcm_op_occs_obj: expected_data.append(vnflcm_op_occs_fakes.get_vnflcm_op_occ_data( - vnflcm_op_occ_obj, columns=columns)) + vnflcm_op_occ_obj_idx, columns=columns)) self.assertItemsEqual(_get_columns_vnflcm_op_occs(action='list'), actual_columns) self.assertItemsEqual(expected_data, list(data)) def test_take_action_with_filter(self): + vnflcm_op_occs_obj = vnflcm_op_occs_fakes.create_vnflcm_op_occs( + count=3) parsed_args = self.check_parser( self.list_vnflcm_op_occ, ["--filter", '(eq,operationState,STARTING)'], @@ -378,7 +380,7 @@ class TestListVnfLcmOp(TestVnfLcm): self.url, 'vnflcm/v1/vnf_lcm_op_occs?' 'filter=(eq,operationState,STARTING)'), - json=self.vnflcm_op_occs_obj, headers=self.header) + json=vnflcm_op_occs_obj, headers=self.header) actual_columns, data = self.list_vnflcm_op_occ.take_action(parsed_args) @@ -386,9 +388,9 @@ class TestListVnfLcmOp(TestVnfLcm): self.list_vnflcm_op_occ.get_attributes(), long_listing=True) expected_data = [] - for vnflcm_op_occ_obj in self.vnflcm_op_occs_obj: + for vnflcm_op_occ_obj_idx in vnflcm_op_occs_obj: expected_data.append(vnflcm_op_occs_fakes.get_vnflcm_op_occ_data( - vnflcm_op_occ_obj, columns=columns)) + vnflcm_op_occ_obj_idx, columns=columns)) self.assertItemsEqual(_get_columns_vnflcm_op_occs(action='list'), actual_columns)