Merge "Add unit test for TestServerList to test --long option."
This commit is contained in:
@@ -624,10 +624,17 @@ class TestServerList(TestServer):
|
|||||||
'Status',
|
'Status',
|
||||||
'Networks',
|
'Networks',
|
||||||
)
|
)
|
||||||
|
columns_long = (
|
||||||
# Data returned by corresponding Nova API. The elements in this list are
|
'ID',
|
||||||
# tuples filled with server attributes.
|
'Name',
|
||||||
data = []
|
'Status',
|
||||||
|
'Task State',
|
||||||
|
'Power State',
|
||||||
|
'Networks',
|
||||||
|
'Availability Zone',
|
||||||
|
'Host',
|
||||||
|
'Properties',
|
||||||
|
)
|
||||||
|
|
||||||
# Default search options, in the case of no commandline option specified.
|
# Default search options, in the case of no commandline option specified.
|
||||||
search_opts = {
|
search_opts = {
|
||||||
@@ -656,12 +663,18 @@ class TestServerList(TestServer):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestServerList, self).setUp()
|
super(TestServerList, self).setUp()
|
||||||
|
|
||||||
# The fake servers' attributes.
|
# The fake servers' attributes. Use the original attributes names in
|
||||||
|
# nova, not the ones printed by "server list" command.
|
||||||
self.attrs = {
|
self.attrs = {
|
||||||
'status': 'ACTIVE',
|
'status': 'ACTIVE',
|
||||||
|
'OS-EXT-STS:task_state': 'None',
|
||||||
|
'OS-EXT-STS:power_state': 0x01, # Running
|
||||||
'networks': {
|
'networks': {
|
||||||
u'public': [u'10.20.30.40', u'2001:db8::5']
|
u'public': [u'10.20.30.40', u'2001:db8::5']
|
||||||
},
|
},
|
||||||
|
'OS-EXT-AZ:availability_zone': 'availability-zone-xxx',
|
||||||
|
'OS-EXT-SRV-ATTR:host': 'host-name-xxx',
|
||||||
|
'Metadata': '',
|
||||||
}
|
}
|
||||||
|
|
||||||
# The servers to be listed.
|
# The servers to be listed.
|
||||||
@@ -673,6 +686,9 @@ class TestServerList(TestServer):
|
|||||||
self.cmd = server.ListServer(self.app, None)
|
self.cmd = server.ListServer(self.app, None)
|
||||||
|
|
||||||
# Prepare data returned by fake Nova API.
|
# Prepare data returned by fake Nova API.
|
||||||
|
self.data = []
|
||||||
|
self.data_long = []
|
||||||
|
|
||||||
for s in self.servers:
|
for s in self.servers:
|
||||||
self.data.append((
|
self.data.append((
|
||||||
s.id,
|
s.id,
|
||||||
@@ -680,6 +696,19 @@ class TestServerList(TestServer):
|
|||||||
s.status,
|
s.status,
|
||||||
server._format_servers_list_networks(s.networks),
|
server._format_servers_list_networks(s.networks),
|
||||||
))
|
))
|
||||||
|
self.data_long.append((
|
||||||
|
s.id,
|
||||||
|
s.name,
|
||||||
|
s.status,
|
||||||
|
getattr(s, 'OS-EXT-STS:task_state'),
|
||||||
|
server._format_servers_list_power_state(
|
||||||
|
getattr(s, 'OS-EXT-STS:power_state')
|
||||||
|
),
|
||||||
|
server._format_servers_list_networks(s.networks),
|
||||||
|
getattr(s, 'OS-EXT-AZ:availability_zone'),
|
||||||
|
getattr(s, 'OS-EXT-SRV-ATTR:host'),
|
||||||
|
s.Metadata,
|
||||||
|
))
|
||||||
|
|
||||||
def test_server_list_no_option(self):
|
def test_server_list_no_option(self):
|
||||||
arglist = []
|
arglist = []
|
||||||
@@ -695,6 +724,22 @@ class TestServerList(TestServer):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(tuple(self.data), tuple(data))
|
self.assertEqual(tuple(self.data), tuple(data))
|
||||||
|
|
||||||
|
def test_server_list_long_option(self):
|
||||||
|
arglist = [
|
||||||
|
'--long',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('all_projects', False),
|
||||||
|
('long', True),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.servers_mock.list.assert_called_with(**self.kwargs)
|
||||||
|
self.assertEqual(self.columns_long, columns)
|
||||||
|
self.assertEqual(tuple(self.data_long), tuple(data))
|
||||||
|
|
||||||
|
|
||||||
class TestServerLock(TestServer):
|
class TestServerLock(TestServer):
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user