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"}