From 1c6f4be73f6d6282f2153776daebc723124b808e Mon Sep 17 00:00:00 2001 From: Lars Michelsen Date: Mon, 13 Jan 2025 20:31:08 +0100 Subject: [PATCH] Add tests to verify tag group painter and sorter registration Change-Id: I0653f34879e29afd0f628a54595b9ed0df12785d --- .../gui/painter/v0/test_host_tag_painters.py | 47 +++++++++++++++++++ .../gui/views/sorter/test_host_tag_sorters.py | 47 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/unit/cmk/gui/painter/v0/test_host_tag_painters.py create mode 100644 tests/unit/cmk/gui/views/sorter/test_host_tag_sorters.py diff --git a/tests/unit/cmk/gui/painter/v0/test_host_tag_painters.py b/tests/unit/cmk/gui/painter/v0/test_host_tag_painters.py new file mode 100644 index 00000000000..49c28ef6f8e --- /dev/null +++ b/tests/unit/cmk/gui/painter/v0/test_host_tag_painters.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# Copyright (C) 2024 Checkmk GmbH - License: GNU General Public License v2 +# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and +# conditions defined in the file COPYING, which is part of this source code package. + +import pytest + +from cmk.utils.tags import TagConfig, TagGroupID, TagID + +from cmk.gui.config import active_config +from cmk.gui.painter.v0 import base +from cmk.gui.views import host_tag_plugins + + +@pytest.mark.usefixtures("load_config") +def test_host_tag_painter_registration(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr( + host_tag_plugins, "painter_registry", painter_registry := base.PainterRegistry() + ) + monkeypatch.setattr(base, "painter_registry", painter_registry) + + with monkeypatch.context() as m: + m.setattr( + active_config, + "tags", + TagConfig.from_config( + { + "aux_tags": [], + "tag_groups": [ + { + "id": TagGroupID("whoot"), + "topic": "Blubberei", + "tags": [ + { + "aux_tags": [], + "id": TagID("bla"), + "title": "Bla", + }, + ], + "title": "Whoot", + }, + ], + } + ), + ) + host_tag_plugins.register_tag_plugins() + assert "host_tag_whoot" in list(base.painter_registry.keys()) diff --git a/tests/unit/cmk/gui/views/sorter/test_host_tag_sorters.py b/tests/unit/cmk/gui/views/sorter/test_host_tag_sorters.py new file mode 100644 index 00000000000..b08ad0257ba --- /dev/null +++ b/tests/unit/cmk/gui/views/sorter/test_host_tag_sorters.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# Copyright (C) 2024 Checkmk GmbH - License: GNU General Public License v2 +# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and +# conditions defined in the file COPYING, which is part of this source code package. + +import pytest + +from cmk.utils.tags import TagConfig, TagGroupID, TagID + +from cmk.gui.config import active_config +from cmk.gui.views import host_tag_plugins +from cmk.gui.views.sorter import registry + + +@pytest.mark.usefixtures("load_config") +def test_host_tag_sorter_registration(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr( + host_tag_plugins, "sorter_registry", sorter_registry := registry.SorterRegistry() + ) + monkeypatch.setattr(registry, "sorter_registry", sorter_registry) + + with monkeypatch.context() as m: + m.setattr( + active_config, + "tags", + TagConfig.from_config( + { + "aux_tags": [], + "tag_groups": [ + { + "id": TagGroupID("whoot"), + "topic": "Blubberei", + "tags": [ + { + "aux_tags": [], + "id": TagID("bla"), + "title": "Bla", + }, + ], + "title": "Whoot", + }, + ], + } + ), + ) + host_tag_plugins.register_tag_plugins() + assert "host_tag_whoot" in list(registry.sorter_registry.keys())