Esempio n. 1
0
def test_legacy_register_rulegroup_with_defaults(monkeypatch):
    monkeypatch.setattr(attrs, "host_attribute_registry", attrs.HostAttributeRegistry())

    assert "lat" not in attrs.host_attribute_registry

    cmk.gui.wato.declare_host_attribute(
        cmk.gui.wato.NagiosTextAttribute(
            "lat",
            "_LAT",
            "Latitude",
            "Latitude",
        ),)

    attr = attrs.host_attribute_registry["lat"]()
    assert isinstance(attr, attrs.ABCHostAttributeNagiosText)
    assert attr.show_in_table() is True
    assert attr.show_in_folder() is True
    assert attr.show_in_host_search() is True
    assert attr.show_in_form() is True
    assert attr.topic() == attrs.HostAttributeTopicBasicSettings
    assert attr.depends_on_tags() == []
    assert attr.depends_on_roles() == []
    assert attr.editable() is True
    assert attr.show_inherited_value() is True
    assert attr.may_edit() is True
    assert attr.from_config() is False
Esempio n. 2
0
def test_legacy_register_rulegroup_without_defaults(monkeypatch):
    monkeypatch.setattr(attrs, "host_attribute_registry",
                        attrs.HostAttributeRegistry())

    assert "lat" not in attrs.host_attribute_registry

    cmk.gui.wato.declare_host_attribute(
        cmk.gui.wato.NagiosTextAttribute(
            "lat",
            "_LAT",
            "Latitude",
            "Latitude",
        ),
        show_in_table=False,
        show_in_folder=False,
        show_in_host_search=False,
        topic="Xyz",
        show_in_form=False,
        depends_on_tags=["xxx"],
        depends_on_roles=["guest"],
        editable=False,
        show_inherited_value=False,
        may_edit=lambda: False,
        from_config=True,
    )

    topic = attrs.host_attribute_topic_registry["xyz"]()
    assert topic.title == "Xyz"
    assert topic.sort_index == 80

    attr = attrs.host_attribute_registry["lat"]()
    assert isinstance(attr, attrs.ABCHostAttributeNagiosText)
    assert attr.show_in_table() is False
    assert attr.show_in_folder() is False
    assert attr.show_in_host_search() is False
    assert attr.show_in_form() is False

    assert attr.topic()().title == "Xyz"
    assert attr.depends_on_tags() == ["xxx"]
    assert attr.depends_on_roles() == ["guest"]
    assert attr.editable() is False
    assert attr.show_inherited_value() is False
    assert attr.may_edit() is False
    assert attr.from_config() is True