From d0d975c131701927a4563fd83d01541e35c8c836 Mon Sep 17 00:00:00 2001 From: Brandon <132288221+brandon-groundlight@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:38:29 -0700 Subject: [PATCH] Adds human review to experimental alerts (#229) * Adds human review to experimental alerts * Automatically reformatting code --------- Co-authored-by: Auto-format Bot --- src/groundlight/experimental_api.py | 3 +++ test/unit/test_actions.py | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/groundlight/experimental_api.py b/src/groundlight/experimental_api.py index ff44ca01..daf57cd4 100644 --- a/src/groundlight/experimental_api.py +++ b/src/groundlight/experimental_api.py @@ -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 @@ -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 """ @@ -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()) diff --git a/test/unit/test_actions.py b/test/unit/test_actions.py index 4c0c10ae..0600ec1e 100644 --- a/test/unit/test_actions.py +++ b/test/unit/test_actions.py @@ -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", "test@example.com") + rule = gl.create_rule(det, f"test_rule_{name}", "EMAIL", "test@example.com") rule2 = gl.get_rule(rule.id) assert rule == rule2 gl.delete_rule(rule.id) @@ -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", "test@example.com", 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)