Adds Templates class and use it

This removes ugly hack when Plan class was used.
Templates retrieval was broken after Roles instantiation
inside of Plan was added b/c API did not returned any roles
in data when asked for templates.

Change-Id: I484dac7c41cb90256aa1dee3eb997a4183635591
This commit is contained in:
Petr Blaho
2014-09-11 11:09:27 +02:00
parent 930d86af06
commit f2799bfc78
2 changed files with 13 additions and 5 deletions

View File

@@ -125,7 +125,8 @@ class PlanManagerTest(tutils.TestCase):
self.pm._get.return_value.to_dict.return_value = 'fake_templates_dict' self.pm._get.return_value.to_dict.return_value = 'fake_templates_dict'
self.assertEqual(self.pm.templates('fake_plan'), 'fake_templates_dict') self.assertEqual(self.pm.templates('fake_plan'), 'fake_templates_dict')
self.pm._get.assert_called_with('/v2/plans/fake_plan/templates') self.pm._get.assert_called_with('/v2/plans/fake_plan/templates',
obj_class=plans.Templates)
def test_roles_subresource(self): def test_roles_subresource(self):
self.pm._get = mock.Mock( self.pm._get = mock.Mock(

View File

@@ -28,6 +28,15 @@ class Plan(common_base.Resource):
self.roles = [roles.Role(None, role) for role in self.roles] self.roles = [roles.Role(None, role) for role in self.roles]
class Templates(common_base.Resource):
"""Represents sets of templates of a Plan in the Tuskar API.
:param manager: Manager object
:param info: dictionary representing resource attributes
:param loaded: prevent lazy-loading if set to True
"""
class PlanManager(base.Manager): class PlanManager(base.Manager):
"""PlanManager interacts with the Tuskar API and provides CRUD """PlanManager interacts with the Tuskar API and provides CRUD
operations for the Plan type. operations for the Plan type.
@@ -157,7 +166,5 @@ class PlanManager(base.Manager):
:rtype: dict :rtype: dict
""" """
# dirty hack as _get() will instantiate Plan with data return self._get(self._templates_path(plan_uuid),
# coming from API response body obj_class=Templates).to_dict()
# and to_dict just get what we want
return self._get(self._templates_path(plan_uuid)).to_dict()