Add PUT method to connector
Add PUT method for sushy connector class that will help extensions to make PUT requests where POST/PATCH is not supported. Change-Id: Ibdd2c819847202eac62c75eb5e73686b22d1ece4
This commit is contained in:
parent
c8dcd357d8
commit
53e0725b5d
|
@ -113,6 +113,18 @@ class Connector(object):
|
|||
"""
|
||||
return self._op('PATCH', path, data, headers)
|
||||
|
||||
def put(self, path='', data=None, headers=None):
|
||||
"""HTTP PUT method.
|
||||
|
||||
:param path: Optional sub-URI path to the resource.
|
||||
:param data: Optional JSON data.
|
||||
:param headers: Optional dictionary of headers.
|
||||
:returns: The response object from the requests library.
|
||||
:raises: ConnectionError
|
||||
:raises: HTTPError
|
||||
"""
|
||||
return self._op('PUT', path, data, headers)
|
||||
|
||||
def delete(self, path='', data=None, headers=None):
|
||||
"""HTTP DELETE method.
|
||||
|
||||
|
|
|
@ -55,6 +55,13 @@ class ConnectorMethodsTestCase(base.TestCase):
|
|||
mock__op.assert_called_once_with(mock.ANY, 'PATCH', 'fake/path',
|
||||
self.data, self.headers)
|
||||
|
||||
@mock.patch.object(connector.Connector, '_op', autospec=True)
|
||||
def test_put(self, mock__op):
|
||||
self.conn.put(path='fake/path', data=self.data.copy(),
|
||||
headers=self.headers.copy())
|
||||
mock__op.assert_called_once_with(mock.ANY, 'PUT', 'fake/path',
|
||||
self.data, self.headers)
|
||||
|
||||
@mock.patch.object(connector.Connector, '_op', autospec=True)
|
||||
def test_delete(self, mock__op):
|
||||
self.conn.delete(path='fake/path', data=self.data.copy(),
|
||||
|
@ -95,6 +102,16 @@ class ConnectorOpTestCase(base.TestCase):
|
|||
'POST', 'http://foo.bar:1234/fake/path',
|
||||
data=json.dumps(self.data), headers=expected_headers)
|
||||
|
||||
def test_ok_put(self):
|
||||
expected_headers = self.headers.copy()
|
||||
expected_headers['Content-Type'] = 'application/json'
|
||||
|
||||
self.conn._op('PUT', path='fake/path', data=self.data.copy(),
|
||||
headers=self.headers)
|
||||
self.request.assert_called_once_with(
|
||||
'PUT', 'http://foo.bar:1234/fake/path',
|
||||
data=json.dumps(self.data), headers=expected_headers)
|
||||
|
||||
def test_ok_delete(self):
|
||||
expected_headers = self.headers.copy()
|
||||
|
||||
|
|
Loading…
Reference in New Issue