Skip to content

Commit 80eaa33

Browse files
committed
volume: Make better use of argparse
The latest in a series. Change-Id: I8273c817e38120ba0b25aebdbfa1c2872222765e Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 181bb19 commit 80eaa33

4 files changed

Lines changed: 182 additions & 145 deletions

File tree

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def test_volume_create_properties(self):
188188
self.new_volume.name,
189189
]
190190
verifylist = [
191-
('property', {'Alpha': 'a', 'Beta': 'b'}),
191+
('properties', {'Alpha': 'a', 'Beta': 'b'}),
192192
('size', self.new_volume.size),
193193
('name', self.new_volume.name),
194194
]
@@ -382,9 +382,7 @@ def test_volume_create_with_bootable_and_readonly(self, mock_wait):
382382
]
383383
verifylist = [
384384
('bootable', True),
385-
('non_bootable', False),
386385
('read_only', True),
387-
('read_write', False),
388386
('size', self.new_volume.size),
389387
('name', self.new_volume.name),
390388
]
@@ -427,9 +425,7 @@ def test_volume_create_with_nonbootable_and_readwrite(self, mock_wait):
427425
]
428426
verifylist = [
429427
('bootable', False),
430-
('non_bootable', True),
431428
('read_only', False),
432-
('read_write', True),
433429
('size', self.new_volume.size),
434430
('name', self.new_volume.name),
435431
]
@@ -481,9 +477,7 @@ def test_volume_create_with_bootable_and_readonly_fail(
481477
]
482478
verifylist = [
483479
('bootable', True),
484-
('non_bootable', False),
485480
('read_only', True),
486-
('read_write', False),
487481
('size', self.new_volume.size),
488482
('name', self.new_volume.name),
489483
]
@@ -532,9 +526,7 @@ def test_volume_create_non_available_with_readonly(
532526
]
533527
verifylist = [
534528
('bootable', False),
535-
('non_bootable', True),
536529
('read_only', True),
537-
('read_write', False),
538530
('size', self.new_volume.size),
539531
('name', self.new_volume.name),
540532
]
@@ -1407,16 +1399,16 @@ def test_volume_set_property(self):
14071399
self.new_volume.id,
14081400
]
14091401
verifylist = [
1410-
('property', {'a': 'b', 'c': 'd'}),
1402+
('properties', {'a': 'b', 'c': 'd'}),
14111403
('volume', self.new_volume.id),
1412-
('bootable', False),
1413-
('non_bootable', False),
1404+
('bootable', None),
1405+
('read_only', None),
14141406
]
14151407
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
14161408

14171409
self.cmd.take_action(parsed_args)
14181410
self.volumes_mock.set_metadata.assert_called_with(
1419-
self.new_volume.id, parsed_args.property
1411+
self.new_volume.id, parsed_args.properties
14201412
)
14211413

14221414
def test_volume_set_image_property(self):
@@ -1428,25 +1420,24 @@ def test_volume_set_image_property(self):
14281420
self.new_volume.id,
14291421
]
14301422
verifylist = [
1431-
('image_property', {'Alpha': 'a', 'Beta': 'b'}),
1423+
('image_properties', {'Alpha': 'a', 'Beta': 'b'}),
14321424
('volume', self.new_volume.id),
1433-
('bootable', False),
1434-
('non_bootable', False),
1425+
('bootable', None),
1426+
('read_only', None),
14351427
]
14361428
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
14371429

14381430
# In base command class ShowOne in cliff, abstract method take_action()
14391431
# returns nothing
14401432
self.cmd.take_action(parsed_args)
14411433
self.volumes_mock.set_image_metadata.assert_called_with(
1442-
self.new_volume.id, parsed_args.image_property
1434+
self.new_volume.id, parsed_args.image_properties
14431435
)
14441436

14451437
def test_volume_set_state(self):
14461438
arglist = ['--state', 'error', self.new_volume.id]
14471439
verifylist = [
1448-
('read_only', False),
1449-
('read_write', False),
1440+
('read_only', None),
14501441
('state', 'error'),
14511442
('volume', self.new_volume.id),
14521443
]
@@ -1511,36 +1502,40 @@ def test_volume_set_detached(self):
15111502

