Skip to content

Commit b58dd4f

Browse files
author
Tang Chen
committed
[Volume] Check return value is None in volume unit tests
take_action() in commands inheriting from Command returns nothing. So we should assert the return is None in the unit tests of these commands. Change-Id: Idd961a5fa3db825353700837a559621d17f782c5 Partial-Bug: #1550636
1 parent 977eb4f commit b58dd4f

7 files changed

Lines changed: 84 additions & 46 deletions

File tree

openstackclient/tests/volume/v1/test_qos_specs.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ def test_qos_associate(self):
6262
]
6363
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
6464

65-
self.cmd.take_action(parsed_args)
65+
result = self.cmd.take_action(parsed_args)
66+
6667
self.qos_mock.associate.assert_called_with(
6768
volume_fakes.qos_id,
6869
volume_fakes.type_id
6970
)
71+
self.assertIsNone(result)
7072

7173

7274
class TestQosCreate(TestQos):
@@ -204,11 +206,12 @@ def test_qos_delete_with_id(self):
204206
verifylist = [
205207
('qos_specs', [volume_fakes.qos_id])
206208
]
207-
208209
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
209210

210-
self.cmd.take_action(parsed_args)
211+
result = self.cmd.take_action(parsed_args)
212+
211213
self.qos_mock.delete.assert_called_with(volume_fakes.qos_id)
214+
self.assertIsNone(result)
212215

213216
def test_qos_delete_with_name(self):
214217
arglist = [
@@ -217,11 +220,12 @@ def test_qos_delete_with_name(self):
217220
verifylist = [
218221
('qos_specs', [volume_fakes.qos_name])
219222
]
220-
221223
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
222224

223-
self.cmd.take_action(parsed_args)
225+
result = self.cmd.take_action(parsed_args)
226+
224227
self.qos_mock.delete.assert_called_with(volume_fakes.qos_id)
228+
self.assertIsNone(result)
225229

226230

227231
class TestQosDisassociate(TestQos):
@@ -253,11 +257,13 @@ def test_qos_disassociate_with_volume_type(self):
253257
]
254258
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
255259

256-
self.cmd.take_action(parsed_args)
260+
result = self.cmd.take_action(parsed_args)
261+
257262
self.qos_mock.disassociate.assert_called_with(
258263
volume_fakes.qos_id,
259264
volume_fakes.type_id
260265
)
266+
self.assertIsNone(result)
261267

262268
def test_qos_disassociate_with_all_volume_types(self):
263269
self.qos_mock.get.return_value = fakes.FakeResource(
@@ -275,8 +281,10 @@ def test_qos_disassociate_with_all_volume_types(self):
275281
]
276282
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
277283

278-
self.cmd.take_action(parsed_args)
284+
result = self.cmd.take_action(parsed_args)
285+
279286
self.qos_mock.disassociate_all.assert_called_with(volume_fakes.qos_id)
287+
self.assertIsNone(result)
280288

281289

282290
class TestQosList(TestQos):
@@ -351,11 +359,13 @@ def test_qos_set_with_properties_with_id(self):
351359
]
352360
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
353361

354-
self.cmd.take_action(parsed_args)
362+
result = self.cmd.take_action(parsed_args)
363+
355364
self.qos_mock.set_keys.assert_called_with(
356365
volume_fakes.qos_id,
357366
volume_fakes.qos_specs
358367
)
368+
self.assertIsNone(result)
359369

360370

361371
class TestQosShow(TestQos):
@@ -436,8 +446,10 @@ def test_qos_unset_with_properties(self):
436446
]
437447
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
438448

439-
self.cmd.take_action(parsed_args)
449+
result = self.cmd.take_action(parsed_args)
450+
440451
self.qos_mock.unset_keys.assert_called_with(
441452
volume_fakes.qos_id,
442453
['iops', 'foo']
443454
)
455+
self.assertIsNone(result)

openstackclient/tests/volume/v1/test_volume.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ def test_volume_set_no_options(self):
578578
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
579579

580580
result = self.cmd.run(parsed_args)
581+
581582
self.assertEqual(0, result)
582583
self.assertEqual("No changes requested\n",
583584
self.app.log.messages.get('error'))
@@ -596,7 +597,7 @@ def test_volume_set_name(self):
596597
]
597598
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
598599

599-
self.cmd.take_action(parsed_args)
600+
result = self.cmd.take_action(parsed_args)
600601

