43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Tray status model: maps `status --json` to a TrayState."""
|
|
import unittest
|
|
|
|
from enodia_sentinel.tray.state import TrayState, parse_status
|
|
|
|
|
|
class TestParseStatus(unittest.TestCase):
|
|
def test_none_is_unknown_grey(self):
|
|
s = parse_status(None)
|
|
self.assertFalse(s.running)
|
|
self.assertEqual(s.color, "grey")
|
|
self.assertEqual(s.summary, "Unknown")
|
|
|
|
def test_stopped_is_grey(self):
|
|
s = parse_status({"running": False, "total_alerts": 3,
|
|
"counts": {"high": 1}})
|
|
self.assertFalse(s.running)
|
|
self.assertEqual(s.color, "grey")
|
|
self.assertEqual(s.summary, "Stopped")
|
|
|
|
def test_running_clean_is_green(self):
|
|
s = parse_status({"running": True, "total_alerts": 0, "counts": {}})
|
|
self.assertEqual(s.color, "green")
|
|
self.assertIn("no alerts", s.summary)
|
|
|
|
def test_running_with_medium_only_is_green(self):
|
|
s = parse_status({"running": True, "total_alerts": 2,
|
|
"counts": {"MEDIUM": 2}})
|
|
self.assertEqual(s.color, "green")
|
|
self.assertIn("2 alerts", s.summary)
|
|
|
|
def test_running_with_high_is_amber(self):
|
|
s = parse_status({"running": True, "total_alerts": 4,
|
|
"counts": {"HIGH": 1, "CRITICAL": 1, "MEDIUM": 2}})
|
|
self.assertEqual(s.high_alerts, 2)
|
|
self.assertEqual(s.color, "amber")
|
|
self.assertIn("high/critical", s.summary)
|
|
|
|
def test_tooltip_includes_summary(self):
|
|
s = parse_status({"running": True, "total_alerts": 0, "counts": {}})
|
|
self.assertIn(s.summary, s.tooltip)
|
|
self.assertIn("Enodia Sentinel", s.tooltip)
|