Skip to content

Commit

Permalink
fix(GenericAPIAction): handle when the response is a no-content respo…
Browse files Browse the repository at this point in the history
…nse.

In this case, we don't try to convert the response's body into a JSON document.
  • Loading branch information
squioc committed Jun 11, 2024
1 parent 94fab9e commit 216f535
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sekoia_automation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ def run(self, arguments) -> dict | None:
if not response.ok:
self.log_request_error(url, arguments, response)
return None
return response.json()

return response.json() if response.status_code != 204 else None

def _wait_param(self) -> wait_base:
return wait_exponential(multiplier=2, min=1, max=10)
14 changes: 14 additions & 0 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@ def init_action():
assert history[0].method == "GET"
assert history[0].url == "http://base_url/resource/fake_uuid/count?param=number"

# success with no content
action = init_action()
arguments = {"uuid": "fake_uuid", "param": "number"}
with requests_mock.Mocker() as mock:
mock.get("http://base_url/resource/fake_uuid/count", status_code=204)

results: dict = action.run(arguments)

assert results == None

Check failure on line 288 in tests/test_action.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E711)

tests/test_action.py:288:27: E711 Comparison to `None` should be `cond is None`
assert mock.call_count == 1
history = mock.request_history
assert history[0].method == "GET"
assert history[0].url == "http://base_url/resource/fake_uuid/count?param=number"

# error on action.run
action = init_action()
with requests_mock.Mocker() as mock:
Expand Down

0 comments on commit 216f535

Please sign in to comment.