From 133662f69666cb94cafee57b604d4d40b608f9a2 Mon Sep 17 00:00:00 2001 From: Tetiana Lashchova Date: Thu, 30 Jul 2015 18:36:31 +0300 Subject: [PATCH] Add to_dict() method to Resource class * It is needed to get full info about resource Change-Id: I5d27d5524788ce8c3ae9f4a6ddb17430362cb943 Closes-Bug: #1479003 --- saharaclient/api/base.py | 4 ++++ saharaclient/tests/unit/test_resource.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/saharaclient/api/base.py b/saharaclient/api/base.py index 6e82f9d4..add56214 100644 --- a/saharaclient/api/base.py +++ b/saharaclient/api/base.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import copy import json import logging @@ -49,6 +50,9 @@ class Resource(object): # In this case we already defined the attribute on the class pass + def to_dict(self): + return copy.deepcopy(self._info) + def __str__(self): return '%s %s' % (self.resource_name, str(self._info)) diff --git a/saharaclient/tests/unit/test_resource.py b/saharaclient/tests/unit/test_resource.py index d6dbe054..b1510ba6 100644 --- a/saharaclient/tests/unit/test_resource.py +++ b/saharaclient/tests/unit/test_resource.py @@ -41,6 +41,14 @@ class ResourceTest(testtools.TestCase): self.assertIsNotNone(resource) self.assertEqual(dict_copy, dict) + def test_to_dict(self): + dict = {"name": "test"} + resource = test_base.TestResource(None, dict) + self.assertEqual({'description': 'Test Description', + 'extra': 'extra', + 'name': 'test'}, + resource.to_dict()) + def test_resource_str(self): dict = {"name": "test", "description": "Changed Description"}