Skip to content

Commit

Permalink
Feature/alerts aggregate data (#319)
Browse files Browse the repository at this point in the history
* added method get_aggregate_data to alerts

* added tests

* added changelog

* fix style

* fix docs tense
  • Loading branch information
kiran-chaudhary committed Apr 15, 2021
1 parent 27263f9 commit cc8b303
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta

- `sdk.alerts.search()` accepts optional `page_num` and `page_size` arguments.

- `sdk.alerts.get_aggregate_data()` to get alert summary and observations.

## 1.13.0 - 2021-04-14

### Added
Expand Down
11 changes: 11 additions & 0 deletions src/py42/clients/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,14 @@ def update_note(self, alert_id, note):
:class:`py42.response.Py42Response`
"""
return self._alert_service.update_note(alert_id, note)

def get_aggregate_data(self, alert_id):
"""Gets alert summary with details about observations.
Args:
alert_id (str): Gets the details for the alert with the given ID.
Returns:
:class:`py42.response.Py42Response`
"""
return self._alert_service.get_aggregate_data(alert_id)
7 changes: 7 additions & 0 deletions src/py42/services/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def update_note(self, alert_id, note):
}
return self._connection.post(uri, json=data)

def get_aggregate_data(self, alert_id):
uri = self._uri_prefix.format(u"query-details-aggregate")
data = {
u"alertId": alert_id,
}
return self._connection.post(uri, json=data)


def _convert_observation_json_strings_to_objects(results):
for alert in results[u"alerts"]:
Expand Down
7 changes: 7 additions & 0 deletions tests/clients/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ def test_alerts_client_calls_search_all_pages_with_expected_value_and_param(
query = '{"test": "data"}}'
alert_client.search_all_pages(query)
mock_alerts_service.search_all_pages.assert_called_once_with(query)

def test_alerts_client_calls_get_aggregate_data_with_expected_value_and_param(
self, mock_alerts_service, mock_alert_rules_service,
):
alert_client = AlertsClient(mock_alerts_service, mock_alert_rules_service)
alert_client.get_aggregate_data("alert-id")
mock_alerts_service.get_aggregate_data.assert_called_once_with("alert-id")
12 changes: 12 additions & 0 deletions tests/services/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,15 @@ def test_search_posts_expected_data_overwrites_default_option_when_passed_page_n
and post_data["groups"][0]["filters"][0]["term"] == "state"
and post_data["groups"][0]["filters"][0]["value"] == "OPEN"
)

def test_get_aggregate_data_calls_post_with_expected_url_and_data(
self, mock_connection, user_context
):
alert_service = AlertService(mock_connection, user_context)
alert_service.get_aggregate_data("alert-id")
assert (
mock_connection.post.call_args[0][0]
== "/svc/api/v1/query-details-aggregate"
)
post_data = mock_connection.post.call_args[1]["json"]
assert post_data["alertId"] == "alert-id"

0 comments on commit cc8b303

Please sign in to comment.