Skip to content

Commit

Permalink
Add list to validate response
Browse files Browse the repository at this point in the history
  • Loading branch information
TOUFIKIzakarya committed Dec 3, 2024
1 parent e156e6b commit 2fb3e92
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 1.18.2 - 2024-12-03

### Add

- Add the support to list type for action response

## 1.18.1 - 2024-12-03

### Add
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "sekoia-automation-sdk"

version = "1.18.1"
version = "1.18.2"
description = "SDK to create Sekoia.io playbook modules"
license = "MIT"
readme = "README.md"
Expand Down
10 changes: 10 additions & 0 deletions sekoia_automation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ def validate_results(self):
except Exception:
sentry_sdk.capture_exception()

# Add a check for list
if isinstance(self._results, list):
for result in self._results:
if isinstance(result, dict):
try:
orjson.dumps(result)
except Exception:
sentry_sdk.capture_exception()

Check warning on line 222 in sekoia_automation/action.py

View check run for this annotation

Codecov / codecov/patch

sekoia_automation/action.py#L221-L222

Added lines #L221 - L222 were not covered by tests
return

# If we reached this point, the results are invalid
self._error = f"Results are invalid: '{self._results}'"
self._results = None
Expand Down
18 changes: 18 additions & 0 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ def test_validate_results_none():
assert action.error_message is None


def test_validate_list_results(mock_volume):
class ListAction(Action):
def run(self, arguments):
return [{"key1": "value1"}, {"key2": "value2"}]

action = ListAction()

with requests_mock.Mocker() as rmock:
rmock.patch(FAKE_URL)

action.execute()

assert rmock.last_request.json()["results"] == [
{"key1": "value1"},
{"key2": "value2"},
]


def test_action_results_invalid(mock_volume):
class TestAction(Action):
def run(self, arguments):
Expand Down

0 comments on commit 2fb3e92

Please sign in to comment.