Implements _patch() method for Manager class
Implements _patch() method for Manager class which calls api.json_request() with proper paremeters and returns resource class instance from body (if any). Adds simple test for _patch() method. Change-Id: I643fc35cf3aa8dec47cb93eae830a0ed2a50db8a
This commit is contained in:
@@ -112,3 +112,8 @@ class Manager(object):
|
||||
|
||||
def _delete(self, url):
|
||||
self.api.raw_request('DELETE', url)
|
||||
|
||||
def _patch(self, url, body, response_key=None):
|
||||
resp, body = self.api.json_request('PATCH', url, body=body)
|
||||
if body:
|
||||
return self.resource_class(self, body)
|
||||
|
||||
@@ -43,6 +43,20 @@ class ManagerTest(tutils.TestCase):
|
||||
obj_class='obj_class',
|
||||
body='body', expect_single=True)
|
||||
|
||||
def test_patch(self):
|
||||
fake_response = mock.Mock()
|
||||
|
||||
self.m.resource_class = mock.Mock(
|
||||
return_value='fake_resource_class_instance')
|
||||
|
||||
self.m.api.json_request = mock.Mock(
|
||||
return_value=(fake_response, 'fake_body'))
|
||||
got = self.m._patch('url', 'body', response_key='response_key')
|
||||
|
||||
self.assertEqual('fake_resource_class_instance', got)
|
||||
self.m.api.json_request.assert_called_with('PATCH', 'url', body='body')
|
||||
self.m.resource_class.assert_called_with(self.m, 'fake_body')
|
||||
|
||||
def test_path(self):
|
||||
self.assertRaises(NotImplementedError, self.m._path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user