Merge "Add DELETE method to connector"

This commit is contained in:
Jenkins 2017-07-28 08:23:04 +00:00 committed by Gerrit Code Review
commit 43cfd0742e
2 changed files with 27 additions and 0 deletions

View File

@ -113,6 +113,18 @@ class Connector(object):
"""
return self._op('PATCH', path, data, headers)
def delete(self, path='', data=None, headers=None):
"""HTTP DELETE 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('DELETE', path, data, headers)
def __enter__(self):
return self

View File

@ -51,6 +51,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_delete(self, mock__op):
self.conn.delete(path='fake/path', data=self.data.copy(),
headers=self.headers.copy())
mock__op.assert_called_once_with(mock.ANY, 'DELETE', 'fake/path',
self.data, self.headers)
class ConnectorOpTestCase(base.TestCase):
@ -84,6 +91,14 @@ class ConnectorOpTestCase(base.TestCase):
'POST', 'http://foo.bar:1234/fake/path',
data=json.dumps(self.data), headers=expected_headers)
def test_ok_delete(self):
expected_headers = self.headers.copy()
self.conn._op('DELETE', path='fake/path', headers=self.headers.copy())
self.request.assert_called_once_with(
'DELETE', 'http://foo.bar:1234/fake/path',
data=None, headers=expected_headers)
def test_connection_error(self):
self.request.side_effect = requests.exceptions.ConnectionError
self.assertRaises(exceptions.ConnectionError, self.conn._op, 'GET')