Add to_dict() method to Resource class

* It is needed to get full info about resource

Change-Id: I5d27d5524788ce8c3ae9f4a6ddb17430362cb943
Closes-Bug: #1479003
This commit is contained in:
Tetiana Lashchova
2015-07-30 18:36:31 +03:00
parent 9297fc7bc4
commit 133662f696
2 changed files with 12 additions and 0 deletions

View File

@@ -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))

View File

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