1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import pathlib
import pytest
from scripts import importer
_samples = pathlib.Path('tests/unit/scripts/importer_sample')
def qm_expected(input_format):
"""Read expected quickmark-formatted output."""
return (_samples / input_format / 'quickmarks').read_text(encoding='utf-8')
def bm_expected(input_format):
"""Read expected bookmark-formatted output."""
return (_samples / input_format / 'bookmarks').read_text(encoding='utf-8')
def search_expected(input_format):
"""Read expected search-formatted (config.py) output."""
return (_samples / input_format / 'config_py').read_text(encoding='utf-8')
def sample_input(input_format):
"""Get the sample input path."""
return str(_samples / input_format / 'input')
def test_opensearch_convert():
urls = [
# simple search query
('http://foo.bar/s?q={searchTerms}', 'http://foo.bar/s?q={}'),
# simple search query with supported additional parameter
('http://foo.bar/s?q={searchTerms}&enc={inputEncoding}',
'http://foo.bar/s?q={}&enc=UTF-8'),
# same as above but with supported optional parameter
('http://foo.bar/s?q={searchTerms}&enc={inputEncoding?}',
'http://foo.bar/s?q={}&enc='),
# unsupported-but-optional parameter
('http://foo.bar/s?q={searchTerms}&opt={unsupported?}',
'http://foo.bar/s?q={}&opt='),
# unsupported-but-optional subset parameter
('http://foo.bar/s?q={searchTerms}&opt={unsupported:unsupported?}',
'http://foo.bar/s?q={}&opt=')
]
for os_url, qb_url in urls:
assert importer.opensearch_convert(os_url) == qb_url
def test_opensearch_convert_unsupported():
"""pass an unsupported, required parameter."""
with pytest.raises(KeyError):
os_url = 'http://foo.bar/s?q={searchTerms}&req={unsupported}'
importer.opensearch_convert(os_url)
def test_chrome_bookmarks(capsys):
"""Read sample bookmarks from chrome profile."""
importer.import_chrome(sample_input('chrome'), ['bookmark'], 'bookmark')
imported = capsys.readouterr()[0]
assert imported == bm_expected('chrome')
def test_chrome_quickmarks(capsys):
"""Read sample bookmarks from chrome profile."""
importer.import_chrome(sample_input('chrome'), ['bookmark'], 'quickmark')
imported = capsys.readouterr()[0]
assert imported == qm_expected('chrome')
def test_chrome_searches(capsys):
"""Read sample searches from chrome profile."""
importer.import_chrome(sample_input('chrome'), ['search'], 'search')
imported = capsys.readouterr()[0]
assert imported == search_expected('chrome')
def test_html_bookmarks(capsys):
importer.import_html_bookmarks(
sample_input('html'), ['bookmark', 'keyword'], 'bookmark')
imported = capsys.readouterr()[0]
assert imported == bm_expected('html')
def test_html_quickmarks(capsys):
importer.import_html_bookmarks(
sample_input('html'), ['bookmark', 'keyword'], 'quickmark')
imported = capsys.readouterr()[0]
assert imported == qm_expected('html')
def test_html_searches(capsys):
importer.import_html_bookmarks(
sample_input('html'), ['search'], 'search')
imported = capsys.readouterr()[0]
assert imported == search_expected('html')
def test_mozilla_bookmarks(capsys):
importer.import_moz_places(
sample_input('mozilla'), ['bookmark', 'keyword'], 'bookmark')
imported = capsys.readouterr()[0]
assert imported == bm_expected('mozilla')
def test_mozilla_quickmarks(capsys):
importer.import_moz_places(
sample_input('mozilla'), ['bookmark', 'keyword'], 'quickmark')
imported = capsys.readouterr()[0]
assert imported == qm_expected('mozilla')
def test_mozilla_searches(capsys):
importer.import_moz_places(sample_input('mozilla'), ['search'], 'search')
imported = capsys.readouterr()[0]
assert imported == search_expected('mozilla')
|