Exemplo n.º 1
0
def test_timerange_value_to_json_conversion():
    with on_time("2020-03-02", "UTC"):
        for choice in vs.Timerange().choices():
            if choice[0] == "age":
                choice = (("age", 12345), "The last..., 3 hours 25 minutes 45 seconds", None)
            elif choice[0] == "date":
                choice = (("date", (1582671600.0, 1582844400.0)),
                          "Date range, 2020-02-25, 2020-02-27", None)
            assert vs.Timerange().value_to_text(choice[0]) == choice[1]
            json_value = vs.Timerange().value_to_json(choice[0])
            assert vs.Timerange().value_from_json(json_value) == choice[0]
Exemplo n.º 2
0
def test_timerange_value_to_json_conversion(request_context):
    with on_time("2020-03-02", "UTC"):
        for ident, title, _vs in vs.Timerange().choices():
            choice_value: vs.CascadingDropdownChoiceValue = ident
            if ident == "age":
                choice_value = ("age", 12345)
                title = "The last..., 3 hours 25 minutes 45 seconds"
            elif ident == "date":
                choice_value = ("date", (1582671600.0, 1582844400.0))
                title = "Date range, 2020-02-25, 2020-02-27"

            assert vs.Timerange().value_to_html(choice_value) == title
            json_value = vs.Timerange().value_to_json(choice_value)
            assert vs.Timerange().value_from_json(json_value) == choice_value
Exemplo n.º 3
0
def test_timerange_value_to_html_conversion(request_context, monkeypatch, value, result_title):
    monkeypatch.setattr(
        config,
        "graph_timeranges",
        [
            {"title": "The last 4 fun hours", "duration": 4 * 60 * 60},
            {"title": "The last 25 hard hours", "duration": 25 * 60 * 60},
            {"title": "Since a sesquiweek", "duration": 3600 * 24 * 7 * 1.5},
        ],
    )

    assert vs.Timerange().value_to_html(value) == result_title
Exemplo n.º 4
0
def test_timerange_value_to_text_conversion(monkeypatch, value, result_title):

    monkeypatch.setattr(cmk.gui.config, "graph_timeranges",
                        [{
                            'title': "The last 4 fun hours",
                            "duration": 4 * 60 * 60
                        }, {
                            'title': "The last 25 hard hours",
                            "duration": 25 * 60 * 60
                        }, {
                            "title": "Since a sesquiweek",
                            "duration": 3600 * 24 * 7 * 1.5
                        }])

    assert vs.Timerange().value_to_text(value) == result_title
Exemplo n.º 5
0
def test_dictionary_value_to_json_conversion(value, result):
    with on_time("2020-03-02", "UTC"):
        # TODO: Obtain this valuespec directly by importing AlertBarChartDashlet
        #       once it's available and simplify to:
        #       abcd_vs = AlertBarChartDashlet.vs_parameters()
        abcd_vs = vs.Dictionary([
            ("time_range", vs.Timerange(title="Time range")),
            ("time_resolution",
             vs.DropdownChoice(title="Time resolution",
                               choices=[("h", "Show alerts per hour"),
                                        ("d", "Show alerts per day")])),
        ])
        abcd_vs._render = "oneline"
        assert abcd_vs.value_to_text(value) == result
        json_value = abcd_vs.value_to_json(value)
        assert abcd_vs.value_from_json(json_value) == value
Exemplo n.º 6
0
def test_timerange2(entry, refutcdate, result):
    with on_time(refutcdate, "UTC"):
        assert vs.Timerange().compute_range(entry) == result
Exemplo n.º 7
0
def test_timerange(entry, result):
    with on_time("2019-09-05 16:50", "UTC"):
        assert vs.Timerange().compute_range(entry) == result