From 0867a95abb3c25d2472e40b6b4dd056c870dcabe Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 2 Oct 2025 08:59:23 +0200 Subject: [PATCH] qutescheme: Add tests for redirects --- tests/unit/browser/test_qutescheme.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/unit/browser/test_qutescheme.py b/tests/unit/browser/test_qutescheme.py index d0a436008..42d082797 100644 --- a/tests/unit/browser/test_qutescheme.py +++ b/tests/unit/browser/test_qutescheme.py @@ -17,6 +17,36 @@ from qutebrowser.utils import resources, urlmatch from qutebrowser.misc import guiprocess +class TestDataForUrl: + @pytest.mark.parametrize( + "url, expected", + [ + # QUrl.UrlFormattingOption.StripTrailingSlash + (QUrl("qute://abc/xyz/"), QUrl("qute://abc/xyz")), + # QUrl.UrlFormattingOption.NormalizePathSegments + (QUrl("qute://abc/uvw/../xyz"), QUrl("qute://abc/xyz")), + # Adding host trailing slash + (QUrl("qute://abc"), QUrl("qute://abc/")), + (QUrl("qute://abc?q=42"), QUrl("qute://abc/?q=42")), + # path -> host + (QUrl("qute:abc"), QUrl("qute://abc/")), + (QUrl("qute:abc?q=42"), QUrl("qute://abc/?q=42")), + ], + ids=lambda url: url.toString(), + ) + def test_redirects(self, url: QUrl, expected: QUrl) -> None: + with pytest.raises(qutescheme.Redirect) as exc: + qutescheme.data_for_url(url) + assert exc.value.url == expected + + def test_invalid_redirect(self) -> None: + url = QUrl("qute:-") + with pytest.raises( + qutescheme.NotFoundError, match="No handler found for qute:-" + ): + qutescheme.data_for_url(url) + + class TestJavascriptHandler: """Test the qute://javascript endpoint."""