importer: tests
Added tests for Netscape and Mozilla formats.
This commit is contained in:
parent
e72e8b8556
commit
2b6763ad13
2
tests/unit/scripts/importer_sample/chrome/bookmarks
Normal file
2
tests/unit/scripts/importer_sample/chrome/bookmarks
Normal file
@ -0,0 +1,2 @@
|
||||
http://foo.com/ Foo
|
||||
http://bar.com/ Bar
|
5
tests/unit/scripts/importer_sample/chrome/config_py
Normal file
5
tests/unit/scripts/importer_sample/chrome/config_py
Normal file
@ -0,0 +1,5 @@
|
||||
# Unsupported parameter in url for google.com; skipping....
|
||||
c.url.searchengines['bing.com'] = 'https://www.bing.com/search?q={}&PC=U316&FORM=CHROMN'
|
||||
c.url.searchengines['yahoo.com'] = 'https://search.yahoo.com/search?ei=UTF-8&fr=crmas&p={}'
|
||||
c.url.searchengines['aol.com'] = 'https://search.aol.com/aol/search?q={}'
|
||||
c.url.searchengines['ask.com'] = 'http://www.ask.com/web?q={}'
|
2
tests/unit/scripts/importer_sample/chrome/quickmarks
Normal file
2
tests/unit/scripts/importer_sample/chrome/quickmarks
Normal file
@ -0,0 +1,2 @@
|
||||
Foo http://foo.com/
|
||||
Bar http://bar.com/
|
2
tests/unit/scripts/importer_sample/mozilla/bookmarks
Normal file
2
tests/unit/scripts/importer_sample/mozilla/bookmarks
Normal file
@ -0,0 +1,2 @@
|
||||
about:blank/bar Standard Bookmark
|
||||
about:blank/foo keyword
|
1
tests/unit/scripts/importer_sample/mozilla/config_py
Normal file
1
tests/unit/scripts/importer_sample/mozilla/config_py
Normal file
@ -0,0 +1 @@
|
||||
c.url.searchengines['search'] = 'about:blank/{}' #Keyword-based search
|
BIN
tests/unit/scripts/importer_sample/mozilla/input/places.sqlite
Normal file
BIN
tests/unit/scripts/importer_sample/mozilla/input/places.sqlite
Normal file
Binary file not shown.
2
tests/unit/scripts/importer_sample/mozilla/quickmarks
Normal file
2
tests/unit/scripts/importer_sample/mozilla/quickmarks
Normal file
@ -0,0 +1,2 @@
|
||||
Standard Bookmark about:blank/bar
|
||||
keyword about:blank/foo
|
2
tests/unit/scripts/importer_sample/netscape/bookmarks
Normal file
2
tests/unit/scripts/importer_sample/netscape/bookmarks
Normal file
@ -0,0 +1,2 @@
|
||||
about:blank/bar Standard Bookmark
|
||||
about:blank/foo Bookmark with Keyword
|
1
tests/unit/scripts/importer_sample/netscape/config_py
Normal file
1
tests/unit/scripts/importer_sample/netscape/config_py
Normal file
@ -0,0 +1 @@
|
||||
c.url.searchengines['search'] = 'about:blank/{}' #Keyword-based search
|
17
tests/unit/scripts/importer_sample/netscape/input
Normal file
17
tests/unit/scripts/importer_sample/netscape/input
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
||||
<!-- This is an automatically generated file.
|
||||
It will be read and overwritten.
|
||||
DO NOT EDIT! -->
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
||||
<TITLE>Bookmarks</TITLE>
|
||||
<H1>Bookmarks Menu</H1>
|
||||
|
||||
<DL><p>
|
||||
<DT><H3 ADD_DATE="1509060420" LAST_MODIFIED="1509060968" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks Toolbar</H3>
|
||||
<DD>Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar
|
||||
<DL><p>
|
||||
<DT><A HREF="about:blank/%s" ADD_DATE="1509060968" LAST_MODIFIED="1509060985" SHORTCUTURL="search">Keyword-based search</A>
|
||||
<DT><A HREF="about:blank/foo" ADD_DATE="1509060896" LAST_MODIFIED="1509061197" SHORTCUTURL="keyword">Bookmark with Keyword</A>
|
||||
<DT><A HREF="about:blank/bar" ADD_DATE="1509060875" LAST_MODIFIED="1509061200">Standard Bookmark</A>
|
||||
</DL><p>
|
||||
</DL>
|
2
tests/unit/scripts/importer_sample/netscape/quickmarks
Normal file
2
tests/unit/scripts/importer_sample/netscape/quickmarks
Normal file
@ -0,0 +1,2 @@
|
||||
Standard Bookmark about:blank/bar
|
||||
keyword about:blank/foo
|
@ -19,9 +19,33 @@
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from scripts import importer
|
||||
|
||||
_chrome_profile = 'tests/unit/scripts/chrome-profile'
|
||||
_samples = 'tests/unit/scripts/importer_sample'
|
||||
|
||||
|
||||
def qm_expected(input_format):
|
||||
"""Read expected quickmark-formatted output."""
|
||||
with open(os.path.join(_samples, input_format, 'quickmarks'), 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def bm_expected(input_format):
|
||||
"""Read expected bookmark-formatted output."""
|
||||
with open(os.path.join(_samples, input_format, 'bookmarks'), 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def search_expected(input_format):
|
||||
"""Read expected search-formatted (config.py) output."""
|
||||
with open(os.path.join(_samples, input_format, 'config_py'), 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def sample_input(input_format):
|
||||
"""Get the sample input path."""
|
||||
return os.path.join(_samples, input_format, 'input')
|
||||
|
||||
|
||||
def test_opensearch_convert():
|
||||
@ -54,20 +78,56 @@ def test_opensearch_convert_unsupported():
|
||||
|
||||
def test_chrome_bookmarks(capsys):
|
||||
"""Read sample bookmarks from chrome profile."""
|
||||
expected = ('Foo http://foo.com/\n' 'Bar http://bar.com/\n')
|
||||
importer.import_chrome(_chrome_profile, ['bookmark'], 'quickmark')
|
||||
importer.import_chrome(sample_input('chrome'), ['bookmark'], 'bookmark')
|
||||
imported = capsys.readouterr()[0]
|
||||
assert imported == expected
|
||||
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."""
|
||||
expected = (
|
||||
"# Unsupported parameter in url for google.com; skipping....\n"
|
||||
"c.url.searchengines['bing.com'] = 'https://www.bing.com/search?q={}&PC=U316&FORM=CHROMN'\n"
|
||||
"c.url.searchengines['yahoo.com'] = 'https://search.yahoo.com/search?ei=UTF-8&fr=crmas&p={}'\n"
|
||||
"c.url.searchengines['aol.com'] = 'https://search.aol.com/aol/search?q={}'\n"
|
||||
"c.url.searchengines['ask.com'] = 'http://www.ask.com/web?q={}'\n")
|
||||
importer.import_chrome(_chrome_profile, ['search'], 'search')
|
||||
importer.import_chrome(sample_input('chrome'), ['search'], 'search')
|
||||
imported = capsys.readouterr()[0]
|
||||
assert imported == expected
|
||||
assert imported == search_expected('chrome')
|
||||
|
||||
|
||||
def test_netscape_bookmarks(capsys):
|
||||
importer.import_netscape_bookmarks(sample_input('netscape'), ['bookmark', 'keyword'], 'bookmark')
|
||||
imported = capsys.readouterr()[0]
|
||||
assert imported == bm_expected('netscape')
|
||||
|
||||
|
||||
def test_netscape_quickmarks(capsys):
|
||||
importer.import_netscape_bookmarks(sample_input('netscape'), ['bookmark', 'keyword'], 'quickmark')
|
||||
imported = capsys.readouterr()[0]
|
||||
assert imported == qm_expected('netscape')
|
||||
|
||||
|
||||
def test_netscape_searches(capsys):
|
||||
importer.import_netscape_bookmarks(sample_input('netscape'), ['search'], 'search')
|
||||
imported = capsys.readouterr()[0]
|
||||
assert imported == search_expected('netscape')
|
||||
|
||||
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user