From 846d7724375860329ade7210358d662bd6815a37 Mon Sep 17 00:00:00 2001 From: Nate Potter Date: Tue, 25 Jul 2017 16:12:20 -0700 Subject: [PATCH] Add DELETE method to connector Add standard HTTP delete method to the sushy connector class to enable extensions that need to make use of deletion. Change-Id: I9f4c102665fc3467ba3e281f39f650018b5e190b --- sushy/connector.py | 12 ++++++++++++ sushy/tests/unit/test_connector.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/sushy/connector.py b/sushy/connector.py index debe8240..9420cccc 100644 --- a/sushy/connector.py +++ b/sushy/connector.py @@ -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 diff --git a/sushy/tests/unit/test_connector.py b/sushy/tests/unit/test_connector.py index 53b04ec0..3586175b 100644 --- a/sushy/tests/unit/test_connector.py +++ b/sushy/tests/unit/test_connector.py @@ -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')