From ea16bf44c11df0efe58949b06aabe925df8201a4 Mon Sep 17 00:00:00 2001 From: Logan Connolly Date: Thu, 12 Dec 2024 10:44:37 +0100 Subject: [PATCH] utils: add tests for makeuri_contextless 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 --- tests/unit/cmk/gui/utils/test_urls.py | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/unit/cmk/gui/utils/test_urls.py b/tests/unit/cmk/gui/utils/test_urls.py index 6f60da57104..a89f3066bca 100644 --- a/tests/unit/cmk/gui/utils/test_urls.py +++ b/tests/unit/cmk/gui/utils/test_urls.py @@ -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( @@ -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