From 7e3c966afeca64d99f9623a12a4286197fbd29d5 Mon Sep 17 00:00:00 2001 From: gammelon Date: Fri, 9 Mar 2018 15:52:03 +0100 Subject: [PATCH] rewrite tests --- qutebrowser/utils/urlutils.py | 3 +- tests/unit/utils/test_urlutils.py | 49 ++++++++++++++++++------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 8bbf5b362..0c77a5d0f 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -103,8 +103,7 @@ def _get_search_url(txt): template = config.val.url.searchengines[engine] url = qurl_from_user_input(template.format(urllib.parse.quote(term))) - if config.val.url.open_base_url and \ - term in config.val.url.searchengines.keys(): + if config.val.url.open_base_url and term in config.val.url.searchengines: url = qurl_from_user_input(config.val.url.searchengines[term]) url.setPath(None) url.setFragment(None) diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index a96236f6e..d2da02d0f 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -277,25 +277,17 @@ class TestFuzzyUrl: def test_special_urls(url, special): assert urlutils.is_special_url(QUrl(url)) == special -@pytest.mark.parametrize('url, host, query, open_base_url', [ - ('testfoo', 'www.example.com', 'q=testfoo', False), - ('test testfoo', 'www.qutebrowser.org', 'q=testfoo', False), - ('test testfoo bar foo', 'www.qutebrowser.org', 'q=testfoo bar foo', False), - ('test testfoo ', 'www.qutebrowser.org', 'q=testfoo', False), - ('!python testfoo', 'www.example.com', 'q=%21python testfoo', False), - ('blub testfoo', 'www.example.com', 'q=blub testfoo', False), - ('stripped ', 'www.example.com', 'q=stripped', False), - ('test-with-dash testfoo', 'www.example.org', 'q=testfoo', False), - ('testfoo', 'www.example.com', 'q=testfoo', True), - ('test testfoo', 'www.qutebrowser.org', 'q=testfoo', True), - ('test testfoo bar foo', 'www.qutebrowser.org', 'q=testfoo bar foo', True), - ('test testfoo ', 'www.qutebrowser.org', 'q=testfoo', True), - ('!python testfoo', 'www.example.com', 'q=%21python testfoo', True), - ('blub testfoo', 'www.example.com', 'q=blub testfoo', True), - ('stripped ', 'www.example.com', 'q=stripped', True), - ('test-with-dash testfoo', 'www.example.org', 'q=testfoo', True), - ('test', 'www.qutebrowser.org', '', True), - ('test-with-dash', 'www.example.org', '', True), +@pytest.mark.parametrize('open_base_url', [True, False]) + +@pytest.mark.parametrize('url, host, query', [ + ('testfoo', 'www.example.com', 'q=testfoo'), + ('test testfoo', 'www.qutebrowser.org', 'q=testfoo'), + ('test testfoo bar foo', 'www.qutebrowser.org', 'q=testfoo bar foo'), + ('test testfoo ', 'www.qutebrowser.org', 'q=testfoo'), + ('!python testfoo', 'www.example.com', 'q=%21python testfoo'), + ('blub testfoo', 'www.example.com', 'q=blub testfoo'), + ('stripped ', 'www.example.com', 'q=stripped'), + ('test-with-dash testfoo', 'www.example.org', 'q=testfoo'), ]) def test_get_search_url(config_stub, url, host, query, open_base_url): """Test _get_search_url(). @@ -308,13 +300,28 @@ def test_get_search_url(config_stub, url, host, query, open_base_url): config_stub.val.url.open_base_url = open_base_url url = urlutils._get_search_url(url) if open_base_url and query == '': - assert url.path() == '' - assert url.fragment() == '' + assert not url.path() + assert not url.fragment() assert url.host() == host assert url.query() == query +@pytest.mark.parametrize('url, host, query', [ + ('test', 'www.qutebrowser.org', ''), + ('test-with-dash', 'www.example.org', ''), +]) + +def test_get_search_url_open_base_url(config_stub, url, host, query): + """Test _get_search_url() with url.open_base_url_enabled. + + Args: + url: The "URL" to enter. + host: The expected search machine host. + query: The expected search query. + """ + test_get_search_url(config_stub, url, host, query, True) + @pytest.mark.parametrize('url', ['\n', ' ', '\n ']) def test_get_search_url_invalid(url): with pytest.raises(ValueError):