Merge "Refactor unit test of "compute service list" command"
This commit is contained in:
@@ -73,7 +73,7 @@ class ListService(command.Lister):
|
|||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
columns = (
|
columns = (
|
||||||
"Id",
|
"ID",
|
||||||
"Binary",
|
"Binary",
|
||||||
"Host",
|
"Host",
|
||||||
"Zone",
|
"Zone",
|
||||||
@@ -84,7 +84,7 @@ class ListService(command.Lister):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
columns = (
|
columns = (
|
||||||
"Id",
|
"ID",
|
||||||
"Binary",
|
"Binary",
|
||||||
"Host",
|
"Host",
|
||||||
"Zone",
|
"Zone",
|
||||||
|
@@ -648,15 +648,19 @@ class FakeService(object):
|
|||||||
:param Dictionary attrs:
|
:param Dictionary attrs:
|
||||||
A dictionary with all attributes
|
A dictionary with all attributes
|
||||||
:return:
|
:return:
|
||||||
A FakeResource object, with id, name, ram, vcpus, properties
|
A FakeResource object, with id, host, binary
|
||||||
"""
|
"""
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
|
|
||||||
# Set default attributes.
|
# Set default attributes.
|
||||||
service_info = {
|
service_info = {
|
||||||
|
'id': 'id-' + uuid.uuid4().hex,
|
||||||
'host': 'host-' + uuid.uuid4().hex,
|
'host': 'host-' + uuid.uuid4().hex,
|
||||||
'binary': 'binary-' + uuid.uuid4().hex,
|
'binary': 'binary-' + uuid.uuid4().hex,
|
||||||
'status': 'enabled',
|
'status': 'enabled',
|
||||||
|
'zone': 'zone-' + uuid.uuid4().hex,
|
||||||
|
'state': 'state-' + uuid.uuid4().hex,
|
||||||
|
'updated_at': 'time-' + uuid.uuid4().hex,
|
||||||
'disabled_reason': 'earthquake',
|
'disabled_reason': 'earthquake',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,11 +62,35 @@ class TestServiceDelete(TestService):
|
|||||||
|
|
||||||
class TestServiceList(TestService):
|
class TestServiceList(TestService):
|
||||||
|
|
||||||
|
service = compute_fakes.FakeService.create_one_service()
|
||||||
|
|
||||||
|
columns = (
|
||||||
|
'ID',
|
||||||
|
'Binary',
|
||||||
|
'Host',
|
||||||
|
'Zone',
|
||||||
|
'Status',
|
||||||
|
'State',
|
||||||
|
'Updated At',
|
||||||
|
)
|
||||||
|
columns_long = columns + (
|
||||||
|
'Disabled Reason',
|
||||||
|
)
|
||||||
|
|
||||||
|
data = [(
|
||||||
|
service.id,
|
||||||
|
service.binary,
|
||||||
|
service.host,
|
||||||
|
service.zone,
|
||||||
|
service.status,
|
||||||
|
service.state,
|
||||||
|
service.updated_at,
|
||||||
|
)]
|
||||||
|
data_long = [data[0] + (service.disabled_reason, )]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestServiceList, self).setUp()
|
super(TestServiceList, self).setUp()
|
||||||
|
|
||||||
self.service = compute_fakes.FakeService.create_one_service()
|
|
||||||
|
|
||||||
self.service_mock.list.return_value = [self.service]
|
self.service_mock.list.return_value = [self.service]
|
||||||
|
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
@@ -93,8 +117,8 @@ class TestServiceList(TestService):
|
|||||||
self.service.binary,
|
self.service.binary,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertNotIn("Disabled Reason", columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertNotIn(self.service.disabled_reason, list(data)[0])
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
def test_service_list_with_long_option(self):
|
def test_service_list_with_long_option(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
@@ -114,8 +138,13 @@ class TestServiceList(TestService):
|
|||||||
# containing the data to be listed.
|
# containing the data to be listed.
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.assertIn("Disabled Reason", columns)
|
self.service_mock.list.assert_called_with(
|
||||||
self.assertIn(self.service.disabled_reason, list(data)[0])
|
self.service.host,
|
||||||
|
self.service.binary,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns_long, columns)
|
||||||
|
self.assertEqual(self.data_long, list(data))
|
||||||
|
|
||||||
|
|
||||||
class TestServiceSet(TestService):
|
class TestServiceSet(TestService):
|
||||||
|
Reference in New Issue
Block a user