Add class TestServerList to provide basic unit test for "server list" command.
This patch provide a class to test "server list" command. Only one simplest case in this patch. Some of the options in "server list" are complicated. And the server object contains lots of attributes need to be handled in specific ways. So other test cases will be added in other patches. Change-Id: Id9fdba8f149bd74187aa42516067dacebc6962b5 Implements: blueprint osc-unit-test-framework-improvement
This commit is contained in:
@ -611,6 +611,87 @@ class TestServerImageCreate(TestServer):
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
|
||||
class TestServerList(TestServer):
|
||||
|
||||
# Columns to be listed up.
|
||||
columns = (
|
||||
'ID',
|
||||
'Name',
|
||||
'Status',
|
||||
'Networks',
|
||||
)
|
||||
|
||||
# Data returned by corresponding Nova API. The elements in this list are
|
||||
# tuples filled with server attributes.
|
||||
data = []
|
||||
|
||||
# Default search options, in the case of no commandline option specified.
|
||||
search_opts = {
|
||||
'reservation_id': None,
|
||||
'ip': None,
|
||||
'ip6': None,
|
||||
'name': None,
|
||||
'instance_name': None,
|
||||
'status': None,
|
||||
'flavor': None,
|
||||
'image': None,
|
||||
'host': None,
|
||||
'tenant_id': None,
|
||||
'all_tenants': False,
|
||||
'user_id': None,
|
||||
}
|
||||
|
||||
# Default params of the core function of the command in the case of no
|
||||
# commandline option specified.
|
||||
kwargs = {
|
||||
'search_opts': search_opts,
|
||||
'marker': None,
|
||||
'limit': None,
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super(TestServerList, self).setUp()
|
||||
|
||||
# The fake servers' attributes.
|
||||
self.attrs = {
|
||||
'status': 'ACTIVE',
|
||||
'networks': {
|
||||
u'public': [u'10.20.30.40', u'2001:db8::5']
|
||||
},
|
||||
}
|
||||
|
||||
# The servers to be listed.
|
||||
self.servers = self.setup_servers_mock(3)
|
||||
|
||||
self.servers_mock.list.return_value = self.servers
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server.ListServer(self.app, None)
|
||||
|
||||
# Prepare data returned by fake Nova API.
|
||||
for s in self.servers:
|
||||
self.data.append((
|
||||
s.id,
|
||||
s.name,
|
||||
s.status,
|
||||
u'public=10.20.30.40, 2001:db8::5',
|
||||
))
|
||||
|
||||
def test_server_list_no_option(self):
|
||||
arglist = []
|
||||
verifylist = [
|
||||
('all_projects', False),
|
||||
('long', False),
|
||||
]
|
||||
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, columns)
|
||||
self.assertEqual(tuple(self.data), tuple(data))
|
||||
|
||||
|
||||
class TestServerLock(TestServer):
|
||||
|
||||
def setUp(self):
|
||||
|
Reference in New Issue
Block a user