Skip to content

Commit 159cf51

Browse files
authored
Merge pull request #85 from amartinunowhy/fix/empty-post-error
fix: Don't post data if no arguments were passed.
2 parents 478eb50 + 2b1cde9 commit 159cf51

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ovh/client.py

Lines changed: 4 additions & 0 deletions
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):

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)