15121503
def test_volume_set_bootable(self):
15131504
arglist = [
1514-
['--bootable', self.new_volume.id],
1515-
['--non-bootable', self.new_volume.id],
1505+
'--bootable',
1506+
self.new_volume.id,
15161507
]
15171508
verifylist = [
1518-
[
1519-
('bootable', True),
1520-
('non_bootable', False),
1521-
('volume', self.new_volume.id),
1522-
],
1523-
[
1524-
('bootable', False),
1525-
('non_bootable', True),
1526-
('volume', self.new_volume.id),
1527-
],
1528-
]
1529-
for index in range(len(arglist)):
1530-
parsed_args = self.check_parser(
1531-
self.cmd, arglist[index], verifylist[index]
1532-
)
1509+
('bootable', True),
1510+
('volume', self.new_volume.id),
1511+
]
1512+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
15331513

1534-
self.cmd.take_action(parsed_args)
1535-
self.volumes_mock.set_bootable.assert_called_with(
1536-
self.new_volume.id, verifylist[index][0][1]
1537-
)
1514+
self.cmd.take_action(parsed_args)
1515+
self.volumes_mock.set_bootable.assert_called_with(
1516+
self.new_volume.id, verifylist[0][1]
1517+
)
1518+
1519+
def test_volume_set_non_bootable(self):
1520+
arglist = [
1521+
'--non-bootable',
1522+
self.new_volume.id,
1523+
]
1524+
verifylist = [
1525+
('bootable', False),
1526+
('volume', self.new_volume.id),
1527+
]
1528+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1529+
1530+
self.cmd.take_action(parsed_args)
1531+
self.volumes_mock.set_bootable.assert_called_with(
1532+
self.new_volume.id, verifylist[0][1]
1533+
)
15381534

1539-
def test_volume_set_readonly(self):
1535+
def test_volume_set_read_only(self):
15401536
arglist = ['--read-only', self.new_volume.id]
15411537
verifylist = [
15421538
('read_only', True),
1543-
('read_write', False),
15441539
('volume', self.new_volume.id),
15451540
]
15461541

@@ -1556,7 +1551,6 @@ def test_volume_set_read_write(self):
15561551
arglist = ['--read-write', self.new_volume.id]
15571552
verifylist = [
15581553
('read_only', False),
1559-
('read_write', True),
15601554
('volume', self.new_volume.id),
15611555
]
15621556

@@ -1686,7 +1680,7 @@ def test_volume_unset_image_property(self):
16861680
self.new_volume.id,
16871681
]
16881682
verifylist = [
1689-
('image_property', {'Alpha': 'a', 'Beta': 'b'}),
1683+
('image_properties', {'Alpha': 'a', 'Beta': 'b'}),
16901684
('volume', self.new_volume.id),
16911685
]
16921686
parsed_args = self.check_parser(self.cmd_set, arglist, verifylist)
@@ -1702,7 +1696,7 @@ def test_volume_unset_image_property(self):
17021696
self.new_volume.id,
17031697
]
17041698
verifylist_unset = [
1705-
('image_property', ['Alpha']),
1699+
('image_properties', ['Alpha']),
17061700
('volume', self.new_volume.id),
17071701
]
17081702
parsed_args_unset = self.check_parser(
@@ -1714,7 +1708,7 @@ def test_volume_unset_image_property(self):
17141708
self.cmd_unset.take_action(parsed_args_unset)
17151709

17161710
self.volumes_mock.delete_image_metadata.assert_called_with(
1717-
self.new_volume.id, parsed_args_unset.image_property
1711+
self.new_volume.id, parsed_args_unset.image_properties
17181712
)
17191713

17201714
def test_volume_unset_image_property_fail(self):
@@ -1729,8 +1723,8 @@ def test_volume_unset_image_property_fail(self):
17291723
self.new_volume.id,
17301724
]
17311725
verifylist = [
1732-
('image_property', ['Alpha']),
1733-
('property', ['Beta']),
1726+
('image_properties', ['Alpha']),
1727+
('properties', ['Beta']),
17341728
('volume', self.new_volume.id),
17351729
]
17361730
parsed_args = self.check_parser(self.cmd_unset, arglist, verifylist)
@@ -1743,10 +1737,10 @@ def test_volume_unset_image_property_fail(self):
17431737
'One or more of the unset operations failed', str(e)
17441738
)
17451739
self.volumes_mock.delete_image_metadata.assert_called_with(
1746-
self.new_volume.id, parsed_args.image_property
1740+
self.new_volume.id, parsed_args.image_properties
17471741
)
17481742
self.volumes_mock.delete_metadata.assert_called_with(
1749-
self.new_volume.id, parsed_args.property
1743+
self.new_volume.id, parsed_args.properties
17501744
)
17511745

17521746

0 commit comments

Comments
 (0)