feat: add operational panel presentation helpers

This commit is contained in:
gti
2026-09-22 16:59:05 -03:00
parent 9f1c259c3e
commit 0846b9d1b0
6 changed files with 174 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
from datetime import datetime, timedelta, timezone
from types import SimpleNamespace
from central.app.panel_presentation import (
format_age,
format_duration,
format_ui_datetime,
health_label,
operational_priority,
)
def test_ui_times_use_configured_timezone_and_human_age(monkeypatch):
monkeypatch.setenv("UI_TIMEZONE", "America/Bahia")
value = datetime(2026, 9, 22, 19, 11, tzinfo=timezone.utc)
assert format_ui_datetime(value) == "22/09/2026 16:11"
assert format_age(value, datetime(2026, 9, 22, 19, 19, tzinfo=timezone.utc)) == "há 8 min"
def test_ui_datetime_treats_naive_values_as_utc():
value = datetime(2026, 9, 22, 19, 11)
assert format_ui_datetime(value) == "22/09/2026 16:11"
def test_age_handles_empty_and_future_values():
now = datetime(2026, 9, 22, 19, 19, tzinfo=timezone.utc)
assert format_age(None, now) == "-"
assert format_age(now + timedelta(minutes=1), now) == "agora"
assert format_age(now - timedelta(hours=2), now) == "há 2 h"
def test_duration_and_priority_are_deterministic():
start = datetime(2026, 9, 22, 19, 0, tzinfo=timezone.utc)
finish = start + timedelta(seconds=194)
assert format_duration(None, finish) == "-"
assert format_duration(start, None) == "em andamento"
assert format_duration(start, finish) == "3 min 14 s"
assert operational_priority(SimpleNamespace(blocker_type="TECHNICAL_FAILURE", field="", reason_code="X")) == "CRITICAL"
def test_health_label_maps_known_states_and_preserves_unknown_states():
assert health_label("ONLINE") == "Online"
assert health_label("DEGRADED") == "Degradado"
assert health_label("OFFLINE") == "Offline"
assert health_label("FAILED") == "Falha"
assert health_label("UNKNOWN") == "Desconhecido"
assert health_label("NEW_STATE") == "NEW_STATE"