test(alerts): the history row test's rule names its metric (#5212)
Run 8504 failed unit: tests/core/test_alert_history_row.py built a rule with no metric_name, which _history_row now reads to say the reading in words. The rule now names cpu_pct, and the value and condition asserts expect "CPU 98%", "No CPU reading" and "CPU > 90%", plus an up/down case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ from steward.alerts.routes import _history_row
|
||||
from steward.core.alerts import MUTED, RELEASED
|
||||
from steward.models.alerts import AlertOperator
|
||||
|
||||
RULE = SimpleNamespace(operator=AlertOperator(">"), threshold=90.0)
|
||||
RULE = SimpleNamespace(metric_name="cpu_pct", operator=AlertOperator(">"), threshold=90.0)
|
||||
|
||||
|
||||
def _event(**kw):
|
||||
@@ -32,10 +32,14 @@ def test_notes_split_into_mute_release_and_the_rest(note, notes, muted_by, relea
|
||||
assert (row["notes"], row["muted_by"], row["released"]) == (notes, muted_by, released)
|
||||
|
||||
|
||||
def test_value_and_condition():
|
||||
assert _history_row(_event(), RULE)["value"] == "97.5"
|
||||
assert _history_row(_event(metric_value=None), RULE)["value"] == "no data"
|
||||
assert _history_row(_event(), RULE)["condition"] == "> 90"
|
||||
def test_value_and_condition_read_in_words():
|
||||
"""#5212: the metric's name and unit, not "cpu_pct = 97.5" and "> 90"."""
|
||||
assert _history_row(_event(), RULE)["value"] == "CPU 98%"
|
||||
assert _history_row(_event(metric_value=None), RULE)["value"] == "No CPU reading"
|
||||
assert _history_row(_event(), RULE)["condition"] == "CPU > 90%"
|
||||
down = SimpleNamespace(metric_name="is_up", operator=AlertOperator("<"), threshold=0.5)
|
||||
row = _history_row(_event(metric_value=0.0), down)
|
||||
assert (row["value"], row["condition"]) == ("Down", "is down")
|
||||
|
||||
|
||||
def test_only_attempted_deliveries_are_listed():
|
||||
|
||||
Reference in New Issue
Block a user