Skip to content

Commit 51fcd7c

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Refactor unit test of "compute service list" command"
2 parents fd03f52 + 70f8ae7 commit 51fcd7c

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

openstackclient/compute/v2/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def take_action(self, parsed_args):
7373
compute_client = self.app.client_manager.compute
7474
if parsed_args.long:
7575
columns = (
76-
"Id",
76+
"ID",
7777
"Binary",
7878
"Host",
7979
"Zone",
@@ -84,7 +84,7 @@ def take_action(self, parsed_args):
8484
)
8585
else:
8686
columns = (
87-
"Id",
87+
"ID",
8888
"Binary",
8989
"Host",
9090
"Zone",

openstackclient/tests/compute/v2/fakes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,15 +648,19 @@ def create_one_service(attrs=None):
648648
:param Dictionary attrs:
649649
A dictionary with all attributes
650650
:return:
651-
A FakeResource object, with id, name, ram, vcpus, properties
651+
A FakeResource object, with id, host, binary
652652
"""
653653
attrs = attrs or {}
654654

655655
# Set default attributes.
656656
service_info = {
657+
'id': 'id-' + uuid.uuid4().hex,
657658
'host': 'host-' + uuid.uuid4().hex,
658659
'binary': 'binary-' + uuid.uuid4().hex,
659660
'status': 'enabled',
661+
'zone': 'zone-' + uuid.uuid4().hex,
662+
'state': 'state-' + uuid.uuid4().hex,
663+
'updated_at': 'time-' + uuid.uuid4().hex,
660664
'disabled_reason': 'earthquake',
661665
}
662666

openstackclient/tests/compute/v2/test_service.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,35 @@ def test_service_delete_no_options(self):
6262

6363
class TestServiceList(TestService):
6464

65+
service = compute_fakes.FakeService.create_one_service()
66+
67+
columns = (
68+
'ID',
69+
'Binary',
70+
'Host',
71+
'Zone',
72+
'Status',
73+
'State',
74+
'Updated At',
75+
)
76+
columns_long = columns + (
77+
'Disabled Reason',
78+
)
79+
80+
data = [(
81+
service.id,
82+
service.binary,
83+
service.host,
84+
service.zone,
85+
service.status,
86+
service.state,
87+
service.updated_at,
88+
)]
89+
data_long = [data[0] + (service.disabled_reason, )]
90+
6591
def setUp(self):
6692
super(TestServiceList, self).setUp()
6793

68-
self.service = compute_fakes.FakeService.create_one_service()
69-
7094
self.service_mock.list.return_value = [self.service]
7195

7296
# Get the command object to test
@@ -93,8 +117,8 @@ def test_service_list(self):
93117
self.service.binary,
94118
)
95119

96-
self.assertNotIn("Disabled Reason", columns)
97-
self.assertNotIn(self.service.disabled_reason, list(data)[0])
120+
self.assertEqual(self.columns, columns)
121+
self.assertEqual(self.data, list(data))
98122

99123
def test_service_list_with_long_option(self):
100124
arglist = [
@@ -114,8 +138,13 @@ def test_service_list_with_long_option(self):
114138
# containing the data to be listed.
115139
columns, data = self.cmd.take_action(parsed_args)
116140

117-
self.assertIn("Disabled Reason", columns)
118-
self.assertIn(self.service.disabled_reason, list(data)[0])
141+
self.service_mock.list.assert_called_with(
142+
self.service.host,
143+
self.service.binary,
144+
)
145+
146+
self.assertEqual(self.columns_long, columns)
147+
self.assertEqual(self.data_long, list(data))
119148

120149

121150
class TestServiceSet(TestService):

0 commit comments

Comments
 (0)