From 906c9986a7e85b0029f4effd6ae3e3f5ca8fbfae Mon Sep 17 00:00:00 2001 From: xiexs Date: Mon, 23 May 2016 08:28:14 -0400 Subject: [PATCH] Make __repr__ print encryption_id for VolumeEncryptionType class The self.name attribute is undefined in the VolumeEncryptionType class. Instead we should print the self.encryption_id attribute in the __repr__(). Change-Id: Ic11b45069145bbae078c8175928c5dd869bd8cb8 Partial-Bug: #1585024 --- .../unit/v1/test_volume_encryption_types.py | 18 ++++++++++++++++++ .../unit/v2/test_volume_encryption_types.py | 18 ++++++++++++++++++ cinderclient/v1/volume_encryption_types.py | 2 +- cinderclient/v3/volume_encryption_types.py | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/cinderclient/tests/unit/v1/test_volume_encryption_types.py b/cinderclient/tests/unit/v1/test_volume_encryption_types.py index 76a81c28f..e6fad933d 100644 --- a/cinderclient/tests/unit/v1/test_volume_encryption_types.py +++ b/cinderclient/tests/unit/v1/test_volume_encryption_types.py @@ -19,6 +19,13 @@ from cinderclient.tests.unit.v1 import fakes cs = fakes.FakeClient() +FAKE_ENCRY_TYPE = {'provider': 'Test', + 'key_size': None, + 'cipher': None, + 'control_location': None, + 'volume_type_id': '65922555-7bc0-47e9-8d88-c7fdbcac4781', + 'encryption_id': '62daf814-cf9b-401c-8fc8-f84d7850fb7c'} + class VolumeEncryptionTypesTest(utils.TestCase): """ @@ -98,3 +105,14 @@ class VolumeEncryptionTypesTest(utils.TestCase): cs.assert_called('DELETE', '/types/1/encryption/provider') self.assertIsInstance(result, tuple) self.assertEqual(202, result[0].status_code) + + def test___repr__(self): + """ + Unit test for VolumeEncryptionTypes.__repr__ + + Verify that one encryption type can be printed + """ + encry_type = VolumeEncryptionType(None, FAKE_ENCRY_TYPE) + self.assertEqual( + "" % FAKE_ENCRY_TYPE['encryption_id'], + repr(encry_type)) diff --git a/cinderclient/tests/unit/v2/test_volume_encryption_types.py b/cinderclient/tests/unit/v2/test_volume_encryption_types.py index ca6ceda9b..193fad81f 100644 --- a/cinderclient/tests/unit/v2/test_volume_encryption_types.py +++ b/cinderclient/tests/unit/v2/test_volume_encryption_types.py @@ -19,6 +19,13 @@ from cinderclient.tests.unit.v2 import fakes cs = fakes.FakeClient() +FAKE_ENCRY_TYPE = {'provider': 'Test', + 'key_size': None, + 'cipher': None, + 'control_location': None, + 'volume_type_id': '65922555-7bc0-47e9-8d88-c7fdbcac4781', + 'encryption_id': '62daf814-cf9b-401c-8fc8-f84d7850fb7c'} + class VolumeEncryptionTypesTest(utils.TestCase): """ @@ -114,3 +121,14 @@ class VolumeEncryptionTypesTest(utils.TestCase): self.assertIsInstance(result, tuple) self.assertEqual(202, result[0].status_code) self._assert_request_id(result) + + def test___repr__(self): + """ + Unit test for VolumeEncryptionTypes.__repr__ + + Verify that one encryption type can be printed + """ + encry_type = VolumeEncryptionType(None, FAKE_ENCRY_TYPE) + self.assertEqual( + "" % FAKE_ENCRY_TYPE['encryption_id'], + repr(encry_type)) diff --git a/cinderclient/v1/volume_encryption_types.py b/cinderclient/v1/volume_encryption_types.py index 1099bc37b..8b22c7764 100644 --- a/cinderclient/v1/volume_encryption_types.py +++ b/cinderclient/v1/volume_encryption_types.py @@ -27,7 +27,7 @@ class VolumeEncryptionType(base.Resource): encryption for a specific volume type. """ def __repr__(self): - return "" % self.name + return "" % self.encryption_id class VolumeEncryptionTypeManager(base.ManagerWithFind): diff --git a/cinderclient/v3/volume_encryption_types.py b/cinderclient/v3/volume_encryption_types.py index c4c7a6981..6faf63312 100644 --- a/cinderclient/v3/volume_encryption_types.py +++ b/cinderclient/v3/volume_encryption_types.py @@ -28,7 +28,7 @@ class VolumeEncryptionType(base.Resource): encryption for a specific volume type. """ def __repr__(self): - return "" % self.name + return "" % self.encryption_id class VolumeEncryptionTypeManager(base.ManagerWithFind):