Skip to content

Commit b5c7dca

Browse files
authored
Fix responses with 204 status codes (#108)
* Don't try to json 204 responses and add test to make sure they succeed * Bump version number
1 parent e24601c commit b5c7dca

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

closeio_api/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

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

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

134134
if response.ok:
135+
# 204 responses have no content.
136+
if response.status_code == 204:
137+
return ''
135138
return response.json()
136139
elif response.status_code == 400:
137140
raise ValidationError(response)

tests/test_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,13 @@ def test_validation_error(api_client):
163163
err = excinfo.value
164164
assert err.errors == []
165165
assert err.field_errors['lead'] == 'This field is required.'
166+
167+
@responses.activate
168+
def test_204_responses(api_client):
169+
responses.add(
170+
responses.DELETE,
171+
"https://api.close.com/api/v1/pipeline/pipe_1234/",
172+
status=204
173+
)
174+
resp = api_client.delete('pipeline/pipe_1234')
175+
assert resp == ''

0 commit comments

Comments
 (0)