From 18407d89602a2e8bedfcfb2d1ce65c06966b28bb Mon Sep 17 00:00:00 2001 From: John Eikenberry Date: Sun, 15 Apr 2018 21:19:09 -0700 Subject: [PATCH 1/6] auto-import's folder as tags uses parent hierarchy When selecting "Add parent folder names as tags" for auto-import you get the parent folder's title, their parent's title, etc. The full folder hierarchy added as separate tags, up to the top level folder. Eg. you have folder 'foo' containing subfolder 'bar' containing bookmark 'website'. Upon importing you'd get a bookmark entry for 'website' with tags for both 'foo' and 'bar' added. --- buku.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/buku.py b/buku.py index f7d4b07..b8827d4 100755 --- a/buku.py +++ b/buku.py @@ -2029,7 +2029,8 @@ class BukuDb: for item in sublist: if item['type'] == 'folder': - for i in self.traverse_bm_folder(item['children'], unique_tag, item['name'], add_parent_folder_as_tag): + next_folder_name = folder_name + ',' + item['name'] + for i in self.traverse_bm_folder(item['children'], unique_tag, next_folder_name, add_parent_folder_as_tag): yield (i) elif item['type'] == 'url': try: @@ -2110,8 +2111,13 @@ class BukuDb: if add_parent_folder_as_tag: # add folder name - res = cur.execute('SELECT title FROM moz_bookmarks WHERE id={}'.format(row[1])) - bookmark_tags.append(res.fetchone()[0]) + parent_id = row[1] + while parent_id: + res = cur.execute('SELECT title,parent FROM moz_bookmarks WHERE id={}'.format(parent_id)) + parent = res.fetchone() + if parent: + title, parent_id = parent + bookmark_tags.append(title) if unique_tag: # add timestamp tag From f50bdd13f8331f9cb16c1c60e3f8b0df772ac0fd Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 18 Apr 2018 05:27:12 +0800 Subject: [PATCH 2/6] chg: test: browser test - add method to dump new exp_res - use local file --- tests/test_bukuDb.py | 49 +++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 920e57d..89f5df8 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -20,6 +20,7 @@ from hypothesis import strategies as st from unittest import mock as mock import pytest import unittest +import yaml from buku import BukuDb, parse_tags, prompt @@ -1253,11 +1254,10 @@ def chrome_db(bookmark_folder): tmpdir = bookmark_folder json_file = [x.strpath for x in tmpdir.listdir() if x.basename == 'Bookmarks'][0] - res_pickle_file = [ - x.strpath for x in tmpdir.listdir() if x.basename == '25491522_res.pickle'][0] - res_nopt_pickle_file = [ - x.strpath for x in tmpdir.listdir() if x.basename == '25491522_res_nopt.pickle'][0] - return json_file, res_pickle_file, res_nopt_pickle_file + dir_path = os.path.dirname(os.path.realpath(__file__)) + res_yaml_file = os.path.join(dir_path, 'test_bukuDb', '25491522_res.yaml') + res_nopt_yaml_file = os.path.join(dir_path, 'test_bukuDb', '25491522_res_nopt.yaml') + return json_file, res_yaml_file, res_nopt_yaml_file @pytest.mark.parametrize('add_pt', [True, False]) @@ -1265,9 +1265,11 @@ def test_load_chrome_database(chrome_db, add_pt): """test method.""" # compatibility json_file = chrome_db[0] - res_pickle_file = chrome_db[1] if add_pt else chrome_db[2] - with open(res_pickle_file, 'rb') as f: - res_pickle = pickle.load(f) + res_yaml_file = chrome_db[1] if add_pt else chrome_db[2] + dump_data = False + if not dump_data: + with open(res_yaml_file, 'r') as f: + res_yaml = yaml.load(f) # init import buku bdb = buku.BukuDb() @@ -1275,7 +1277,12 @@ def test_load_chrome_database(chrome_db, add_pt): bdb.load_chrome_database(json_file, None, add_pt) call_args_list_dict = dict(bdb.add_rec.call_args_list) # test - assert call_args_list_dict == res_pickle + if not dump_data: + assert call_args_list_dict == res_yaml + # dump data for new test + if dump_data: + with open(res_yaml_file, 'w') as f: + yaml.dump(call_args_list_dict, f) @pytest.fixture() @@ -1284,21 +1291,21 @@ def firefox_db(bookmark_folder): tmpdir = bookmark_folder ff_db_path = [x.strpath for x in tmpdir.listdir() if x.basename == 'places.sqlite'][0] - res_pickle_file = [ - x.strpath for x in tmpdir.listdir() if x.basename == 'firefox_res.pickle'][0] - res_nopt_pickle_file = [ - x.strpath for x in tmpdir.listdir() if x.basename == 'firefox_res_nopt.pickle'][0] - return ff_db_path, res_pickle_file, res_nopt_pickle_file + dir_path = os.path.dirname(os.path.realpath(__file__)) + res_yaml_file = os.path.join(dir_path, 'test_bukuDb', 'firefox_res.yaml') + res_nopt_yaml_file = os.path.join(dir_path, 'test_bukuDb', 'firefox_res_nopt.yaml') + return ff_db_path, res_yaml_file, res_nopt_yaml_file @pytest.mark.parametrize('add_pt', [True, False]) def test_load_firefox_database(firefox_db, add_pt): # compatibility ff_db_path = firefox_db[0] - - res_pickle_file = firefox_db[1] if add_pt else firefox_db[2] - with open(res_pickle_file, 'rb') as f: - res_pickle = pickle.load(f) + dump_data = False + res_yaml_file = firefox_db[1] if add_pt else firefox_db[2] + if not dump_data: + with open(res_yaml_file, 'r') as f: + res_yaml = yaml.load(f) # init import buku bdb = buku.BukuDb() @@ -1306,7 +1313,11 @@ def test_load_firefox_database(firefox_db, add_pt): bdb.load_firefox_database(ff_db_path, None, add_pt) call_args_list_dict = dict(bdb.add_rec.call_args_list) # test - assert call_args_list_dict == res_pickle + if not dump_data: + assert call_args_list_dict == res_yaml + if dump_data: + with open(res_yaml_file, 'w') as f: + yaml.dump(call_args_list_dict, f) @pytest.mark.parametrize( From 1305dd6f1dff34bb28c6605916cf32a459fbf7a6 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 18 Apr 2018 05:27:36 +0800 Subject: [PATCH 3/6] new: test: add yaml for testing --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ec85849..e746944 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ with open('README.md', encoding='utf-8') as f: tests_require = [ 'pytest-cov', 'hypothesis>=3.7.0', 'py>=1.5.0', - 'beautifulsoup4>=4.6.0', 'flake8>=3.4.1', 'pylint>=1.7.2' + 'beautifulsoup4>=4.6.0', 'flake8>=3.4.1', 'pylint>=1.7.2', 'PyYAML>=3.12' ] if sys.version_info.major == 3 and sys.version_info.minor == 6: tests_require.append('pytest>=3.4.2,!=3.5.0,!=3.5.1') From a505c77fe4893d9204b2e7423159eddae5397bb9 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 18 Apr 2018 05:28:02 +0800 Subject: [PATCH 4/6] new: test: local test file --- tests/test_bukuDb/25491522_res.yaml | 45 ++++++++++++++++++++++ tests/test_bukuDb/25491522_res_nopt.yaml | 39 +++++++++++++++++++ tests/test_bukuDb/firefox_res.yaml | 49 ++++++++++++++++++++++++ tests/test_bukuDb/firefox_res_nopt.yaml | 45 ++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 tests/test_bukuDb/25491522_res.yaml create mode 100644 tests/test_bukuDb/25491522_res_nopt.yaml create mode 100644 tests/test_bukuDb/firefox_res.yaml create mode 100644 tests/test_bukuDb/firefox_res_nopt.yaml diff --git a/tests/test_bukuDb/25491522_res.yaml b/tests/test_bukuDb/25491522_res.yaml new file mode 100644 index 0000000..c29cce7 --- /dev/null +++ b/tests/test_bukuDb/25491522_res.yaml @@ -0,0 +1,45 @@ +? !!python/tuple ['http://voyagerlive.org/', Voyager, ',bookmarks bar,', null, 0, + true] +: {} +? !!python/tuple ['http://wiki.ubuntu.com/', Ubuntu Wiki (community-edited website), + ',bookmarks bar,imported from firefox,ubuntu and free software links,', null, 0, + true] +: {} +? !!python/tuple ['http://www.debian.org/', Debian (Ubuntu is based on Debian), ',bookmarks + bar,imported from firefox,ubuntu and free software links,', null, 0, true] +: {} +? !!python/tuple ['http://www.ubuntu.com/', Ubuntu, ',bookmarks bar,imported from + firefox,ubuntu and free software links,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', Adblock + Plus, ',bookmarks bar,f+,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/searchpreview/', SearchPreview, + ',bookmarks bar,f+,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', Language + Tools, ',bookmarks bar,f+,', null, 0, true] +: {} +? !!python/tuple ['https://answers.launchpad.net/ubuntu/+addquestion', Make a Support + Request to the Ubuntu Community, ',bookmarks bar,imported from firefox,ubuntu + and free software links,', null, 0, true] +: {} +? !!python/tuple ['https://one.ubuntu.com/', Ubuntu One - The personal cloud that + brings your digital life together, ',bookmarks bar,imported from firefox,ubuntu + and free software links,', null, 0, true] +: {} +? !!python/tuple ['https://www.google.com/', Google, ',other bookmarks,', null, 0, + true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/about/', About Us, ',bookmarks bar,imported + from firefox,mozilla firefox,', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/contribute/', Get Involved, ',bookmarks + bar,imported from firefox,mozilla firefox,', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/firefox/customize/', Customize Firefox, + ',bookmarks bar,imported from firefox,mozilla firefox,', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/firefox/help/', Help and Tutorials, + ',bookmarks bar,imported from firefox,mozilla firefox,', null, 0, true] +: {} diff --git a/tests/test_bukuDb/25491522_res_nopt.yaml b/tests/test_bukuDb/25491522_res_nopt.yaml new file mode 100644 index 0000000..b8b86bc --- /dev/null +++ b/tests/test_bukuDb/25491522_res_nopt.yaml @@ -0,0 +1,39 @@ +? !!python/tuple ['http://voyagerlive.org/', Voyager, ',', null, 0, true] +: {} +? !!python/tuple ['http://wiki.ubuntu.com/', Ubuntu Wiki (community-edited website), + ',', null, 0, true] +: {} +? !!python/tuple ['http://www.debian.org/', Debian (Ubuntu is based on Debian), ',', + null, 0, true] +: {} +? !!python/tuple ['http://www.ubuntu.com/', Ubuntu, ',', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', Adblock + Plus, ',', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/searchpreview/', SearchPreview, + ',', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', Language + Tools, ',', null, 0, true] +: {} +? !!python/tuple ['https://answers.launchpad.net/ubuntu/+addquestion', Make a Support + Request to the Ubuntu Community, ',', null, 0, true] +: {} +? !!python/tuple ['https://one.ubuntu.com/', Ubuntu One - The personal cloud that + brings your digital life together, ',', null, 0, true] +: {} +? !!python/tuple ['https://www.google.com/', Google, ',', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/about/', About Us, ',', null, 0, + true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/contribute/', Get Involved, ',', + null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/firefox/customize/', Customize Firefox, + ',', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/firefox/help/', Help and Tutorials, + ',', null, 0, true] +: {} diff --git a/tests/test_bukuDb/firefox_res.yaml b/tests/test_bukuDb/firefox_res.yaml new file mode 100644 index 0000000..2b10704 --- /dev/null +++ b/tests/test_bukuDb/firefox_res.yaml @@ -0,0 +1,49 @@ +? !!python/tuple ['http://voyagerlive.org/', Voyager, ',bookmarks toolbar,', null, + 0, true] +: {} +? !!python/tuple ['http://wiki.ubuntu.com/', Ubuntu Wiki (community-edited website), + ',bookmarks menu,ubuntu and free software links,', null, 0, true] +: {} +? !!python/tuple ['http://www.debian.org/', Debian (Ubuntu is based on Debian), ',bookmarks + menu,ubuntu and free software links,', null, 0, true] +: {} +? !!python/tuple ['http://www.ubuntu.com/', Ubuntu, ',bookmarks menu,ubuntu and free + software links,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', '', + ',language,tags,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', Adblock + Plus, ',bookmarks toolbar,f+,language,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/searchpreview/', SearchPreview, + ',bookmarks toolbar,f+,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', '', ',hello,language,tags,', + null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', Language + Tools, ',bookmarks toolbar,f+,hello,language,', null, 0, true] +: {} +? !!python/tuple ['https://answers.launchpad.net/ubuntu/+addquestion', Make a Support + Request to the Ubuntu Community, ',bookmarks menu,ubuntu and free software links,', + null, 0, true] +: {} +? !!python/tuple ['https://one.ubuntu.com/', Ubuntu One - The personal cloud that + brings your digital life together, ',bookmarks menu,ubuntu and free software links,', + null, 0, true] +: {} +? !!python/tuple ['https://www.google.co.in/', '', ',bookmarks menu,', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/about/', About Us, ',bookmarks menu,mozilla + firefox,', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/contribute/', Get Involved, ',bookmarks + menu,mozilla firefox,', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/firefox/customize/', Customize Firefox, + ',bookmarks menu,mozilla firefox,', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/firefox/help/', Help and Tutorials, + ',bookmarks menu,mozilla firefox,', null, 0, true] +: {} diff --git a/tests/test_bukuDb/firefox_res_nopt.yaml b/tests/test_bukuDb/firefox_res_nopt.yaml new file mode 100644 index 0000000..e716da6 --- /dev/null +++ b/tests/test_bukuDb/firefox_res_nopt.yaml @@ -0,0 +1,45 @@ +? !!python/tuple ['http://voyagerlive.org/', Voyager, ',', null, 0, true] +: {} +? !!python/tuple ['http://wiki.ubuntu.com/', Ubuntu Wiki (community-edited website), + ',', null, 0, true] +: {} +? !!python/tuple ['http://www.debian.org/', Debian (Ubuntu is based on Debian), ',', + null, 0, true] +: {} +? !!python/tuple ['http://www.ubuntu.com/', Ubuntu, ',', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', '', + ',language,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', Adblock + Plus, ',language,', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/searchpreview/', SearchPreview, + ',', null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', '', ',hello,language,', + null, 0, true] +: {} +? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', Language + Tools, ',hello,language,', null, 0, true] +: {} +? !!python/tuple ['https://answers.launchpad.net/ubuntu/+addquestion', Make a Support + Request to the Ubuntu Community, ',', null, 0, true] +: {} +? !!python/tuple ['https://one.ubuntu.com/', Ubuntu One - The personal cloud that + brings your digital life together, ',', null, 0, true] +: {} +? !!python/tuple ['https://www.google.co.in/', '', ',', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/about/', About Us, ',', null, 0, + true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/contribute/', Get Involved, ',', + null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/firefox/customize/', Customize Firefox, + ',', null, 0, true] +: {} +? !!python/tuple ['https://www.mozilla.org/en-US/firefox/help/', Help and Tutorials, + ',', null, 0, true] +: {} From 738afa36a668959d09feb7fa1cc0b03ba3f32960 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 18 Apr 2018 05:31:51 +0800 Subject: [PATCH 5/6] chg: test: remove unused pickle lib --- tests/test_bukuDb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 89f5df8..c8fdc45 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -4,7 +4,6 @@ # import math import os -import pickle import re import shutil import sqlite3 From 0e9ebcc46498ff37e1a8856e207390925c130b82 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 18 Apr 2018 05:33:20 +0800 Subject: [PATCH 6/6] chg: test: remove unused zip link --- tests/test_bukuDb.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index c8fdc45..ba4e362 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -1240,10 +1240,6 @@ def bookmark_folder(tmpdir): zip_url = 'https://github.com/jarun/Buku/files/1319933/bookmarks.zip' tmp_zip = tmpdir.join('bookmarks.zip') extract_all_from_zip_url(zip_url, tmp_zip, tmpdir) - # expected res - zip_url = 'https://github.com/jarun/Buku/files/1321193/bookmarks_res.zip' - tmp_zip = tmpdir.join('bookmarks_res.zip') - extract_all_from_zip_url(zip_url, tmp_zip, tmpdir) return tmpdir