diff options
| author | Stephen Finucane <sfinucan@redhat.com> | 2023-05-08 10:54:22 +0100 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2023-05-10 10:51:30 +0100 |
| commit | 35ba1d8f1304d3255b96b704d524666ec5b6fea2 (patch) | |
| tree | 6d4ab560d4086e8b1a1f935b8531d7e85550cc36 /openstackclient/tests/unit/volume/v2/test_volume.py | |
| parent | 28ffa2bf9f017212da5eb84b0cf74df62e2f5eb9 (diff) | |
| download | python-openstackclient-35ba1d8f1304d3255b96b704d524666ec5b6fea2.tar.gz | |
Blacken openstackclient.volume
Black used with the '-l 79 -S' flags.
A future change will ignore this commit in git-blame history by adding a
'git-blame-ignore-revs' file.
Change-Id: Ic318617c67ab7ce6527f9016b759a1d4b0b80802
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/tests/unit/volume/v2/test_volume.py')
| -rw-r--r-- | openstackclient/tests/unit/volume/v2/test_volume.py | 617 |
1 files changed, 344 insertions, 273 deletions
diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py index 0419acef..8a743725 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume.py +++ b/openstackclient/tests/unit/volume/v2/test_volume.py @@ -29,7 +29,6 @@ from openstackclient.volume.v2 import volume class TestVolume(volume_fakes.TestVolume): - def setUp(self): super().setUp() @@ -55,7 +54,8 @@ class TestVolume(volume_fakes.TestVolume): self.types_mock.reset_mock() self.consistencygroups_mock = ( - self.app.client_manager.volume.consistencygroups) + self.app.client_manager.volume.consistencygroups + ) self.consistencygroups_mock.reset_mock() def setup_volumes_mock(self, count): @@ -66,7 +66,6 @@ class TestVolume(volume_fakes.TestVolume): class TestVolumeCreate(TestVolume): - project = identity_fakes.FakeProject.create_one_project() user = identity_fakes.FakeUser.create_one_user() @@ -109,7 +108,8 @@ class TestVolumeCreate(TestVolume): def test_volume_create_min_options(self): arglist = [ - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), ] verifylist = [ ('size', self.new_volume.size), @@ -143,12 +143,18 @@ class TestVolumeCreate(TestVolume): consistency_group = volume_fakes.create_one_consistency_group() self.consistencygroups_mock.get.return_value = consistency_group arglist = [ - '--size', str(self.new_volume.size), - '--description', self.new_volume.description, - '--type', self.new_volume.volume_type, - '--availability-zone', self.new_volume.availability_zone, - '--consistency-group', consistency_group.id, - '--hint', 'k=v', + '--size', + str(self.new_volume.size), + '--description', + self.new_volume.description, + '--type', + self.new_volume.volume_type, + '--availability-zone', + self.new_volume.availability_zone, + '--consistency-group', + consistency_group.id, + '--hint', + 'k=v', self.new_volume.name, ] verifylist = [ @@ -187,9 +193,12 @@ class TestVolumeCreate(TestVolume): def test_volume_create_properties(self): arglist = [ - '--property', 'Alpha=a', - '--property', 'Beta=b', - '--size', str(self.new_volume.size), + '--property', + 'Alpha=a', + '--property', + 'Beta=b', + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -227,8 +236,10 @@ class TestVolumeCreate(TestVolume): self.find_image_mock.return_value = image arglist = [ - '--image', image.id, - '--size', str(self.new_volume.size), + '--image', + image.id, + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -266,8 +277,10 @@ class TestVolumeCreate(TestVolume): self.find_image_mock.return_value = image arglist = [ - '--image', image.name, - '--size', str(self.new_volume.size), + '--image', + image.name, + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -304,7 +317,8 @@ class TestVolumeCreate(TestVolume): snapshot = volume_fakes.create_one_snapshot() self.new_volume.snapshot_id = snapshot.id arglist = [ - '--snapshot', self.new_volume.snapshot_id, + '--snapshot', + self.new_volume.snapshot_id, self.new_volume.name, ] verifylist = [ @@ -342,7 +356,8 @@ class TestVolumeCreate(TestVolume): backup = volume_fakes.create_one_backup() self.new_volume.backup_id = backup.id arglist = [ - '--backup', self.new_volume.backup_id, + '--backup', + self.new_volume.backup_id, self.new_volume.name, ] verifylist = [ @@ -353,8 +368,9 @@ class TestVolumeCreate(TestVolume): self.backups_mock.get.return_value = backup - self.app.client_manager.volume.api_version = \ - api_versions.APIVersion('3.47') + self.app.client_manager.volume.api_version = api_versions.APIVersion( + '3.47' + ) # In base command class ShowOne in cliff, abstract method take_action() # returns a two-part tuple with a tuple of column names and a tuple of @@ -383,7 +399,8 @@ class TestVolumeCreate(TestVolume): backup = volume_fakes.create_one_backup() self.new_volume.backup_id = backup.id arglist = [ - '--backup', self.new_volume.backup_id, + '--backup', + self.new_volume.backup_id, self.new_volume.name, ] verifylist = [ @@ -394,14 +411,16 @@ class TestVolumeCreate(TestVolume): self.backups_mock.get.return_value = backup - exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + exc = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) self.assertIn("--os-volume-api-version 3.47 or greater", str(exc)) def test_volume_create_with_source_volume(self): source_vol = "source_vol" arglist = [ - '--source', self.new_volume.id, + '--source', + self.new_volume.id, source_vol, ] verifylist = [ @@ -440,7 +459,8 @@ class TestVolumeCreate(TestVolume): arglist = [ '--bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -452,8 +472,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -475,16 +494,19 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) @mock.patch.object(utils, 'wait_for_status', return_value=True) def test_volume_create_with_nonbootable_and_readwrite(self, mock_wait): arglist = [ '--non-bootable', '--read-write', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -496,8 +518,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -519,25 +540,28 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, False) + self.new_volume.id, False + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, False) + self.new_volume.id, False + ) @mock.patch.object(volume.LOG, 'error') @mock.patch.object(utils, 'wait_for_status', return_value=True) def test_volume_create_with_bootable_and_readonly_fail( - self, mock_wait, mock_error): - - self.volumes_mock.set_bootable.side_effect = ( - exceptions.CommandError()) + self, mock_wait, mock_error + ): + self.volumes_mock.set_bootable.side_effect = exceptions.CommandError() self.volumes_mock.update_readonly_flag.side_effect = ( - exceptions.CommandError()) + exceptions.CommandError() + ) arglist = [ '--bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -549,8 +573,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -573,19 +596,24 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertCountEqual(self.datalist, data) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) self.volumes_mock.update_readonly_flag.assert_called_with( - self.new_volume.id, True) + self.new_volume.id, True + ) @mock.patch.object(volume.LOG, 'error') @mock.patch.object(utils, 'wait_for_status', return_value=False) def test_volume_create_non_available_with_readonly( - self, mock_wait, mock_error, + self, + mock_wait, + mock_error, ): arglist = [ '--non-bootable', '--read-only', - '--size', str(self.new_volume.size), + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -597,8 +625,7 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - parsed_args = self.check_parser( - self.cmd, arglist, verifylist) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -630,15 +657,20 @@ class TestVolumeCreate(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) def test_volume_create_with_multi_source(self): arglist = [ - '--image', 'source_image', - '--source', 'source_volume', - '--snapshot', 'source_snapshot', - '--size', str(self.new_volume.size), + '--image', + 'source_image', + '--source', + 'source_volume', + '--snapshot', + 'source_snapshot', + '--size', + str(self.new_volume.size), self.new_volume.name, ] verifylist = [ @@ -649,12 +681,16 @@ class TestVolumeCreate(TestVolume): ('name', self.new_volume.name), ] - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) class TestVolumeDelete(TestVolume): - def setUp(self): super().setUp() @@ -666,9 +702,7 @@ class TestVolumeDelete(TestVolume): def test_volume_delete_one_volume(self): volumes = self.setup_volumes_mock(count=1) - arglist = [ - volumes[0].id - ] + arglist = [volumes[0].id] verifylist = [ ("force", False), ("purge", False), @@ -679,7 +713,8 @@ class TestVolumeDelete(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.delete.assert_called_once_with( - volumes[0].id, cascade=False) + volumes[0].id, cascade=False + ) self.assertIsNone(result) def test_volume_delete_multi_volumes(self): @@ -714,21 +749,22 @@ class TestVolumeDelete(TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) find_mock_result = [volumes[0], exceptions.CommandError] - with mock.patch.object(utils, 'find_resource', - side_effect=find_mock_result) as find_mock: + with mock.patch.object( + utils, 'find_resource', side_effect=find_mock_result + ) as find_mock: try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('1 of 2 volumes failed to delete.', - str(e)) + self.assertEqual('1 of 2 volumes failed to delete.', str(e)) find_mock.assert_any_call(self.volumes_mock, volumes[0].id) find_mock.assert_any_call(self.volumes_mock, 'unexist_volume') self.assertEqual(2, find_mock.call_count) self.volumes_mock.delete.assert_called_once_with( - volumes[0].id, cascade=False) + volumes[0].id, cascade=False + ) def test_volume_delete_with_purge(self): volumes = self.setup_volumes_mock(count=1) @@ -747,7 +783,8 @@ class TestVolumeDelete(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.delete.assert_called_once_with( - volumes[0].id, cascade=True) + volumes[0].id, cascade=True + ) self.assertIsNone(result) def test_volume_delete_with_force(self): @@ -771,7 +808,6 @@ class TestVolumeDelete(TestVolume): class TestVolumeList(TestVolume): - project = identity_fakes.FakeProject.create_one_project() user = identity_fakes.FakeUser.create_one_user() @@ -825,18 +861,21 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_project(self): arglist = [ - '--project', self.project.name, + '--project', + self.project.name, ] verifylist = [ ('project', self.project.name), @@ -865,19 +904,23 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_project_domain(self): arglist = [ - '--project', self.project.name, - '--project-domain', self.project.domain_id, + '--project', + self.project.name, + '--project-domain', + self.project.domain_id, ] verifylist = [ ('project', self.project.name), @@ -907,18 +950,21 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_user(self): arglist = [ - '--user', self.user.name, + '--user', + self.user.name, ] verifylist = [ ('user', self.user.name), @@ -946,19 +992,23 @@ class TestVolumeList(TestVolume): ) self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_user_domain(self): arglist = [ - '--user', self.user.name, - '--user-domain', self.user.domain_id, + '--user', + self.user.name, + '--user-domain', + self.user.domain_id, ] verifylist = [ ('user', self.user.name), @@ -988,18 +1038,21 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_name(self): arglist = [ - '--name', self.mock_volume.name, + '--name', + self.mock_volume.name, ] verifylist = [ ('long', False), @@ -1028,18 +1081,21 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_status(self): arglist = [ - '--status', self.mock_volume.status, + '--status', + self.mock_volume.status, ] verifylist = [ ('long', False), @@ -1068,13 +1124,15 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_all_projects(self): @@ -1108,13 +1166,15 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_long(self): @@ -1159,22 +1219,26 @@ class TestVolumeList(TestVolume): ] self.assertEqual(collist, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - self.mock_volume.volume_type, - self.mock_volume.bootable, - volume.AttachmentsColumn(self.mock_volume.attachments), - format_columns.DictColumn(self.mock_volume.metadata), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + self.mock_volume.volume_type, + self.mock_volume.bootable, + volume.AttachmentsColumn(self.mock_volume.attachments), + format_columns.DictColumn(self.mock_volume.metadata), + ), + ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_with_marker_and_limit(self): arglist = [ - "--marker", self.mock_volume.id, - "--limit", "2", + "--marker", + self.mock_volume.id, + "--limit", + "2", ] verifylist = [ ('long', False), @@ -1190,13 +1254,15 @@ class TestVolumeList(TestVolume): self.assertEqual(self.columns, columns) - datalist = (( - self.mock_volume.id, - self.mock_volume.name, - self.mock_volume.status, - self.mock_volume.size, - volume.AttachmentsColumn(self.mock_volume.attachments), - ), ) + datalist = ( + ( + self.mock_volume.id, + self.mock_volume.name, + self.mock_volume.status, + self.mock_volume.size, + volume.AttachmentsColumn(self.mock_volume.attachments), + ), + ) self.volumes_mock.list.assert_called_once_with( marker=self.mock_volume.id, @@ -1206,23 +1272,31 @@ class TestVolumeList(TestVolume): 'project_id': None, 'user_id': None, 'name': None, - 'all_tenants': False, } + 'all_tenants': False, + }, ) self.assertCountEqual(datalist, tuple(data)) def test_volume_list_negative_limit(self): arglist = [ - "--limit", "-2", + "--limit", + "-2", ] verifylist = [ ("limit", -2), ] - self.assertRaises(argparse.ArgumentTypeError, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + argparse.ArgumentTypeError, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) def test_volume_list_backward_compatibility(self): arglist = [ - '-c', 'Display Name', + '-c', + 'Display Name', ] verifylist = [ ('columns', ['Display Name']), @@ -1258,7 +1332,6 @@ class TestVolumeList(TestVolume): class TestVolumeMigrate(TestVolume): - _volume = volume_fakes.create_one_volume() def setUp(self): @@ -1271,7 +1344,8 @@ class TestVolumeMigrate(TestVolume): def test_volume_migrate(self): arglist = [ - "--host", "host@backend-name#pool", + "--host", + "host@backend-name#pool", self._volume.id, ] verifylist = [ @@ -1285,14 +1359,16 @@ class TestVolumeMigrate(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.get.assert_called_once_with(self._volume.id) self.volumes_mock.migrate_volume.assert_called_once_with( - self._volume.id, "host@backend-name#pool", False, False) + self._volume.id, "host@backend-name#pool", False, False + ) self.assertIsNone(result) def test_volume_migrate_with_option(self): arglist = [ "--force-host-copy", "--lock-volume", - "--host", "host@backend-name#pool", + "--host", + "host@backend-name#pool", self._volume.id, ] verifylist = [ @@ -1306,7 +1382,8 @@ class TestVolumeMigrate(TestVolume): result = self.cmd.take_action(parsed_args) self.volumes_mock.get.assert_called_once_with(self._volume.id) self.volumes_mock.migrate_volume.assert_called_once_with( - self._volume.id, "host@backend-name#pool", True, True) + self._volume.id, "host@backend-name#pool", True, True + ) self.assertIsNone(result) def test_volume_migrate_without_host(self): @@ -1319,12 +1396,16 @@ class TestVolumeMigrate(TestVolume): ("volume", self._volume.id), ] - self.assertRaises(tests_utils.ParserException, self.check_parser, - self.cmd, arglist, verifylist) + self.assertRaises( + tests_utils.ParserException, + self.check_parser, + self.cmd, + arglist, + verifylist, + ) class TestVolumeSet(TestVolume): - volume_type = volume_fakes.create_one_volume_type() def setUp(self): @@ -1339,33 +1420,38 @@ class TestVolumeSet(TestVolume): def test_volume_set_property(self): arglist = [ - '--property', 'a=b', - '--property', 'c=d', + '--property', + 'a=b', + '--property', + 'c=d', self.new_volume.id, ] verifylist = [ ('property', {'a': 'b', 'c': 'd'}), ('volume', self.new_volume.id), ('bootable', False), - ('non_bootable', False) + ('non_bootable', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) self.volumes_mock.set_metadata.assert_called_with( - self.new_volume.id, parsed_args.property) + self.new_volume.id, parsed_args.property + ) def test_volume_set_image_property(self): arglist = [ - '--image-property', 'Alpha=a', - '--image-property', 'Beta=b', + '--image-property', + 'Alpha=a', + '--image-property', + 'Beta=b', self.new_volume.id, ] verifylist = [ ('image_property', {'Alpha': 'a', 'Beta': 'b'}), ('volume', self.new_volume.id), ('bootable', False), - ('non_bootable', False) + ('non_bootable', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -1373,211 +1459,192 @@ class TestVolumeSet(TestVolume): # returns nothing self.cmd.take_action(parsed_args) self.volumes_mock.set_image_metadata.assert_called_with( - self.new_volume.id, parsed_args.image_property) + self.new_volume.id, parsed_args.image_property + ) def test_volume_set_state(self): - arglist = [ - '--state', 'error', - self.new_volume.id - ] + arglist = ['--state', 'error', self.new_volume.id] verifylist = [ ('read_only', False), ('read_write', False), ('state', 'error'), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.reset_state.assert_called_with( - self.new_volume.id, 'error') + self.new_volume.id, 'error' + ) self.volumes_mock.update_readonly_flag.assert_not_called() self.assertIsNone(result) def test_volume_set_state_failed(self): self.volumes_mock.reset_state.side_effect = exceptions.CommandError() - arglist = [ - '--state', 'error', - self.new_volume.id - ] - verifylist = [ - ('state', 'error'), - ('volume', self.new_volume.id) - ] + arglist = ['--state', 'error', self.new_volume.id] + verifylist = [('state', 'error'), ('volume', self.new_volume.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('One or more of the set operations failed', - str(e)) + self.assertEqual( + 'One or more of the set operations failed', str(e) + ) self.volumes_mock.reset_state.assert_called_with( - self.new_volume.id, 'error') + self.new_volume.id, 'error' + ) def test_volume_set_attached(self): - arglist = [ - '--attached', - self.new_volume.id - ] + arglist = ['--attached', self.new_volume.id] verifylist = [ ('attached', True), ('detached', False), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.reset_state.assert_called_with( - self.new_volume.id, attach_status='attached', state=None) + self.new_volume.id, attach_status='attached', state=None + ) self.assertIsNone(result) def test_volume_set_detached(self): - arglist = [ - '--detached', - self.new_volume.id - ] + arglist = ['--detached', self.new_volume.id] verifylist = [ ('attached', False), ('detached', True), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.reset_state.assert_called_with( - self.new_volume.id, attach_status='detached', state=None) + self.new_volume.id, attach_status='detached', state=None + ) self.assertIsNone(result) def test_volume_set_bootable(self): arglist = [ ['--bootable', self.new_volume.id], - ['--non-bootable', self.new_volume.id] + ['--non-bootable', self.new_volume.id], ] verifylist = [ [ ('bootable', True), ('non_bootable', False), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ], [ ('bootable', False), ('non_bootable', True), - ('volume', self.new_volume.id) - ] + ('volume', self.new_volume.id), + ], ] for index in range(len(arglist)): parsed_args = self.check_parser( - self.cmd, arglist[index], verifylist[index]) + self.cmd, arglist[index], verifylist[index] + ) self.cmd.take_action(parsed_args) self.volumes_mock.set_bootable.assert_called_with( - self.new_volume.id, verifylist[index][0][1]) + self.new_volume.id, verifylist[index][0][1] + ) def test_volume_set_readonly(self): - arglist = [ - '--read-only', - self.new_volume.id - ] + arglist = ['--read-only', self.new_volume.id] verifylist = [ ('read_only', True), ('read_write', False), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.update_readonly_flag.assert_called_once_with( - self.new_volume.id, - True) + self.new_volume.id, True + ) self.assertIsNone(result) def test_volume_set_read_write(self): - arglist = [ - '--read-write', - self.new_volume.id - ] + arglist = ['--read-write', self.new_volume.id] verifylist = [ ('read_only', False), ('read_write', True), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.update_readonly_flag.assert_called_once_with( - self.new_volume.id, - False) + self.new_volume.id, False + ) self.assertIsNone(result) def test_volume_set_type(self): - arglist = [ - '--type', self.volume_type.id, - self.new_volume.id - ] + arglist = ['--type', self.volume_type.id, self.new_volume.id] verifylist = [ ('retype_policy', None), ('type', self.volume_type.id), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.retype.assert_called_once_with( - self.new_volume.id, - self.volume_type.id, - 'never') + self.new_volume.id, self.volume_type.id, 'never' + ) self.assertIsNone(result) def test_volume_set_type_with_policy(self): arglist = [ - '--retype-policy', 'on-demand', - '--type', self.volume_type.id, - self.new_volume.id + '--retype-policy', + 'on-demand', + '--type', + self.volume_type.id, + self.new_volume.id, ] verifylist = [ ('retype_policy', 'on-demand'), ('type', self.volume_type.id), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.retype.assert_called_once_with( - self.new_volume.id, - self.volume_type.id, - 'on-demand') + self.new_volume.id, self.volume_type.id, 'on-demand' + ) self.assertIsNone(result) @mock.patch.object(volume.LOG, 'warning') def test_volume_set_with_only_retype_policy(self, mock_warning): - arglist = [ - '--retype-policy', 'on-demand', - self.new_volume.id - ] + arglist = ['--retype-policy', 'on-demand', self.new_volume.id] verifylist = [ ('retype_policy', 'on-demand'), - ('volume', self.new_volume.id) + ('volume', self.new_volume.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.volumes_mock.retype.assert_not_called() - mock_warning.assert_called_with("'--retype-policy' option will " - "not work without '--type' option") + mock_warning.assert_called_with( + "'--retype-policy' option will " "not work without '--type' option" + ) self.assertIsNone(result) class TestVolumeShow(TestVolume): - def setUp(self): super().setUp() @@ -1587,12 +1654,8 @@ class TestVolumeShow(TestVolume): self.cmd = volume.ShowVolume(self.app, None) def test_volume_show(self): - arglist = [ - self._volume.id - ] - verifylist = [ - ("volume", self._volume.id) - ] + arglist = [self._volume.id] + verifylist = [("volume", self._volume.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) @@ -1609,7 +1672,6 @@ class TestVolumeShow(TestVolume): class TestVolumeUnset(TestVolume): - def setUp(self): super().setUp() @@ -1623,11 +1685,12 @@ class TestVolumeUnset(TestVolume): self.cmd_unset = volume.UnsetVolume(self.app, None) def test_volume_unset_image_property(self): - # Arguments for setting image properties arglist = [ - '--image-property', 'Alpha=a', - '--image-property', 'Beta=b', + '--image-property', + 'Alpha=a', + '--image-property', + 'Beta=b', self.new_volume.id, ] verifylist = [ @@ -1642,30 +1705,35 @@ class TestVolumeUnset(TestVolume): # Arguments for unsetting image properties arglist_unset = [ - '--image-property', 'Alpha', + '--image-property', + 'Alpha', self.new_volume.id, ] verifylist_unset = [ ('image_property', ['Alpha']), ('volume', self.new_volume.id), ] - parsed_args_unset = self.check_parser(self.cmd_unset, - arglist_unset, - verifylist_unset) + parsed_args_unset = self.check_parser( + self.cmd_unset, arglist_unset, verifylist_unset + ) # In base command class ShowOne in cliff, abstract method take_action() # returns nothing self.cmd_unset.take_action(parsed_args_unset) self.volumes_mock.delete_image_metadata.assert_called_with( - self.new_volume.id, parsed_args_unset.image_property) + self.new_volume.id, parsed_args_unset.image_property + ) def test_volume_unset_image_property_fail(self): self.volumes_mock.delete_image_metadata.side_effect = ( - exceptions.CommandError()) + exceptions.CommandError() + ) arglist = [ - '--image-property', 'Alpha', - '--property', 'Beta', + '--image-property', + 'Alpha', + '--property', + 'Beta', self.new_volume.id, ] verifylist = [ @@ -1673,31 +1741,33 @@ class TestVolumeUnset(TestVolume): ('property', ['Beta']), ('volume', self.new_volume.id), ] - parsed_args = self.check_parser( - self.cmd_unset, arglist, verifylist) + parsed_args = self.check_parser(self.cmd_unset, arglist, verifylist) try: self.cmd_unset.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: - self.assertEqual('One or more of the unset operations failed', - str(e)) + self.assertEqual( + 'One or more of the unset operations failed', str(e) + ) self.volumes_mock.delete_image_metadata.assert_called_with( - self.new_volume.id, parsed_args.image_property) + self.new_volume.id, parsed_args.image_property + ) self.volumes_mock.delete_metadata.assert_called_with( - self.new_volume.id, parsed_args.property) + self.new_volume.id, parsed_args.property + ) class TestColumns(TestVolume): - def test_attachments_column_without_server_cache(self): _volume = volume_fakes.create_one_volume() server_id = _volume.attachments[0]['server_id'] device = _volume.attachments[0]['device'] col = volume.AttachmentsColumn(_volume.attachments, {}) - self.assertEqual('Attached to %s on %s ' % (server_id, device), - col.human_readable()) + self.assertEqual( + 'Attached to %s on %s ' % (server_id, device), col.human_readable() + ) self.assertEqual(_volume.attachments, col.machine_readable()) def test_attachments_column_with_server_cache(self): @@ -1712,5 +1782,6 @@ class TestColumns(TestVolume): col = volume.AttachmentsColumn(_volume.attachments, server_cache) self.assertEqual( 'Attached to %s on %s ' % ('fake-server-name', device), - col.human_readable()) + col.human_readable(), + ) self.assertEqual(_volume.attachments, col.machine_readable()) |
