Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action: handle no-content response #125

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- For GenericAPIAction, handle when the response is a no content response

## [1.14.0] - 2024-08-30

### Added
Expand Down
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 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
Loading