Skip to content

Commit

Permalink
Adds human review to experimental alerts (#229)
Browse files Browse the repository at this point in the history
* Adds human review to experimental alerts

* Automatically reformatting code

---------

Co-authored-by: Auto-format Bot <[email protected]>
  • Loading branch information
brandon-groundlight and Auto-format Bot authored Jul 31, 2024
1 parent af19a50 commit d0d975c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/groundlight/experimental_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def create_rule( # pylint: disable=too-many-locals # noqa: PLR0913
snooze_time_enabled: bool = False,
snooze_time_value: int = 3600,
snooze_time_unit: str = "SECONDS",
human_review_required: bool = False,
) -> Rule:
"""
Adds a notification rule to the given detector
Expand All @@ -72,6 +73,7 @@ def create_rule( # pylint: disable=too-many-locals # noqa: PLR0913
will be delivered until the snooze time has passed
:param snooze_time_value: The value of the snooze time
:param snooze_time_unit: The unit of the snooze time
:param huamn_review_required: If true, a cloud labeler will review and confirm alerts before they are sent
:return: a Rule object corresponding to the new rule
"""
Expand Down Expand Up @@ -99,6 +101,7 @@ def create_rule( # pylint: disable=too-many-locals # noqa: PLR0913
snooze_time_enabled=snooze_time_enabled,
snooze_time_value=snooze_time_value,
snooze_time_unit=snooze_time_unit,
human_review_required=human_review_required,
)
return Rule.model_validate(self.actions_api.create_rule(det_id, rule_input).to_dict())

Expand Down
16 changes: 13 additions & 3 deletions test/unit/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@


def test_create_action(gl: ExperimentalApi):
# We first clear out any rules in case the account has any left over from a previous test
gl.delete_all_rules()
# use a unique name for the alert
name = f"Test {datetime.utcnow()}"
det = gl.get_or_create_detector(name, "test_query")
rule = gl.create_rule(det, "test_rule", "EMAIL", "[email protected]")
rule = gl.create_rule(det, f"test_rule_{name}", "EMAIL", "[email protected]")
rule2 = gl.get_rule(rule.id)
assert rule == rule2
gl.delete_rule(rule.id)
Expand All @@ -35,3 +34,14 @@ def test_get_all_actions(gl: ExperimentalApi):
assert num_deleted == num_test_rules
rules = gl.list_rules()
assert rules.count == 0


def test_create_action_with_human_review(gl: ExperimentalApi):
name = f"Test {datetime.utcnow()}"
det = gl.get_or_create_detector(name, "test_query")
rule = gl.create_rule(det, f"test_rule_{name}", "EMAIL", "[email protected]", human_review_required=True)
rule2 = gl.get_rule(rule.id)
assert rule == rule2
gl.delete_rule(rule.id)
with pytest.raises(NotFoundException) as _:
gl.get_rule(rule.id)

0 comments on commit d0d975c

Please sign in to comment.