From 216f535c98c1c128dfbc986e8a8769771bfb6a63 Mon Sep 17 00:00:00 2001 From: Sebastien Quioc Date: Tue, 11 Jun 2024 09:27:18 +0200 Subject: [PATCH] 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: