Skip to content

Commit d7c3048

Browse files
committed
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
1 parent d37d27b commit d7c3048

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

openstackclient/tests/compute/v2/test_server.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,87 @@ def test_server_image_create_name(self):
611611
self.assertEqual(datalist, data)
612612

613613

614+
class TestServerList(TestServer):
615+
616+
# Columns to be listed up.
617+
columns = (
618+
'ID',
619+
'Name',
620+
'Status',
621+
'Networks',
622+
)
623+
624+
# Data returned by corresponding Nova API. The elements in this list are
625+
# tuples filled with server attributes.
626+
data = []
627+
628+
# Default search options, in the case of no commandline option specified.
629+
search_opts = {
630+
'reservation_id': None,
631+
'ip': None,
632+
'ip6': None,
633+
'name': None,
634+
'instance_name': None,
635+
'status': None,
636+
'flavor': None,
637+
'image': None,
638+
'host': None,
639+
'tenant_id': None,
640+
'all_tenants': False,
641+
'user_id': None,
642+
}
643+
644+
# Default params of the core function of the command in the case of no
645+
# commandline option specified.
646+
kwargs = {
647+
'search_opts': search_opts,
648+
'marker': None,
649+
'limit': None,
650+
}
651+
652+
def setUp(self):
653+
super(TestServerList, self).setUp()
654+
655+
# The fake servers' attributes.
656+
self.attrs = {
657+
'status': 'ACTIVE',
658+
'networks': {
659+
u'public': [u'10.20.30.40', u'2001:db8::5']
660+
},
661+
}
662+
663+
# The servers to be listed.
664+
self.servers = self.setup_servers_mock(3)
665+
666+
self.servers_mock.list.return_value = self.servers
667+
668+
# Get the command object to test
669+
self.cmd = server.ListServer(self.app, None)
670+
671+
# Prepare data returned by fake Nova API.
672+
for s in self.servers:
673+
self.data.append((
674+
s.id,
675+
s.name,
676+
s.status,
677+
u'public=10.20.30.40, 2001:db8::5',
678+
))
679+
680+
def test_server_list_no_option(self):
681+
arglist = []
682+
verifylist = [
683+
('all_projects', False),
684+
('long', False),
685+
]
686+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
687+
688+
columns, data = self.cmd.take_action(parsed_args)
689+
690+
self.servers_mock.list.assert_called_with(**self.kwargs)
691+
self.assertEqual(self.columns, columns)
692+
self.assertEqual(tuple(self.data), tuple(data))
693+
694+
614695
class TestServerLock(TestServer):
615696

616697
def setUp(self):

0 commit comments

Comments
 (0)