From b58dd4f17f60b3c6347683b619c093b8d1a40c0b Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Mon, 29 Feb 2016 16:50:54 +0800 Subject: [PATCH] [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 --- .../tests/volume/v1/test_qos_specs.py | 30 ++++++++++++------ .../tests/volume/v1/test_volume.py | 16 +++++++--- .../tests/volume/v2/test_backup.py | 8 +++-- .../tests/volume/v2/test_qos_specs.py | 31 +++++++++++++------ .../tests/volume/v2/test_snapshot.py | 17 +++++----- openstackclient/tests/volume/v2/test_type.py | 18 ++++++----- .../tests/volume/v2/test_volume.py | 10 +++--- 7 files changed, 84 insertions(+), 46 deletions(-) diff --git a/openstackclient/tests/volume/v1/test_qos_specs.py b/openstackclient/tests/volume/v1/test_qos_specs.py index 1a6c0fa4ed..4943f5df69 100644 --- a/openstackclient/tests/volume/v1/test_qos_specs.py +++ b/openstackclient/tests/volume/v1/test_qos_specs.py @@ -62,11 +62,13 @@ class TestQosAssociate(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.associate.assert_called_with( volume_fakes.qos_id, volume_fakes.type_id ) + self.assertIsNone(result) class TestQosCreate(TestQos): @@ -204,11 +206,12 @@ class TestQosDelete(TestQos): verifylist = [ ('qos_specs', [volume_fakes.qos_id]) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.delete.assert_called_with(volume_fakes.qos_id) + self.assertIsNone(result) def test_qos_delete_with_name(self): arglist = [ @@ -217,11 +220,12 @@ class TestQosDelete(TestQos): verifylist = [ ('qos_specs', [volume_fakes.qos_name]) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.delete.assert_called_with(volume_fakes.qos_id) + self.assertIsNone(result) class TestQosDisassociate(TestQos): @@ -253,11 +257,13 @@ class TestQosDisassociate(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.disassociate.assert_called_with( volume_fakes.qos_id, volume_fakes.type_id ) + self.assertIsNone(result) def test_qos_disassociate_with_all_volume_types(self): self.qos_mock.get.return_value = fakes.FakeResource( @@ -275,8 +281,10 @@ class TestQosDisassociate(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.disassociate_all.assert_called_with(volume_fakes.qos_id) + self.assertIsNone(result) class TestQosList(TestQos): @@ -351,11 +359,13 @@ class TestQosSet(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.set_keys.assert_called_with( volume_fakes.qos_id, volume_fakes.qos_specs ) + self.assertIsNone(result) class TestQosShow(TestQos): @@ -436,8 +446,10 @@ class TestQosUnset(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.unset_keys.assert_called_with( volume_fakes.qos_id, ['iops', 'foo'] ) + self.assertIsNone(result) diff --git a/openstackclient/tests/volume/v1/test_volume.py b/openstackclient/tests/volume/v1/test_volume.py index 00c509b5d9..35fc917f11 100644 --- a/openstackclient/tests/volume/v1/test_volume.py +++ b/openstackclient/tests/volume/v1/test_volume.py @@ -578,6 +578,7 @@ class TestVolumeSet(TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.run(parsed_args) + self.assertEqual(0, result) self.assertEqual("No changes requested\n", self.app.log.messages.get('error')) @@ -596,7 +597,7 @@ class TestVolumeSet(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) # Set expected values kwargs = { @@ -606,6 +607,7 @@ class TestVolumeSet(TestVolume): volume_fakes.volume_id, **kwargs ) + self.assertIsNone(result) def test_volume_set_description(self): arglist = [ @@ -621,7 +623,7 @@ class TestVolumeSet(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) # Set expected values kwargs = { @@ -631,6 +633,7 @@ class TestVolumeSet(TestVolume): volume_fakes.volume_id, **kwargs ) + self.assertIsNone(result) def test_volume_set_size(self): arglist = [ @@ -646,15 +649,15 @@ class TestVolumeSet(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) # Set expected values size = 130 - self.volumes_mock.extend.assert_called_with( volume_fakes.volume_id, size ) + self.assertIsNone(result) def test_volume_set_size_smaller(self): arglist = [ @@ -671,6 +674,7 @@ class TestVolumeSet(TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.run(parsed_args) + self.assertEqual(0, result) self.assertEqual("New size must be greater than %s GB" % volume_fakes.volume_size, @@ -692,6 +696,7 @@ class TestVolumeSet(TestVolume): parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.run(parsed_args) + self.assertEqual(0, result) self.assertEqual("Volume is in %s state, it must be available before " "size can be extended" % 'error', @@ -711,7 +716,7 @@ class TestVolumeSet(TestVolume): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) # Set expected values metadata = { @@ -721,3 +726,4 @@ class TestVolumeSet(TestVolume): volume_fakes.volume_id, metadata ) + self.assertIsNone(result) diff --git a/openstackclient/tests/volume/v2/test_backup.py b/openstackclient/tests/volume/v2/test_backup.py index 6fe3f6668c..cc8dff5a36 100644 --- a/openstackclient/tests/volume/v2/test_backup.py +++ b/openstackclient/tests/volume/v2/test_backup.py @@ -99,11 +99,12 @@ class TestBackupDelete(TestBackup): verifylist = [ ("backups", [volume_fakes.backup_id]) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.backups_mock.delete.assert_called_with(volume_fakes.backup_id) + self.assertIsNone(result) class TestBackupList(TestBackup): @@ -213,9 +214,10 @@ class TestBackupRestore(TestBackup): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) self.restores_mock.restore.assert_called_with(volume_fakes.backup_id, volume_fakes.volume_id) + self.assertIsNone(result) class TestBackupShow(TestBackup): diff --git a/openstackclient/tests/volume/v2/test_qos_specs.py b/openstackclient/tests/volume/v2/test_qos_specs.py index c826925fda..5232285c85 100644 --- a/openstackclient/tests/volume/v2/test_qos_specs.py +++ b/openstackclient/tests/volume/v2/test_qos_specs.py @@ -62,11 +62,13 @@ class TestQosAssociate(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.associate.assert_called_with( volume_fakes.qos_id, volume_fakes.type_id ) + self.assertIsNone(result) class TestQosCreate(TestQos): @@ -205,11 +207,12 @@ class TestQosDelete(TestQos): verifylist = [ ('qos_specs', [volume_fakes.qos_id]) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.delete.assert_called_with(volume_fakes.qos_id) + self.assertIsNone(result) def test_qos_delete_with_name(self): arglist = [ @@ -218,11 +221,12 @@ class TestQosDelete(TestQos): verifylist = [ ('qos_specs', [volume_fakes.qos_name]) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.delete.assert_called_with(volume_fakes.qos_id) + self.assertIsNone(result) class TestQosDisassociate(TestQos): @@ -254,11 +258,13 @@ class TestQosDisassociate(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.disassociate.assert_called_with( volume_fakes.qos_id, volume_fakes.type_id ) + self.assertIsNone(result) def test_qos_disassociate_with_all_volume_types(self): self.qos_mock.get.return_value = fakes.FakeResource( @@ -276,8 +282,10 @@ class TestQosDisassociate(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.disassociate_all.assert_called_with(volume_fakes.qos_id) + self.assertIsNone(result) class TestQosList(TestQos): @@ -352,11 +360,13 @@ class TestQosSet(TestQos): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.set_keys.assert_called_with( volume_fakes.qos_id, volume_fakes.qos_specs ) + self.assertIsNone(result) class TestQosShow(TestQos): @@ -430,15 +440,16 @@ class TestQosUnset(TestQos): '--property', 'iops', '--property', 'foo' ] - verifylist = [ ('qos_spec', volume_fakes.qos_id), ('property', ['iops', 'foo']) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.qos_mock.unset_keys.assert_called_with( volume_fakes.qos_id, ['iops', 'foo'] ) + self.assertIsNone(result) diff --git a/openstackclient/tests/volume/v2/test_snapshot.py b/openstackclient/tests/volume/v2/test_snapshot.py index 349e8dac85..87e2fccfa8 100644 --- a/openstackclient/tests/volume/v2/test_snapshot.py +++ b/openstackclient/tests/volume/v2/test_snapshot.py @@ -97,11 +97,12 @@ class TestSnapshotDelete(TestSnapshot): verifylist = [ ("snapshots", [volume_fakes.snapshot_id]) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.snapshots_mock.delete.assert_called_with(volume_fakes.snapshot_id) + self.assertIsNone(result) class TestSnapshotList(TestSnapshot): @@ -231,18 +232,19 @@ class TestSnapshotSet(TestSnapshot): ("name", "new_snapshot"), ("property", new_property) ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) 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 ) + self.assertIsNone(result) class TestSnapshotShow(TestSnapshot): @@ -296,10 +298,11 @@ class TestSnapshotUnset(TestSnapshot): ("snapshot", volume_fakes.snapshot_id), ("property", ["foo"]) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + + result = self.cmd.take_action(parsed_args) self.snapshots_mock.delete_metadata.assert_called_with( volume_fakes.snapshot_id, ["foo"] ) + self.assertIsNone(result) diff --git a/openstackclient/tests/volume/v2/test_type.py b/openstackclient/tests/volume/v2/test_type.py index 1408b9d93c..b014706b69 100644 --- a/openstackclient/tests/volume/v2/test_type.py +++ b/openstackclient/tests/volume/v2/test_type.py @@ -137,11 +137,12 @@ class TestTypeDelete(TestType): verifylist = [ ("volume_type", volume_fakes.type_id) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.types_mock.delete.assert_called_with(volume_fakes.type_id) + self.assertIsNone(result) class TestTypeList(TestType): @@ -227,7 +228,7 @@ class TestTypeSet(TestType): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) # Set expected values kwargs = { @@ -237,6 +238,7 @@ class TestTypeSet(TestType): volume_fakes.type_id, **kwargs ) + self.assertIsNone(result) def test_type_set_description(self): new_desc = 'new_desc' @@ -252,7 +254,7 @@ class TestTypeSet(TestType): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) # Set expected values kwargs = { @@ -262,6 +264,7 @@ class TestTypeSet(TestType): volume_fakes.type_id, **kwargs ) + self.assertIsNone(result) def test_type_set_property(self): arglist = [ @@ -276,7 +279,8 @@ class TestTypeSet(TestType): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.assertIsNone(result) result = self.types_mock.get.return_value._keys self.assertIn('myprop', result) @@ -338,8 +342,8 @@ class TestTypeUnset(TestType): parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.assertIsNone(result) result = self.types_mock.get.return_value._keys - self.assertNotIn('property', result) diff --git a/openstackclient/tests/volume/v2/test_volume.py b/openstackclient/tests/volume/v2/test_volume.py index cbca09b286..a836f79ec6 100644 --- a/openstackclient/tests/volume/v2/test_volume.py +++ b/openstackclient/tests/volume/v2/test_volume.py @@ -396,11 +396,12 @@ class TestVolumeDelete(TestVolume): verifylist = [ ("volumes", [volumes[0].id]) ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) + self.volumes_mock.delete.assert_called_with(volumes[0].id) + self.assertIsNone(result) def test_volume_delete_multi_volumes(self): volumes = self.setup_volumes_mock(count=3) @@ -409,14 +410,13 @@ class TestVolumeDelete(TestVolume): verifylist = [ ('volumes', arglist), ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.cmd.take_action(parsed_args) + result = self.cmd.take_action(parsed_args) calls = [call(v.id) for v in volumes] - self.volumes_mock.delete.assert_has_calls(calls) + self.assertIsNone(result) class TestVolumeList(TestVolume):