Replaces _create calls with _post in PlanManager
_create method was removed in https://review.openstack.org/#/c/149183/ during refactoring Manager class from Tuskar out in favor of similar class from oslo libs. This was not catched by tests due to their mocking nature. Patch also adds IsMethodOn matcher and enhaces tests for PlanManager#create and PlanManager#add_role methods by testing if _create method exists before mocking it out. Change-Id: I75257095163bd8f57d8cbaa1916c166030c03704
This commit is contained in:
@@ -68,6 +68,23 @@ class ManagerClassMismatch(object):
|
||||
return {}
|
||||
|
||||
|
||||
class IsMethodOn(object):
|
||||
"""Match if there is method with same name on object."""
|
||||
def __init__(self, obj):
|
||||
self.obj = obj
|
||||
|
||||
def __str__(self):
|
||||
return 'IsMethodOn(%s)' % (self.obj)
|
||||
|
||||
def match(self, method_name):
|
||||
result = hasattr(self.obj, method_name)
|
||||
if result:
|
||||
return None
|
||||
else:
|
||||
return testtools.matchers.Mismatch("%s is not a method on %s" %
|
||||
(method_name, self.obj))
|
||||
|
||||
|
||||
class CommandTestCase(TestCase):
|
||||
def setUp(self):
|
||||
super(CommandTestCase, self).setUp()
|
||||
|
||||
@@ -49,13 +49,14 @@ class PlanManagerTest(tutils.TestCase):
|
||||
|
||||
def test_create(self):
|
||||
"""Test creating a new plan via POST."""
|
||||
self.pm._create = mock.Mock(return_value=['fake_plan'])
|
||||
self.assertThat('_post', tutils.IsMethodOn(self.pm))
|
||||
self.pm._post = mock.Mock(return_value=['fake_plan'])
|
||||
|
||||
self.assertEqual(
|
||||
self.pm.create(dummy='dummy plan data'),
|
||||
['fake_plan'])
|
||||
|
||||
self.pm._create.assert_called_with(
|
||||
self.pm._post.assert_called_with(
|
||||
'/v2/plans',
|
||||
{'dummy': 'dummy plan data'})
|
||||
|
||||
@@ -92,11 +93,12 @@ class PlanManagerTest(tutils.TestCase):
|
||||
|
||||
def test_add_role(self):
|
||||
"""Test assigning Role to a Plan."""
|
||||
self.pm._create = mock.Mock(return_value='dummy plan')
|
||||
self.assertThat('_post', tutils.IsMethodOn(self.pm))
|
||||
self.pm._post = mock.Mock(return_value='dummy plan')
|
||||
|
||||
self.assertEqual(self.pm.add_role('42', role_uuid='qwert12345'),
|
||||
'dummy plan')
|
||||
self.pm._create.assert_called_with(
|
||||
self.pm._post.assert_called_with(
|
||||
'/v2/plans/42/roles',
|
||||
{'uuid': 'qwert12345'})
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class PlanManager(base.BaseManager):
|
||||
:return: A Plan instance or None if its not found.
|
||||
:rtype: tuskarclient.v2.plans.Plan
|
||||
"""
|
||||
return self._create(self._path(), fields)
|
||||
return self._post(self._path(), fields)
|
||||
|
||||
def patch(self, plan_uuid, attribute_list):
|
||||
"""Patch an existing Plan.
|
||||
@@ -135,7 +135,7 @@ class PlanManager(base.BaseManager):
|
||||
:return: A Plan instance or None if its not found.
|
||||
:rtype: tuskarclient.v2.plans.Plan
|
||||
"""
|
||||
return self._create(self._roles_path(plan_uuid), {'uuid': role_uuid})
|
||||
return self._post(self._roles_path(plan_uuid), {'uuid': role_uuid})
|
||||
|
||||
def remove_role(self, plan_uuid, role_uuid):
|
||||
"""Removes a Role from a Plan.
|
||||
|
||||
Reference in New Issue
Block a user