Skip to content

Commit 2b1cde9

Browse files
committed
fix(call): do not send body for POST/PUT operations when none were provided
Signed-off-by: Romain Beuque <556072+rbeuque74@users.noreply.github.com>
1 parent 5cfac4b commit 2b1cde9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ovh/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ def put(self, _target, _need_auth=True, **kwargs):
355355
the default
356356
"""
357357
kwargs = self._canonicalize_kwargs(kwargs)
358+
if not kwargs:
359+
kwargs = None
358360
return self.call('PUT', _target, kwargs, _need_auth)
359361

360362
def post(self, _target, _need_auth=True, **kwargs):
@@ -370,6 +372,8 @@ def post(self, _target, _need_auth=True, **kwargs):
370372
the default
371373
"""
372374
kwargs = self._canonicalize_kwargs(kwargs)
375+
if not kwargs:
376+
kwargs = None
373377
return self.call('POST', _target, kwargs, _need_auth)
374378

375379
def delete(self, _target, _need_auth=True, **kwargs):
@@ -494,7 +498,7 @@ def raw_call(self, method, path, data=None, need_auth=True):
494498
}
495499

496500
# include payload
497-
if data:
501+
if data is not None:
498502
headers['Content-type'] = 'application/json'
499503
body = json.dumps(data)
500504

tests/test_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ def test_post(self, m_call):
245245
self.assertEqual(m_call.return_value, api.post(FAKE_URL, **PAYLOAD))
246246
m_call.assert_called_once_with('POST', FAKE_URL, PAYLOAD, True)
247247

248+
@mock.patch.object(Client, 'call')
249+
def test_post_no_body(self, m_call):
250+
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET, CONSUMER_KEY)
251+
self.assertEqual(m_call.return_value, api.post(FAKE_URL))
252+
m_call.assert_called_once_with('POST', FAKE_URL, None, True)
253+
248254
@mock.patch.object(Client, 'call')
249255
def test_put(self, m_call):
250256
PAYLOAD = {
@@ -258,6 +264,12 @@ def test_put(self, m_call):
258264
self.assertEqual(m_call.return_value, api.put(FAKE_URL, **PAYLOAD))
259265
m_call.assert_called_once_with('PUT', FAKE_URL, PAYLOAD, True)
260266

267+
@mock.patch.object(Client, 'call')
268+
def test_put_no_body(self, m_call):
269+
api = Client(ENDPOINT, APPLICATION_KEY, APPLICATION_SECRET, CONSUMER_KEY)
270+
self.assertEqual(m_call.return_value, api.put(FAKE_URL))
271+
m_call.assert_called_once_with('PUT', FAKE_URL, None, True)
272+
261273
## test core function
262274

263275
@mock.patch('ovh.client.Session.request')

0 commit comments

Comments
 (0)