Skip to content

Commit

Permalink
utils: add tests for makeuri_contextless
Browse files Browse the repository at this point in the history
This function is ubiquitous (used in 450+ locations) and should be
covered with tests which also serve as documentation to show what the
underlying behavior is.

Change-Id: I0e9cd28a7184985f0282160ee7b2979719893781
  • Loading branch information
logan-connolly committed Dec 12, 2024
1 parent d6867c8 commit ea16bf4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/unit/cmk/gui/utils/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
# conditions defined in the file COPYING, which is part of this source code package.

import pytest
from werkzeug.test import create_environ

from cmk.gui.http import Request
from cmk.gui.logged_in import user
from cmk.gui.type_defs import HTTPVariables
from cmk.gui.utils.urls import doc_reference_url, DocReference, urlencode, urlencode_vars
from cmk.gui.utils.urls import (
doc_reference_url,
DocReference,
makeuri_contextless,
urlencode,
urlencode_vars,
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -55,3 +63,21 @@ def test_empty_doc_reference(request_context: None) -> None:

def test_doc_references(request_context: None) -> None:
assert [doc_reference_url(r) for r in DocReference]


def test_makeuri_contextless() -> None:
request = Request(create_environ())

value = makeuri_contextless(request, [("foo", "val"), ("bar", "val")], "wato.py")
expected = "wato.py?bar=val&foo=val" # query params are sorted

assert value == expected


def test_makeuri_contextless_no_variables() -> None:
request = Request(create_environ())

value = makeuri_contextless(request, [], "wato.py")
expected = "wato.py"

assert value == expected

0 comments on commit ea16bf4

Please sign in to comment.