Use QUrl for parsing, add tests
This commit is contained in:
parent
16218a9900
commit
a730290d40
@ -105,8 +105,10 @@ def _get_search_url(txt):
|
|||||||
|
|
||||||
if config.val.url.open_base_url and \
|
if config.val.url.open_base_url and \
|
||||||
term in config.val.url.searchengines.keys():
|
term in config.val.url.searchengines.keys():
|
||||||
search_url = urllib.parse.urlparse(config.val.url.searchengines[term])
|
url = qurl_from_user_input(config.val.url.searchengines[term])
|
||||||
url = QUrl('{}://{}'.format(search_url.scheme, search_url.netloc))
|
url.setPath(None)
|
||||||
|
url.setFragment(None)
|
||||||
|
url.setQuery(None)
|
||||||
qtutils.ensure_valid(url)
|
qtutils.ensure_valid(url)
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
@ -277,18 +277,27 @@ class TestFuzzyUrl:
|
|||||||
def test_special_urls(url, special):
|
def test_special_urls(url, special):
|
||||||
assert urlutils.is_special_url(QUrl(url)) == special
|
assert urlutils.is_special_url(QUrl(url)) == special
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('url, host, query, open_base_url', [
|
||||||
@pytest.mark.parametrize('url, host, query', [
|
('testfoo', 'www.example.com', 'q=testfoo', False),
|
||||||
('testfoo', 'www.example.com', 'q=testfoo'),
|
('test testfoo', 'www.qutebrowser.org', 'q=testfoo', False),
|
||||||
('test testfoo', 'www.qutebrowser.org', 'q=testfoo'),
|
('test testfoo bar foo', 'www.qutebrowser.org', 'q=testfoo bar foo', False),
|
||||||
('test testfoo bar foo', 'www.qutebrowser.org', 'q=testfoo bar foo'),
|
('test testfoo ', 'www.qutebrowser.org', 'q=testfoo', False),
|
||||||
('test testfoo ', 'www.qutebrowser.org', 'q=testfoo'),
|
('!python testfoo', 'www.example.com', 'q=%21python testfoo', False),
|
||||||
('!python testfoo', 'www.example.com', 'q=%21python testfoo'),
|
('blub testfoo', 'www.example.com', 'q=blub testfoo', False),
|
||||||
('blub testfoo', 'www.example.com', 'q=blub testfoo'),
|
('stripped ', 'www.example.com', 'q=stripped', False),
|
||||||
('stripped ', 'www.example.com', 'q=stripped'),
|
('test-with-dash testfoo', 'www.example.org', 'q=testfoo', False),
|
||||||
('test-with-dash testfoo', 'www.example.org', 'q=testfoo'),
|
('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),
|
||||||
])
|
])
|
||||||
def test_get_search_url(url, host, query):
|
def test_get_search_url(config_stub, url, host, query, open_base_url):
|
||||||
"""Test _get_search_url().
|
"""Test _get_search_url().
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -296,7 +305,12 @@ def test_get_search_url(url, host, query):
|
|||||||
host: The expected search machine host.
|
host: The expected search machine host.
|
||||||
query: The expected search query.
|
query: The expected search query.
|
||||||
"""
|
"""
|
||||||
|
config_stub.val.url.open_base_url = open_base_url
|
||||||
url = urlutils._get_search_url(url)
|
url = urlutils._get_search_url(url)
|
||||||
|
if open_base_url and query == '':
|
||||||
|
assert url.path() == ''
|
||||||
|
assert url.fragment() == ''
|
||||||
|
|
||||||
assert url.host() == host
|
assert url.host() == host
|
||||||
assert url.query() == query
|
assert url.query() == query
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user