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
This commit is contained in:
SaiKiran 2016-01-09 20:51:10 +05:30
parent 75caafa096
commit 69b8cde5f1
6 changed files with 106 additions and 171 deletions

View File

@ -240,6 +240,19 @@ class TestImageDelete(TestImage):
class TestImageList(TestImage): class TestImageList(TestImage):
columns = (
'ID',
'Name',
'Status',
)
datalist = (
(
image_fakes.image_id,
image_fakes.image_name,
'',
),
)
def setUp(self): def setUp(self):
super(TestImageList, self).setUp() super(TestImageList, self).setUp()
@ -268,15 +281,8 @@ class TestImageList(TestImage):
marker=image_fakes.image_id, marker=image_fakes.image_id,
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(collist, columns)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
def test_image_list_public_option(self): def test_image_list_public_option(self):
arglist = [ arglist = [
@ -297,15 +303,8 @@ class TestImageList(TestImage):
marker=image_fakes.image_id, marker=image_fakes.image_id,
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(collist, columns)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
def test_image_list_private_option(self): def test_image_list_private_option(self):
arglist = [ arglist = [
@ -326,15 +325,8 @@ class TestImageList(TestImage):
marker=image_fakes.image_id, marker=image_fakes.image_id,
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(collist, columns)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
def test_image_list_long_option(self): def test_image_list_long_option(self):
arglist = [ arglist = [
@ -407,15 +399,8 @@ class TestImageList(TestImage):
property_field='properties', property_field='properties',
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(columns, collist)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
@mock.patch('openstackclient.common.utils.sort_items') @mock.patch('openstackclient.common.utils.sort_items')
def test_image_list_sort_option(self, si_mock): def test_image_list_sort_option(self, si_mock):
@ -438,15 +423,8 @@ class TestImageList(TestImage):
'name:asc' 'name:asc'
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(collist, columns)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
class TestImageSet(TestImage): class TestImageSet(TestImage):

View File

@ -333,6 +333,17 @@ class TestImageCreate(TestImage):
class TestAddProjectToImage(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): def setUp(self):
super(TestAddProjectToImage, self).setUp() super(TestAddProjectToImage, self).setUp()
@ -375,14 +386,8 @@ class TestAddProjectToImage(TestImage):
image_fakes.image_id, image_fakes.image_id,
identity_fakes.project_id identity_fakes.project_id
) )
collist = ('image_id', 'member_id', 'status') self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns) self.assertEqual(self.datalist, data)
datalist = (
image_fakes.image_id,
identity_fakes.project_id,
image_fakes.member_status
)
self.assertEqual(datalist, data)
def test_add_project_to_image_with_option(self): def test_add_project_to_image_with_option(self):
arglist = [ arglist = [
@ -403,14 +408,8 @@ class TestAddProjectToImage(TestImage):
image_fakes.image_id, image_fakes.image_id,
identity_fakes.project_id identity_fakes.project_id
) )
collist = ('image_id', 'member_id', 'status') self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns) self.assertEqual(self.datalist, data)
datalist = (
image_fakes.image_id,
identity_fakes.project_id,
image_fakes.member_status
)
self.assertEqual(datalist, data)
class TestImageDelete(TestImage): class TestImageDelete(TestImage):
@ -460,6 +459,19 @@ class TestImageDelete(TestImage):
class TestImageList(TestImage): class TestImageList(TestImage):
columns = (
'ID',
'Name',
'Status',
)
datalist = (
(
image_fakes.image_id,
image_fakes.image_name,
'',
),
)
def setUp(self): def setUp(self):
super(TestImageList, self).setUp() super(TestImageList, self).setUp()
@ -488,15 +500,8 @@ class TestImageList(TestImage):
marker=image_fakes.image_id, marker=image_fakes.image_id,
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(collist, columns)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
def test_image_list_public_option(self): def test_image_list_public_option(self):
arglist = [ arglist = [
@ -517,15 +522,8 @@ class TestImageList(TestImage):
marker=image_fakes.image_id, marker=image_fakes.image_id,
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(collist, columns)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
def test_image_list_private_option(self): def test_image_list_private_option(self):
arglist = [ arglist = [
@ -546,15 +544,8 @@ class TestImageList(TestImage):
marker=image_fakes.image_id, marker=image_fakes.image_id,
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(collist, columns)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
def test_image_list_shared_option(self): def test_image_list_shared_option(self):
arglist = [ arglist = [
@ -575,15 +566,8 @@ class TestImageList(TestImage):
marker=image_fakes.image_id, marker=image_fakes.image_id,
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(columns, collist)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
def test_image_list_long_option(self): def test_image_list_long_option(self):
arglist = [ arglist = [
@ -654,15 +638,8 @@ class TestImageList(TestImage):
property_field='properties', property_field='properties',
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(columns, collist)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
@mock.patch('openstackclient.common.utils.sort_items') @mock.patch('openstackclient.common.utils.sort_items')
def test_image_list_sort_option(self, si_mock): def test_image_list_sort_option(self, si_mock):
@ -684,15 +661,8 @@ class TestImageList(TestImage):
'name:asc' 'name:asc'
) )
collist = ('ID', 'Name', 'Status') self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
self.assertEqual(collist, columns)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
), )
self.assertEqual(datalist, tuple(data))
class TestRemoveProjectImage(TestImage): class TestRemoveProjectImage(TestImage):

View File

@ -32,6 +32,9 @@ class FakeClient(object):
class TestContainer(object_fakes.TestObjectv1): class TestContainer(object_fakes.TestObjectv1):
columns = ('Name',)
def setUp(self): def setUp(self):
super(TestContainer, self).setUp() super(TestContainer, self).setUp()
self.app.client_manager.object_store = object_store.APIv1( self.app.client_manager.object_store = object_store.APIv1(
@ -73,8 +76,7 @@ class TestContainerList(TestContainer):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = ( datalist = (
(object_fakes.container_name, ), (object_fakes.container_name, ),
(object_fakes.container_name_3, ), (object_fakes.container_name_3, ),
@ -107,8 +109,7 @@ class TestContainerList(TestContainer):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = ( datalist = (
(object_fakes.container_name, ), (object_fakes.container_name, ),
(object_fakes.container_name_3, ), (object_fakes.container_name_3, ),
@ -143,8 +144,7 @@ class TestContainerList(TestContainer):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = ( datalist = (
(object_fakes.container_name, ), (object_fakes.container_name, ),
(object_fakes.container_name_3, ), (object_fakes.container_name_3, ),
@ -176,8 +176,7 @@ class TestContainerList(TestContainer):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = ( datalist = (
(object_fakes.container_name, ), (object_fakes.container_name, ),
(object_fakes.container_name_3, ), (object_fakes.container_name_3, ),
@ -250,8 +249,7 @@ class TestContainerList(TestContainer):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = ( datalist = (
(object_fakes.container_name, ), (object_fakes.container_name, ),
(object_fakes.container_name_2, ), (object_fakes.container_name_2, ),

View File

@ -29,6 +29,12 @@ class TestContainerAll(object_fakes.TestObjectv1):
class TestContainerCreate(TestContainerAll): class TestContainerCreate(TestContainerAll):
columns = (
'account',
'container',
'x-trans-id',
)
def setUp(self): def setUp(self):
super(TestContainerCreate, self).setUp() super(TestContainerCreate, self).setUp()
@ -54,8 +60,7 @@ class TestContainerCreate(TestContainerAll):
# DisplayCommandBase.take_action() returns two tuples # DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
collist = ('account', 'container', 'x-trans-id') self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = [( datalist = [(
object_fakes.ACCOUNT_ID, object_fakes.ACCOUNT_ID,
'ernie', 'ernie',
@ -89,8 +94,7 @@ class TestContainerCreate(TestContainerAll):
# DisplayCommandBase.take_action() returns two tuples # DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
collist = ('account', 'container', 'x-trans-id') self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = [ datalist = [
( (
object_fakes.ACCOUNT_ID, object_fakes.ACCOUNT_ID,
@ -161,6 +165,8 @@ class TestContainerDelete(TestContainerAll):
class TestContainerList(TestContainerAll): class TestContainerList(TestContainerAll):
columns = ('Name',)
def setUp(self): def setUp(self):
super(TestContainerList, self).setUp() super(TestContainerList, self).setUp()
@ -187,8 +193,7 @@ class TestContainerList(TestContainerAll):
# Lister.take_action() returns two tuples # Lister.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = [ datalist = [
(object_fakes.container_name, ), (object_fakes.container_name, ),
(object_fakes.container_name_3, ), (object_fakes.container_name_3, ),
@ -219,8 +224,7 @@ class TestContainerList(TestContainerAll):
# Lister.take_action() returns two tuples # Lister.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = [ datalist = [
(object_fakes.container_name, ), (object_fakes.container_name, ),
(object_fakes.container_name_3, ), (object_fakes.container_name_3, ),

View File

@ -40,6 +40,13 @@ class TestObject(object_fakes.TestObjectv1):
) )
class TestObjectList(TestObject): class TestObjectList(TestObject):
columns = ('Name',)
datalist = (
(
object_fakes.object_name_2,
),
)
def setUp(self): def setUp(self):
super(TestObjectList, self).setUp() super(TestObjectList, self).setUp()
@ -67,8 +74,7 @@ class TestObjectList(TestObject):
container=object_fakes.container_name, container=object_fakes.container_name,
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = ( datalist = (
(object_fakes.object_name_1, ), (object_fakes.object_name_1, ),
(object_fakes.object_name_2, ), (object_fakes.object_name_2, ),
@ -102,12 +108,8 @@ class TestObjectList(TestObject):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns) self.assertEqual(self.datalist, tuple(data))
datalist = (
(object_fakes.object_name_2, ),
)
self.assertEqual(datalist, tuple(data))
def test_object_list_objects_delimiter(self, o_mock): def test_object_list_objects_delimiter(self, o_mock):
o_mock.return_value = [ o_mock.return_value = [
@ -136,12 +138,8 @@ class TestObjectList(TestObject):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns) self.assertEqual(self.datalist, tuple(data))
datalist = (
(object_fakes.object_name_2, ),
)
self.assertEqual(datalist, tuple(data))
def test_object_list_objects_marker(self, o_mock): def test_object_list_objects_marker(self, o_mock):
o_mock.return_value = [ o_mock.return_value = [
@ -170,12 +168,8 @@ class TestObjectList(TestObject):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns) self.assertEqual(self.datalist, tuple(data))
datalist = (
(object_fakes.object_name_2, ),
)
self.assertEqual(datalist, tuple(data))
def test_object_list_objects_end_marker(self, o_mock): def test_object_list_objects_end_marker(self, o_mock):
o_mock.return_value = [ o_mock.return_value = [
@ -204,12 +198,8 @@ class TestObjectList(TestObject):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns) self.assertEqual(self.datalist, tuple(data))
datalist = (
(object_fakes.object_name_2, ),
)
self.assertEqual(datalist, tuple(data))
def test_object_list_objects_limit(self, o_mock): def test_object_list_objects_limit(self, o_mock):
o_mock.return_value = [ o_mock.return_value = [
@ -238,12 +228,8 @@ class TestObjectList(TestObject):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns) self.assertEqual(self.datalist, tuple(data))
datalist = (
(object_fakes.object_name_2, ),
)
self.assertEqual(datalist, tuple(data))
def test_object_list_objects_long(self, o_mock): def test_object_list_objects_long(self, o_mock):
o_mock.return_value = [ o_mock.return_value = [
@ -320,8 +306,7 @@ class TestObjectList(TestObject):
**kwargs **kwargs
) )
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = ( datalist = (
(object_fakes.object_name_1, ), (object_fakes.object_name_1, ),
(object_fakes.object_name_2, ), (object_fakes.object_name_2, ),

View File

@ -37,6 +37,8 @@ class TestObjectCreate(TestObjectAll):
class TestObjectList(TestObjectAll): class TestObjectList(TestObjectAll):
columns = ('Name',)
def setUp(self): def setUp(self):
super(TestObjectList, self).setUp() super(TestObjectList, self).setUp()
@ -69,8 +71,7 @@ class TestObjectList(TestObjectAll):
# Lister.take_action() returns two tuples # Lister.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = [ datalist = [
(object_fakes.object_name_1, ), (object_fakes.object_name_1, ),
(object_fakes.object_name_2, ), (object_fakes.object_name_2, ),
@ -104,8 +105,7 @@ class TestObjectList(TestObjectAll):
# DisplayCommandBase.take_action() returns two tuples # DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
collist = ('Name',) self.assertEqual(self.columns, columns)
self.assertEqual(collist, columns)
datalist = ( datalist = (
(object_fakes.object_name_2, ), (object_fakes.object_name_2, ),
) )