601602
# Set expected values
602603
kwargs = {
@@ -606,6 +607,7 @@ def test_volume_set_name(self):
606607
volume_fakes.volume_id,
607608
**kwargs
608609
)
610+
self.assertIsNone(result)
609611

610612
def test_volume_set_description(self):
611613
arglist = [
@@ -621,7 +623,7 @@ def test_volume_set_description(self):
621623
]
622624
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
623625

624-
self.cmd.take_action(parsed_args)
626+
result = self.cmd.take_action(parsed_args)
625627

626628
# Set expected values
627629
kwargs = {
@@ -631,6 +633,7 @@ def test_volume_set_description(self):
631633
volume_fakes.volume_id,
632634
**kwargs
633635
)
636+
self.assertIsNone(result)
634637

635638
def test_volume_set_size(self):
636639
arglist = [
@@ -646,15 +649,15 @@ def test_volume_set_size(self):
646649
]
647650
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
648651

649-
self.cmd.take_action(parsed_args)
652+
result = self.cmd.take_action(parsed_args)
650653

651654
# Set expected values
652655
size = 130
653-
654656
self.volumes_mock.extend.assert_called_with(
655657
volume_fakes.volume_id,
656658
size
657659
)
660+
self.assertIsNone(result)
658661

659662
def test_volume_set_size_smaller(self):
660663
arglist = [
@@ -671,6 +674,7 @@ def test_volume_set_size_smaller(self):
671674
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
672675

673676
result = self.cmd.run(parsed_args)
677+
674678
self.assertEqual(0, result)
675679
self.assertEqual("New size must be greater than %s GB" %
676680
volume_fakes.volume_size,
@@ -692,6 +696,7 @@ def test_volume_set_size_not_available(self):
692696
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
693697

694698
result = self.cmd.run(parsed_args)
699+
695700
self.assertEqual(0, result)
696701
self.assertEqual("Volume is in %s state, it must be available before "
697702
"size can be extended" % 'error',
@@ -711,7 +716,7 @@ def test_volume_set_property(self):
711716
]
712717
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
713718

714-
self.cmd.take_action(parsed_args)
719+
result = self.cmd.take_action(parsed_args)
715720

716721
# Set expected values
717722
metadata = {
@@ -721,3 +726,4 @@ def test_volume_set_property(self):
721726
volume_fakes.volume_id,
722727
metadata
723728
)
729+
self.assertIsNone(result)

openstackclient/tests/volume/v2/test_backup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ def test_backup_delete(self):
9999
verifylist = [
100100
("backups", [volume_fakes.backup_id])
101101
]
102-
103102
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
104103

105-
self.cmd.take_action(parsed_args)
104+
result = self.cmd.take_action(parsed_args)
105+
106106
self.backups_mock.delete.assert_called_with(volume_fakes.backup_id)
107+
self.assertIsNone(result)
107108

108109

109110
class TestBackupList(TestBackup):
@@ -213,9 +214,10 @@ def test_backup_restore(self):
213214
]
214215
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
215216

216-
self.cmd.take_action(parsed_args)
217+
result = self.cmd.take_action(parsed_args)
217218
self.restores_mock.restore.assert_called_with(volume_fakes.backup_id,
218219
volume_fakes.volume_id)
220+
self.assertIsNone(result)
219221

220222

221223
class TestBackupShow(TestBackup):

openstackclient/tests/volume/v2/test_qos_specs.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ def test_qos_associate(self):
6262
]
6363
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
6464

65-
self.cmd.take_action(parsed_args)
65+
result = self.cmd.take_action(parsed_args)
66+
6667
self.qos_mock.associate.assert_called_with(
6768
volume_fakes.qos_id,
6869
volume_fakes.type_id
6970
)
71+
self.assertIsNone(result)
7072

7173

7274
class TestQosCreate(TestQos):
@@ -205,11 +207,12 @@ def test_qos_delete_with_id(self):
205207
verifylist = [
206208
('qos_specs', [volume_fakes.qos_id])
207209
]
208-
209210
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
210211

211-
self.cmd.take_action(parsed_args)
212+
result = self.cmd.take_action(parsed_args)
213+
212214
self.qos_mock.delete.assert_called_with(volume_fakes.qos_id)
215+
self.assertIsNone(result)
213216

