Skip to content

Commit

Permalink
Fix responses with 204 status codes (#108)
Browse files Browse the repository at this point in the history
* Don't try to json 204 responses and add test to make sure they succeed

* Bump version number
  • Loading branch information
eengoron authored Dec 9, 2020
1 parent e24601c commit b5c7dca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion closeio_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# To update the package version, change this variable. This variable is also
# read by setup.py when installing the package.
__version__ = '1.3'
__version__ = '1.4'

class APIError(Exception):
"""Raised when sending a request to the API failed."""
Expand Down Expand Up @@ -132,6 +132,9 @@ def _dispatch(self, method_name, endpoint, api_key=None, data=None,
break

if response.ok:
# 204 responses have no content.
if response.status_code == 204:
return ''
return response.json()
elif response.status_code == 400:
raise ValidationError(response)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,13 @@ def test_validation_error(api_client):
err = excinfo.value
assert err.errors == []
assert err.field_errors['lead'] == 'This field is required.'

@responses.activate
def test_204_responses(api_client):
responses.add(
responses.DELETE,
"https://api.close.com/api/v1/pipeline/pipe_1234/",
status=204
)
resp = api_client.delete('pipeline/pipe_1234')
assert resp == ''

0 comments on commit b5c7dca

Please sign in to comment.