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

fix put json req #1226

Merged
merged 2 commits into from
Dec 11, 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
2 changes: 1 addition & 1 deletion Sekoia.io/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## 2024-12-11 - 2.65.11
## 2024-12-10 - 2.65.12

### Changed

Expand Down
2 changes: 1 addition & 1 deletion Sekoia.io/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"name": "Sekoia.io",
"uuid": "92d8bb47-7c51-445d-81de-ae04edbb6f0a",
"slug": "sekoia.io",
"version": "2.65.11",
"version": "2.65.12",
"categories": [
"Generic"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ def get_assets(search_query: str, also_search_in_detection_properties: bool = Fa

def post_request(endpoint: str, json_data: str) -> Dict[str, Any]:
api_path = urljoin(base_url + "/", endpoint)
response = session.post(api_path, json=json_data)
response = session.post(api_path, data=json_data)
if not response.ok:
self.error(f"HTTP POST request failed: {api_path} with status code {response.status_code}")
return response.json()

def put_request(endpoint: str, json_data: str) -> None:
api_path = urljoin(base_url + "/", endpoint)
response = session.put(api_path, json=json_data)
response = session.put(api_path, data=json_data)
# print(f"\nresponse.status_code: {response.status_code}")
if not response.ok:
self.error(f"HTTP PUT request failed: {api_path} with status code {response.status_code}")

Expand Down
29 changes: 25 additions & 4 deletions Sekoia.io/tests/operation_center_action/test_synchronize_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def match_detection_properties(request):
"atoms": {"email": ["[email protected]"], "department": ["engineering"]},
"community_uuid": "community-1234",
}
assert post_request.json() == json.dumps(expected_post_payload), "POST request payload mismatch."
assert post_request.json() == expected_post_payload, "POST request payload mismatch."

def test_on_asset_found_and_merge(self, requests_mock, action_instance, arguments):
def test_one_asset_found_and_merge(self, requests_mock, action_instance, arguments):
"""
Test the SynchronizeAssetsWithAD action for the scenario where multiple assets are found,
and one of them is edited while merging the others.
Expand Down Expand Up @@ -244,7 +244,7 @@ def match_detection_properties(request):
"props": {"dept": "engineering"},
"atoms": {"email": ["[email protected]"], "department": ["engineering"]},
}
assert put_request.json() == json.dumps(expected_put_payload), "PUT request payload mismatch."
assert put_request.json() == expected_put_payload, "PUT request payload mismatch."

def test_multiple_assets_found_and_merge(self, requests_mock, action_instance, arguments):
"""
Expand Down Expand Up @@ -351,7 +351,7 @@ def match_detection_properties(request):
"props": {"dept": "engineering"},
"atoms": {"email": ["[email protected]"], "department": ["engineering"]},
}
assert put_request.json() == json.dumps(expected_put_payload), "PUT request payload mismatch."
assert put_request.json() == expected_put_payload, "PUT request payload mismatch."

# Verify POST merge request payload
post_merge_requests = [
Expand All @@ -368,3 +368,24 @@ def match_detection_properties(request):

# Assert 'sources' list contains the same elements, regardless of order
assert set(post_merge["sources"]) == set(expected_merge_payload["sources"]), "Sources mismatch."

# def test_one_asset_found_and_merge_testapp(self):
# # Extract configuration from the mock module
# base_url = "https://app.test.sekoia.io"
# api_key = "TO_ADD"

# app_test_arg = Arguments( # TO COMPLETE
# user_ad_data={},
# asset_synchronization_configuration={},
# community_uuid="",
# )

# configuration = {
# "base_url": base_url,
# "api_key": api_key,
# }
# module = MockModule(configuration=configuration)
# action = SynchronizeAssetsWithAD()
# action.module = module
# # Execute the action
# response = action.run(app_test_arg)
Loading