214217
def test_qos_delete_with_name(self):
215218
arglist = [
@@ -218,11 +221,12 @@ def test_qos_delete_with_name(self):
218221
verifylist = [
219222
('qos_specs', [volume_fakes.qos_name])
220223
]
221-
222224
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
223225

224-
self.cmd.take_action(parsed_args)
226+
result = self.cmd.take_action(parsed_args)
227+
225228
self.qos_mock.delete.assert_called_with(volume_fakes.qos_id)
229+
self.assertIsNone(result)
226230

227231

228232
class TestQosDisassociate(TestQos):
@@ -254,11 +258,13 @@ def test_qos_disassociate_with_volume_type(self):
254258
]
255259
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
256260

257-
self.cmd.take_action(parsed_args)
261+
result = self.cmd.take_action(parsed_args)
262+
258263
self.qos_mock.disassociate.assert_called_with(
259264
volume_fakes.qos_id,
260265
volume_fakes.type_id
261266
)
267+
self.assertIsNone(result)
262268

263269
def test_qos_disassociate_with_all_volume_types(self):
264270
self.qos_mock.get.return_value = fakes.FakeResource(
@@ -276,8 +282,10 @@ def test_qos_disassociate_with_all_volume_types(self):
276282
]
277283
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
278284

279-
self.cmd.take_action(parsed_args)
285+
result = self.cmd.take_action(parsed_args)
286+
280287
self.qos_mock.disassociate_all.assert_called_with(volume_fakes.qos_id)
288+
self.assertIsNone(result)
281289

282290

283291
class TestQosList(TestQos):
@@ -352,11 +360,13 @@ def test_qos_set_with_properties_with_id(self):
352360
]
353361
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
354362

355-
self.cmd.take_action(parsed_args)
363+
result = self.cmd.take_action(parsed_args)
364+
356365
self.qos_mock.set_keys.assert_called_with(
357366
volume_fakes.qos_id,
358367
volume_fakes.qos_specs
359368
)
369+
self.assertIsNone(result)
360370

361371

362372
class TestQosShow(TestQos):
@@ -430,15 +440,16 @@ def test_qos_unset_with_properties(self):
430440
'--property', 'iops',
431441
'--property', 'foo'
432442
]
433-
434443
verifylist = [
435444
('qos_spec', volume_fakes.qos_id),
436445
('property', ['iops', 'foo'])
437446
]
438447
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
439448

440-
self.cmd.take_action(parsed_args)
449+
result = self.cmd.take_action(parsed_args)
450+
441451
self.qos_mock.unset_keys.assert_called_with(
442452
volume_fakes.qos_id,
443453
['iops', 'foo']
444454
)
455+
self.assertIsNone(result)

openstackclient/tests/volume/v2/test_snapshot.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ def test_snapshot_delete(self):
9797
verifylist = [
9898
("snapshots", [volume_fakes.snapshot_id])
9999
]
100-
101100
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
102101

103-
self.cmd.take_action(parsed_args)
102+
result = self.cmd.take_action(parsed_args)
103+
104104
self.snapshots_mock.delete.assert_called_with(volume_fakes.snapshot_id)
105+
self.assertIsNone(result)
105106

106107

107108
class TestSnapshotList(TestSnapshot):
@@ -231,18 +232,19 @@ def test_snapshot_set(self):
231232
("name", "new_snapshot"),
232233
("property", new_property)
233234
]
235+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
236+
237+
result = self.cmd.take_action(parsed_args)
234238

235239
kwargs = {
236240
"name": "new_snapshot",
237241
}
238-
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
239-
self.cmd.take_action(parsed_args)
240-
241242
self.snapshots_mock.update.assert_called_with(
242243
volume_fakes.snapshot_id, **kwargs)
243244
self.snapshots_mock.set_metadata.assert_called_with(
244245
volume_fakes.snapshot_id, new_property
245246
)
247+
self.assertIsNone(result)
246248

247249

248250
class TestSnapshotShow(TestSnapshot):
@@ -296,10 +298,11 @@ def test_snapshot_unset(self):
296298
("snapshot", volume_fakes.snapshot_id),
297299
("property", ["foo"])
298300
]
299-
300301
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
301-
self.cmd.take_action(parsed_args)
302+
303+
result = self.cmd.take_action(parsed_args)
302304

303305
self.snapshots_mock.delete_metadata.assert_called_with(
304306
volume_fakes.snapshot_id, ["foo"]
305307
)
308+
self.assertIsNone(result)

0 commit comments

Comments
 (0)