From 216f535c98c1c128dfbc986e8a8769771bfb6a63 Mon Sep 17 00:00:00 2001 From: Sebastien Quioc Date: Tue, 11 Jun 2024 09:27:18 +0200 Subject: [PATCH 1/3] fix(GenericAPIAction): handle when the response is a no-content response. In this case, we don't try to convert the response's body into a JSON document. --- sekoia_automation/action.py | 3 ++- tests/test_action.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sekoia_automation/action.py b/sekoia_automation/action.py index 0008569..a02e9c8 100644 --- a/sekoia_automation/action.py +++ b/sekoia_automation/action.py @@ -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) diff --git a/tests/test_action.py b/tests/test_action.py index 4d47409..2ee300a 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -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 + 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: From 797ce99b9e26bf6c78f09e81cea90d13cbc986d9 Mon Sep 17 00:00:00 2001 From: Sebastien Quioc Date: Tue, 11 Jun 2024 09:46:42 +0200 Subject: [PATCH 2/3] fix(Action): apply ruff --- tests/test_action.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_action.py b/tests/test_action.py index 2ee300a..f7f20c1 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -285,7 +285,7 @@ def init_action(): results: dict = action.run(arguments) - assert results == None + assert results is None assert mock.call_count == 1 history = mock.request_history assert history[0].method == "GET" From 320ec9c9210959f72bb536ff29249c78cea089f2 Mon Sep 17 00:00:00 2001 From: Sebastien Quioc Date: Tue, 11 Jun 2024 09:47:00 +0200 Subject: [PATCH 3/3] chore: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20ff36f..2ee503f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.13.0] - 2024-04-22 ### Changed