From 69b8cde5f12c1d11036d99ef69421f103ebed87d Mon Sep 17 00:00:00 2001 From: SaiKiran Date: Sat, 9 Jan 2016 20:51:10 +0530 Subject: [PATCH] Refactor abstract columns and datalist out in image and object test cases columns and datalist has been set in each test case in image and object which is not necessary. This patch abstract it out and remove all redundant code. Change-Id: Ie6aa3fa27ab2a468c67da31209107517259631c2 Related-Bug: 1532384 --- openstackclient/tests/image/v1/test_image.py | 68 ++++------- openstackclient/tests/image/v2/test_image.py | 110 +++++++----------- .../tests/object/v1/test_container.py | 18 ++- .../tests/object/v1/test_container_all.py | 20 ++-- .../tests/object/v1/test_object.py | 53 +++------ .../tests/object/v1/test_object_all.py | 8 +- 6 files changed, 106 insertions(+), 171 deletions(-) diff --git a/openstackclient/tests/image/v1/test_image.py b/openstackclient/tests/image/v1/test_image.py index 60b7f3093d..1e0b29aa33 100644 --- a/openstackclient/tests/image/v1/test_image.py +++ b/openstackclient/tests/image/v1/test_image.py @@ -240,6 +240,19 @@ class TestImageDelete(TestImage): class TestImageList(TestImage): + columns = ( + 'ID', + 'Name', + 'Status', + ) + datalist = ( + ( + image_fakes.image_id, + image_fakes.image_name, + '', + ), + ) + def setUp(self): super(TestImageList, self).setUp() @@ -268,15 +281,8 @@ class TestImageList(TestImage): marker=image_fakes.image_id, ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(collist, columns) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_image_list_public_option(self): arglist = [ @@ -297,15 +303,8 @@ class TestImageList(TestImage): marker=image_fakes.image_id, ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(collist, columns) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_image_list_private_option(self): arglist = [ @@ -326,15 +325,8 @@ class TestImageList(TestImage): marker=image_fakes.image_id, ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(collist, columns) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_image_list_long_option(self): arglist = [ @@ -407,15 +399,8 @@ class TestImageList(TestImage): property_field='properties', ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(columns, collist) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) @mock.patch('openstackclient.common.utils.sort_items') def test_image_list_sort_option(self, si_mock): @@ -438,15 +423,8 @@ class TestImageList(TestImage): 'name:asc' ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(collist, columns) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) class TestImageSet(TestImage): diff --git a/openstackclient/tests/image/v2/test_image.py b/openstackclient/tests/image/v2/test_image.py index 3534a3a441..488eab20c9 100644 --- a/openstackclient/tests/image/v2/test_image.py +++ b/openstackclient/tests/image/v2/test_image.py @@ -333,6 +333,17 @@ class TestImageCreate(TestImage): class TestAddProjectToImage(TestImage): + columns = ( + 'image_id', + 'member_id', + 'status', + ) + datalist = ( + image_fakes.image_id, + identity_fakes.project_id, + image_fakes.member_status, + ) + def setUp(self): super(TestAddProjectToImage, self).setUp() @@ -375,14 +386,8 @@ class TestAddProjectToImage(TestImage): image_fakes.image_id, identity_fakes.project_id ) - collist = ('image_id', 'member_id', 'status') - self.assertEqual(collist, columns) - datalist = ( - image_fakes.image_id, - identity_fakes.project_id, - image_fakes.member_status - ) - self.assertEqual(datalist, data) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, data) def test_add_project_to_image_with_option(self): arglist = [ @@ -403,14 +408,8 @@ class TestAddProjectToImage(TestImage): image_fakes.image_id, identity_fakes.project_id ) - collist = ('image_id', 'member_id', 'status') - self.assertEqual(collist, columns) - datalist = ( - image_fakes.image_id, - identity_fakes.project_id, - image_fakes.member_status - ) - self.assertEqual(datalist, data) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, data) class TestImageDelete(TestImage): @@ -460,6 +459,19 @@ class TestImageDelete(TestImage): class TestImageList(TestImage): + columns = ( + 'ID', + 'Name', + 'Status', + ) + datalist = ( + ( + image_fakes.image_id, + image_fakes.image_name, + '', + ), + ) + def setUp(self): super(TestImageList, self).setUp() @@ -488,15 +500,8 @@ class TestImageList(TestImage): marker=image_fakes.image_id, ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(collist, columns) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_image_list_public_option(self): arglist = [ @@ -517,15 +522,8 @@ class TestImageList(TestImage): marker=image_fakes.image_id, ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(collist, columns) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_image_list_private_option(self): arglist = [ @@ -546,15 +544,8 @@ class TestImageList(TestImage): marker=image_fakes.image_id, ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(collist, columns) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_image_list_shared_option(self): arglist = [ @@ -575,15 +566,8 @@ class TestImageList(TestImage): marker=image_fakes.image_id, ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(columns, collist) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_image_list_long_option(self): arglist = [ @@ -654,15 +638,8 @@ class TestImageList(TestImage): property_field='properties', ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(columns, collist) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) @mock.patch('openstackclient.common.utils.sort_items') def test_image_list_sort_option(self, si_mock): @@ -684,15 +661,8 @@ class TestImageList(TestImage): 'name:asc' ) - collist = ('ID', 'Name', 'Status') - - self.assertEqual(collist, columns) - datalist = (( - image_fakes.image_id, - image_fakes.image_name, - '', - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) class TestRemoveProjectImage(TestImage): diff --git a/openstackclient/tests/object/v1/test_container.py b/openstackclient/tests/object/v1/test_container.py index 2ef2f7b52a..afcb3386b4 100644 --- a/openstackclient/tests/object/v1/test_container.py +++ b/openstackclient/tests/object/v1/test_container.py @@ -32,6 +32,9 @@ class FakeClient(object): class TestContainer(object_fakes.TestObjectv1): + + columns = ('Name',) + def setUp(self): super(TestContainer, self).setUp() self.app.client_manager.object_store = object_store.APIv1( @@ -73,8 +76,7 @@ class TestContainerList(TestContainer): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = ( (object_fakes.container_name, ), (object_fakes.container_name_3, ), @@ -107,8 +109,7 @@ class TestContainerList(TestContainer): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = ( (object_fakes.container_name, ), (object_fakes.container_name_3, ), @@ -143,8 +144,7 @@ class TestContainerList(TestContainer): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = ( (object_fakes.container_name, ), (object_fakes.container_name_3, ), @@ -176,8 +176,7 @@ class TestContainerList(TestContainer): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = ( (object_fakes.container_name, ), (object_fakes.container_name_3, ), @@ -250,8 +249,7 @@ class TestContainerList(TestContainer): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = ( (object_fakes.container_name, ), (object_fakes.container_name_2, ), diff --git a/openstackclient/tests/object/v1/test_container_all.py b/openstackclient/tests/object/v1/test_container_all.py index 69fc0f3962..c2dd02a59a 100644 --- a/openstackclient/tests/object/v1/test_container_all.py +++ b/openstackclient/tests/object/v1/test_container_all.py @@ -29,6 +29,12 @@ class TestContainerAll(object_fakes.TestObjectv1): class TestContainerCreate(TestContainerAll): + columns = ( + 'account', + 'container', + 'x-trans-id', + ) + def setUp(self): super(TestContainerCreate, self).setUp() @@ -54,8 +60,7 @@ class TestContainerCreate(TestContainerAll): # DisplayCommandBase.take_action() returns two tuples columns, data = self.cmd.take_action(parsed_args) - collist = ('account', 'container', 'x-trans-id') - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = [( object_fakes.ACCOUNT_ID, 'ernie', @@ -89,8 +94,7 @@ class TestContainerCreate(TestContainerAll): # DisplayCommandBase.take_action() returns two tuples columns, data = self.cmd.take_action(parsed_args) - collist = ('account', 'container', 'x-trans-id') - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = [ ( object_fakes.ACCOUNT_ID, @@ -161,6 +165,8 @@ class TestContainerDelete(TestContainerAll): class TestContainerList(TestContainerAll): + columns = ('Name',) + def setUp(self): super(TestContainerList, self).setUp() @@ -187,8 +193,7 @@ class TestContainerList(TestContainerAll): # Lister.take_action() returns two tuples columns, data = self.cmd.take_action(parsed_args) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = [ (object_fakes.container_name, ), (object_fakes.container_name_3, ), @@ -219,8 +224,7 @@ class TestContainerList(TestContainerAll): # Lister.take_action() returns two tuples columns, data = self.cmd.take_action(parsed_args) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = [ (object_fakes.container_name, ), (object_fakes.container_name_3, ), diff --git a/openstackclient/tests/object/v1/test_object.py b/openstackclient/tests/object/v1/test_object.py index 305fe8f83b..f0d62f6e16 100644 --- a/openstackclient/tests/object/v1/test_object.py +++ b/openstackclient/tests/object/v1/test_object.py @@ -40,6 +40,13 @@ class TestObject(object_fakes.TestObjectv1): ) class TestObjectList(TestObject): + columns = ('Name',) + datalist = ( + ( + object_fakes.object_name_2, + ), + ) + def setUp(self): super(TestObjectList, self).setUp() @@ -67,8 +74,7 @@ class TestObjectList(TestObject): container=object_fakes.container_name, ) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = ( (object_fakes.object_name_1, ), (object_fakes.object_name_2, ), @@ -102,12 +108,8 @@ class TestObjectList(TestObject): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) - datalist = ( - (object_fakes.object_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_object_list_objects_delimiter(self, o_mock): o_mock.return_value = [ @@ -136,12 +138,8 @@ class TestObjectList(TestObject): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) - datalist = ( - (object_fakes.object_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_object_list_objects_marker(self, o_mock): o_mock.return_value = [ @@ -170,12 +168,8 @@ class TestObjectList(TestObject): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) - datalist = ( - (object_fakes.object_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_object_list_objects_end_marker(self, o_mock): o_mock.return_value = [ @@ -204,12 +198,8 @@ class TestObjectList(TestObject): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) - datalist = ( - (object_fakes.object_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_object_list_objects_limit(self, o_mock): o_mock.return_value = [ @@ -238,12 +228,8 @@ class TestObjectList(TestObject): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) - datalist = ( - (object_fakes.object_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, tuple(data)) def test_object_list_objects_long(self, o_mock): o_mock.return_value = [ @@ -320,8 +306,7 @@ class TestObjectList(TestObject): **kwargs ) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = ( (object_fakes.object_name_1, ), (object_fakes.object_name_2, ), diff --git a/openstackclient/tests/object/v1/test_object_all.py b/openstackclient/tests/object/v1/test_object_all.py index 7a76ab76ad..a90e5b6587 100644 --- a/openstackclient/tests/object/v1/test_object_all.py +++ b/openstackclient/tests/object/v1/test_object_all.py @@ -37,6 +37,8 @@ class TestObjectCreate(TestObjectAll): class TestObjectList(TestObjectAll): + columns = ('Name',) + def setUp(self): super(TestObjectList, self).setUp() @@ -69,8 +71,7 @@ class TestObjectList(TestObjectAll): # Lister.take_action() returns two tuples columns, data = self.cmd.take_action(parsed_args) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = [ (object_fakes.object_name_1, ), (object_fakes.object_name_2, ), @@ -104,8 +105,7 @@ class TestObjectList(TestObjectAll): # DisplayCommandBase.take_action() returns two tuples columns, data = self.cmd.take_action(parsed_args) - collist = ('Name',) - self.assertEqual(collist, columns) + self.assertEqual(self.columns, columns) datalist = ( (object_fakes.object_name_2, ), )