From f2ef9f2044abbe25eb4d7ba5d3998b0169abb757 Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Wed, 2 Mar 2016 16:48:16 +0800 Subject: [PATCH] Trivial: Reorder unit tests in alphabetical order in volume tests Change-Id: I622123f68e2bb53f8767069e4a717fcc34e37b5c --- .../tests/volume/v2/test_backup.py | 126 +++++------ .../tests/volume/v2/test_snapshot.py | 204 +++++++++--------- 2 files changed, 165 insertions(+), 165 deletions(-) diff --git a/openstackclient/tests/volume/v2/test_backup.py b/openstackclient/tests/volume/v2/test_backup.py index edb4eb8e73..6fe3f6668c 100644 --- a/openstackclient/tests/volume/v2/test_backup.py +++ b/openstackclient/tests/volume/v2/test_backup.py @@ -78,34 +78,6 @@ class TestBackupCreate(TestBackup): self.assertEqual(data, volume_fakes.BACKUP_data) -class TestBackupShow(TestBackup): - - def setUp(self): - super(TestBackupShow, self).setUp() - - self.backups_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.BACKUP), - loaded=True) - # Get the command object to test - self.cmd = backup.ShowBackup(self.app, None) - - def test_backup_show(self): - arglist = [ - volume_fakes.backup_id - ] - verifylist = [ - ("backup", volume_fakes.backup_id) - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - columns, data = self.cmd.take_action(parsed_args) - self.backups_mock.get.assert_called_with(volume_fakes.backup_id) - - self.assertEqual(volume_fakes.BACKUP_columns, columns) - self.assertEqual(volume_fakes.BACKUP_data, data) - - class TestBackupDelete(TestBackup): def setUp(self): @@ -134,41 +106,6 @@ class TestBackupDelete(TestBackup): self.backups_mock.delete.assert_called_with(volume_fakes.backup_id) -class TestBackupRestore(TestBackup): - - def setUp(self): - super(TestBackupRestore, self).setUp() - - self.backups_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.BACKUP), - loaded=True - ) - self.volumes_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.VOLUME), - loaded=True - ) - self.restores_mock.restore.return_value = None - # Get the command object to mock - self.cmd = backup.RestoreBackup(self.app, None) - - def test_backup_restore(self): - arglist = [ - volume_fakes.backup_id, - volume_fakes.volume_id - ] - verifylist = [ - ("backup", volume_fakes.backup_id), - ("volume", volume_fakes.volume_id) - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - self.cmd.take_action(parsed_args) - self.restores_mock.restore.assert_called_with(volume_fakes.backup_id, - volume_fakes.volume_id) - - class TestBackupList(TestBackup): columns = [ @@ -244,3 +181,66 @@ class TestBackupList(TestBackup): volume_fakes.backup_container ),) self.assertEqual(datalist, tuple(data)) + + +class TestBackupRestore(TestBackup): + + def setUp(self): + super(TestBackupRestore, self).setUp() + + self.backups_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(volume_fakes.BACKUP), + loaded=True + ) + self.volumes_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(volume_fakes.VOLUME), + loaded=True + ) + self.restores_mock.restore.return_value = None + # Get the command object to mock + self.cmd = backup.RestoreBackup(self.app, None) + + def test_backup_restore(self): + arglist = [ + volume_fakes.backup_id, + volume_fakes.volume_id + ] + verifylist = [ + ("backup", volume_fakes.backup_id), + ("volume", volume_fakes.volume_id) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.restores_mock.restore.assert_called_with(volume_fakes.backup_id, + volume_fakes.volume_id) + + +class TestBackupShow(TestBackup): + + def setUp(self): + super(TestBackupShow, self).setUp() + + self.backups_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(volume_fakes.BACKUP), + loaded=True) + # Get the command object to test + self.cmd = backup.ShowBackup(self.app, None) + + def test_backup_show(self): + arglist = [ + volume_fakes.backup_id + ] + verifylist = [ + ("backup", volume_fakes.backup_id) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + self.backups_mock.get.assert_called_with(volume_fakes.backup_id) + + self.assertEqual(volume_fakes.BACKUP_columns, columns) + self.assertEqual(volume_fakes.BACKUP_data, data) diff --git a/openstackclient/tests/volume/v2/test_snapshot.py b/openstackclient/tests/volume/v2/test_snapshot.py index b4fb004bee..349e8dac85 100644 --- a/openstackclient/tests/volume/v2/test_snapshot.py +++ b/openstackclient/tests/volume/v2/test_snapshot.py @@ -76,34 +76,6 @@ class TestSnapshotCreate(TestSnapshot): self.assertEqual(data, volume_fakes.SNAPSHOT_data) -class TestSnapshotShow(TestSnapshot): - - def setUp(self): - super(TestSnapshotShow, self).setUp() - - self.snapshots_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.SNAPSHOT), - loaded=True) - # Get the command object to test - self.cmd = snapshot.ShowSnapshot(self.app, None) - - def test_snapshot_show(self): - arglist = [ - volume_fakes.snapshot_id - ] - verifylist = [ - ("snapshot", volume_fakes.snapshot_id) - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - columns, data = self.cmd.take_action(parsed_args) - self.snapshots_mock.get.assert_called_with(volume_fakes.snapshot_id) - - self.assertEqual(volume_fakes.SNAPSHOT_columns, columns) - self.assertEqual(volume_fakes.SNAPSHOT_data, data) - - class TestSnapshotDelete(TestSnapshot): def setUp(self): @@ -132,80 +104,6 @@ class TestSnapshotDelete(TestSnapshot): self.snapshots_mock.delete.assert_called_with(volume_fakes.snapshot_id) -class TestSnapshotSet(TestSnapshot): - - def setUp(self): - super(TestSnapshotSet, self).setUp() - - self.snapshots_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.SNAPSHOT), - loaded=True - ) - self.snapshots_mock.set_metadata.return_value = None - self.snapshots_mock.update.return_value = None - # Get the command object to mock - self.cmd = snapshot.SetSnapshot(self.app, None) - - def test_snapshot_set(self): - arglist = [ - volume_fakes.snapshot_id, - "--name", "new_snapshot", - "--property", "x=y", - "--property", "foo=foo" - ] - new_property = {"x": "y", "foo": "foo"} - verifylist = [ - ("snapshot", volume_fakes.snapshot_id), - ("name", "new_snapshot"), - ("property", new_property) - ] - - kwargs = { - "name": "new_snapshot", - } - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) - - self.snapshots_mock.update.assert_called_with( - volume_fakes.snapshot_id, **kwargs) - self.snapshots_mock.set_metadata.assert_called_with( - volume_fakes.snapshot_id, new_property - ) - - -class TestSnapshotUnset(TestSnapshot): - - def setUp(self): - super(TestSnapshotUnset, self).setUp() - - self.snapshots_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.SNAPSHOT), - loaded=True - ) - self.snapshots_mock.delete_metadata.return_value = None - # Get the command object to mock - self.cmd = snapshot.UnsetSnapshot(self.app, None) - - def test_snapshot_unset(self): - arglist = [ - volume_fakes.snapshot_id, - "--property", "foo" - ] - verifylist = [ - ("snapshot", volume_fakes.snapshot_id), - ("property", ["foo"]) - ] - - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) - - self.snapshots_mock.delete_metadata.assert_called_with( - volume_fakes.snapshot_id, ["foo"] - ) - - class TestSnapshotList(TestSnapshot): columns = [ @@ -303,3 +201,105 @@ class TestSnapshotList(TestSnapshot): volume_fakes.snapshot_size ), ) self.assertEqual(datalist, tuple(data)) + + +class TestSnapshotSet(TestSnapshot): + + def setUp(self): + super(TestSnapshotSet, self).setUp() + + self.snapshots_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(volume_fakes.SNAPSHOT), + loaded=True + ) + self.snapshots_mock.set_metadata.return_value = None + self.snapshots_mock.update.return_value = None + # Get the command object to mock + self.cmd = snapshot.SetSnapshot(self.app, None) + + def test_snapshot_set(self): + arglist = [ + volume_fakes.snapshot_id, + "--name", "new_snapshot", + "--property", "x=y", + "--property", "foo=foo" + ] + new_property = {"x": "y", "foo": "foo"} + verifylist = [ + ("snapshot", volume_fakes.snapshot_id), + ("name", "new_snapshot"), + ("property", new_property) + ] + + kwargs = { + "name": "new_snapshot", + } + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.cmd.take_action(parsed_args) + + self.snapshots_mock.update.assert_called_with( + volume_fakes.snapshot_id, **kwargs) + self.snapshots_mock.set_metadata.assert_called_with( + volume_fakes.snapshot_id, new_property + ) + + +class TestSnapshotShow(TestSnapshot): + + def setUp(self): + super(TestSnapshotShow, self).setUp() + + self.snapshots_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(volume_fakes.SNAPSHOT), + loaded=True) + # Get the command object to test + self.cmd = snapshot.ShowSnapshot(self.app, None) + + def test_snapshot_show(self): + arglist = [ + volume_fakes.snapshot_id + ] + verifylist = [ + ("snapshot", volume_fakes.snapshot_id) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + self.snapshots_mock.get.assert_called_with(volume_fakes.snapshot_id) + + self.assertEqual(volume_fakes.SNAPSHOT_columns, columns) + self.assertEqual(volume_fakes.SNAPSHOT_data, data) + + +class TestSnapshotUnset(TestSnapshot): + + def setUp(self): + super(TestSnapshotUnset, self).setUp() + + self.snapshots_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(volume_fakes.SNAPSHOT), + loaded=True + ) + self.snapshots_mock.delete_metadata.return_value = None + # Get the command object to mock + self.cmd = snapshot.UnsetSnapshot(self.app, None) + + def test_snapshot_unset(self): + arglist = [ + volume_fakes.snapshot_id, + "--property", "foo" + ] + verifylist = [ + ("snapshot", volume_fakes.snapshot_id), + ("property", ["foo"]) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.cmd.take_action(parsed_args) + + self.snapshots_mock.delete_metadata.assert_called_with( + volume_fakes.snapshot_id, ["foo"] + )