Files
computer-playbook/tests/unit/python/utils/roles/applications/test_dashboard.py
T
kevinveenbirkenbachandClaude Opus 5.5 c855efc30a refactor(web-app-dashboard): hide a tile through services.dashboard.enabled instead of display
services.dashboard.enabled already says whether a role takes part in the dashboard: roles_with_service lists only roles with enabled and shared as tile-reachability targets, the CSP filter adds the dashboard to frame-ancestors only when it is set, and docker_cards uses it as the card's iframe flag. A separate display key duplicated that switch and left a role with enabled false still rendering a card. docker_cards now skips the card when services.dashboard.enabled is false (a role without a dashboard binding keeps its card, and a value that is not a boolean fails loudly), so display, its validator exception and its roles_with_service filter go again; base.md documents enabled as the per-host switch.

An inventory hides a tile with applications.<role>.services.dashboard.enabled: false, which also drops the dashboard framing of that role. Unit tests cover false, true, a missing binding, a rendered string and a non-boolean; forcing the helper to always show the card fails four of them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 19:00:46 +01:00

68 lines
2.3 KiB
Python

"""Unit tests for ``utils/roles/applications/dashboard.py``."""
from __future__ import annotations
import unittest
from ansible.errors import AnsibleError
from utils.roles.applications.dashboard import card_is_displayed, card_target_key
class TestCardTargetKey(unittest.TestCase):
def test_a_binding_without_the_key_targets_the_primary_domain(self):
self.assertEqual(
"", card_target_key("web-app-foo", {"enabled": True, "shared": True})
)
def test_a_missing_binding_targets_the_primary_domain(self):
self.assertEqual("", card_target_key("web-app-foo", None))
def test_the_named_key_is_returned(self):
self.assertEqual(
"element",
card_target_key("web-app-matrix", {"card": "element"}),
)
def test_surrounding_whitespace_is_dropped(self):
self.assertEqual(
"webmail",
card_target_key("web-app-stalwart", {"card": " webmail "}),
)
def test_an_alias_canonical_key_is_not_a_card_target(self):
self.assertEqual("", card_target_key("web-svc-cdn", {"canonical": "cdn"}))
def test_an_empty_key_fails_loudly(self):
with self.assertRaisesRegex(AnsibleError, "web-app-foo"):
card_target_key("web-app-foo", {"card": " "})
def test_a_non_string_key_fails_loudly(self):
with self.assertRaises(AnsibleError):
card_target_key("web-app-foo", {"card": ["element"]})
class TestCardIsDisplayed(unittest.TestCase):
def test_a_binding_without_the_key_is_displayed(self):
self.assertTrue(card_is_displayed("web-app-foo", {"shared": True}))
def test_a_missing_binding_is_displayed(self):
self.assertTrue(card_is_displayed("web-app-foo", None))
def test_enabled_false_hides_the_card(self):
self.assertFalse(card_is_displayed("web-app-foo", {"enabled": False}))
def test_enabled_true_shows_the_card(self):
self.assertTrue(card_is_displayed("web-app-foo", {"enabled": True}))
def test_a_rendered_string_flag_is_read_as_a_boolean(self):
self.assertFalse(card_is_displayed("web-app-foo", {"enabled": "False"}))
def test_a_non_boolean_flag_fails_loudly(self):
with self.assertRaisesRegex(AnsibleError, "web-app-foo"):
card_is_displayed("web-app-foo", {"enabled": "maybe"})
if __name__ == "__main__":
unittest.main()