Skip to content

Commit f2339e9

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add unit test for TestServerList to test --long option."
2 parents 24712ba + 6a5be8c commit f2339e9

1 file changed

Lines changed: 50 additions & 5 deletions

File tree

openstackclient/tests/compute/v2/test_server.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,17 @@ class TestServerList(TestServer):
624624
'Status',
625625
'Networks',
626626
)
627-
628-
# Data returned by corresponding Nova API. The elements in this list are
629-
# tuples filled with server attributes.
630-
data = []
627+
columns_long = (
628+
'ID',
629+
'Name',
630+
'Status',
631+
'Task State',
632+
'Power State',
633+
'Networks',
634+
'Availability Zone',
635+
'Host',
636+
'Properties',
637+
)
631638

632639
# Default search options, in the case of no commandline option specified.
633640
search_opts = {
@@ -656,12 +663,18 @@ class TestServerList(TestServer):
656663
def setUp(self):
657664
super(TestServerList, self).setUp()
658665

659-
# The fake servers' attributes.
666+
# The fake servers' attributes. Use the original attributes names in
667+
# nova, not the ones printed by "server list" command.
660668
self.attrs = {
661669
'status': 'ACTIVE',
670+
'OS-EXT-STS:task_state': 'None',
671+
'OS-EXT-STS:power_state': 0x01, # Running
662672
'networks': {
663673
u'public': [u'10.20.30.40', u'2001:db8::5']
664674
},
675+
'OS-EXT-AZ:availability_zone': 'availability-zone-xxx',
676+
'OS-EXT-SRV-ATTR:host': 'host-name-xxx',
677+
'Metadata': '',
665678
}
666679

667680
# The servers to be listed.
@@ -673,13 +686,29 @@ def setUp(self):
673686
self.cmd = server.ListServer(self.app, None)
674687

675688
# Prepare data returned by fake Nova API.
689+
self.data = []
690+
self.data_long = []
691+
676692
for s in self.servers:
677693
self.data.append((
678694
s.id,
679695
s.name,
680696
s.status,
681697
server._format_servers_list_networks(s.networks),
682698
))
699+
self.data_long.append((
700+
s.id,
701+
s.name,
702+
s.status,
703+
getattr(s, 'OS-EXT-STS:task_state'),
704+
server._format_servers_list_power_state(
705+
getattr(s, 'OS-EXT-STS:power_state')
706+
),
707+
server._format_servers_list_networks(s.networks),
708+
getattr(s, 'OS-EXT-AZ:availability_zone'),
709+
getattr(s, 'OS-EXT-SRV-ATTR:host'),
710+
s.Metadata,
711+
))
683712

684713
def test_server_list_no_option(self):
685714
arglist = []
@@ -695,6 +724,22 @@ def test_server_list_no_option(self):
695724
self.assertEqual(self.columns, columns)
696725
self.assertEqual(tuple(self.data), tuple(data))
697726

727+
def test_server_list_long_option(self):
728+
arglist = [
729+
'--long',
730+
]
731+
verifylist = [
732+
('all_projects', False),
733+
('long', True),
734+
]
735+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
736+
737+
columns, data = self.cmd.take_action(parsed_args)
738+
739+
self.servers_mock.list.assert_called_with(**self.kwargs)
740+
self.assertEqual(self.columns_long, columns)
741+
self.assertEqual(tuple(self.data_long), tuple(data))
742+
698743

699744
class TestServerLock(TestServer):
700745

0 commit comments

Comments
 (0)