Skip to content

Commit

Permalink
Add tests to verify tag group painter and sorter registration
Browse files Browse the repository at this point in the history
Change-Id: I0653f34879e29afd0f628a54595b9ed0df12785d
  • Loading branch information
LarsMichelsen committed Jan 16, 2025
1 parent 1fb2ff4 commit 1c6f4be
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/unit/cmk/gui/painter/v0/test_host_tag_painters.py
Original file line number Diff line number Diff line change
@@ -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())
47 changes: 47 additions & 0 deletions tests/unit/cmk/gui/views/sorter/test_host_tag_sorters.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 1c6f4be

Please sign in to comment.