Skip to content

Commit

Permalink
fix(quick_setup): notification count limit
Browse files Browse the repository at this point in the history
CMK-22121

Change-Id: Ib9f43b343b57126432a664c7ae650ca7519af036
  • Loading branch information
logan-connolly committed Feb 28, 2025
1 parent e179634 commit f143d5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 42 deletions.
14 changes: 10 additions & 4 deletions cmk/gui/wato/pages/notifications/quick_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,10 +1470,16 @@ def _get_time_periods() -> list[tuple[TimeperiodName, str]]:

def validate_notification_count_values(values: tuple[object, ...]) -> None:
match values:
case (int() as lower_value, int() as upper_value) if lower_value >= upper_value:
raise ValidationError(
Message("The first value must be lower than the second value."),
)
case (int(lower_bound), _) if lower_bound < 1:
raise ValidationError(Message("The lower bound must be greater than 0."))
case (_, int(upper_bound)) if upper_bound < 1:
raise ValidationError(Message("The upper bound must be greater than 0."))
case (int(lower_bound), int(upper_bound)) if lower_bound > upper_bound:
raise ValidationError(Message("Lower bound cannot be higher than upper bound."))
case (int(_), int(_)):
return
case _:
raise ValidationError(Message("Unexpected notification count values passed."))


def validate_throttling_values(values: tuple[object, ...]) -> None:
Expand Down
46 changes: 8 additions & 38 deletions tests/unit/cmk/gui/quick_setup/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def test_validate_throttling_values_raises(payload: tuple[int, ...]) -> None:
"payload",
[
pytest.param((1, 2), id="second value is greater than first"),
pytest.param(
(1, 1),
marks=pytest.mark.xfail(reason="this should be allowed"),
id="values are the same",
),
pytest.param((1, 1), id="values are the same"),
],
)
def test_validate_notification_count_values(payload: tuple[int, ...]) -> None:
Expand All @@ -58,39 +54,13 @@ def test_validate_notification_count_values(payload: tuple[int, ...]) -> None:
@pytest.mark.parametrize(
"payload",
[
pytest.param(
tuple(),
marks=pytest.mark.xfail(reason="this should raise"),
id="no arguments provided",
),
pytest.param(
(0, 1),
marks=pytest.mark.xfail(reason="this should raise"),
id="zero is invalid lower bound",
),
pytest.param(
(0, 0),
id="zero is invalid upper bound",
),
pytest.param(
(2, 1),
id="second value less than first",
),
pytest.param(
("foo", 2),
marks=pytest.mark.xfail(reason="this should raise"),
id="first value is the wrong type",
),
pytest.param(
(1, "bar"),
marks=pytest.mark.xfail(reason="this should raise"),
id="second value is wrong type",
),
pytest.param(
(1, 2, 3),
marks=pytest.mark.xfail(reason="this should raise"),
id="we only expect two inputs",
),
pytest.param(tuple(), id="no arguments provided"),
pytest.param((0, 1), id="zero is invalid lower bound"),
pytest.param((0, 0), id="zero is invalid upper bound"),
pytest.param((2, 1), id="second value less than first"),
pytest.param(("foo", 2), id="first value is the wrong type"),
pytest.param((1, "bar"), id="second value is wrong type"),
pytest.param((1, 2, 3), id="we only expect two inputs"),
],
)
def test_validate_notification_count_values_raises(payload: tuple[int, ...]) -> None:
Expand Down

0 comments on commit f143d5d

Please sign in to comment.