FIX(buku) correct hierarchical folder handling

- fix hierarchical folder handling when adding parent folder
  as tag: only parent folder is added, no concatenation
- handling of folder without title added
- tests added for the above
This commit is contained in:
Chris Drexler 2018-12-30 15:37:38 +01:00
parent 727141b5e2
commit 9159e148d9
2 changed files with 49 additions and 6 deletions

18
buku
View File

@ -3014,7 +3014,8 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None)
desc = extract_desc(bm_entry)
bookmark_tags = extract_tags(bm_entry)
if add_bookmark_folder_as_tag:
# if parent_folder is not "None"
if add_bookmark_folder_as_tag and parent_folder:
bookmark_tags.append(parent_folder)
if unique_tag:
@ -3033,10 +3034,14 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None)
try:
# from python 3.3 on:
# yield from iterate_children(bm_entry['title'], bm_entry['children'])
try:
title = bm_entry['title']
except Exception:
title = ""
for entry in iterate_children(
parent_folder+"/"+bm_entry['title'], bm_entry['children']):
for entry in iterate_children(title, bm_entry['children']):
yield entry
except Exception:
# if any of the properties does not exist, bail out silently
LOGDBG("No 'children' found in bookmark folder - skipping: {}".format(bm_entry['title']))
@ -3050,7 +3055,12 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None)
LOGERR("No children in Root entry found")
return []
yield from iterate_children("", entry_list)
try:
title = json['title']
except Exception:
title = None
yield from iterate_children(title, entry_list)
def import_html(html_soup, add_parent_folder_as_tag, newtag):

View File

@ -215,6 +215,31 @@ def test_load_many_children():
assert len(result) == 3
def test_load_container_no_title():
"""test method."""
# Arrange
data = json.loads("""
{
"typeCode" : 2,
"children": [
{"title":"title1","typeCode":1,"uri":"http://uri.com"}
]
}
""")
# Act
items = import_firefox_json(data, add_bookmark_folder_as_tag=True)
# Assert
result = []
for item in items:
result.append(item)
assert 1 == len(result)
assert 'http://uri.com' == result[0][0]
assert ',' == result[0][2]
def test_load_hierarchical_container():
"""test method."""
@ -225,7 +250,7 @@ def test_load_hierarchical_container():
"typeCode" : 2,
"children": [
{
"title" : "title",
"title" : "title2",
"typeCode" : 2,
"children": [
{"title":"title1","typeCode":1,"uri":"http://uri1.com/#more-74"},
@ -241,7 +266,7 @@ def test_load_hierarchical_container():
""")
# Act
items = import_firefox_json(data)
items = import_firefox_json(data, add_bookmark_folder_as_tag=True)
# Assert
result = []
@ -256,6 +281,14 @@ def test_load_hierarchical_container():
assert result[4][0] == 'http://uri5.com/xyz'
assert result[5][0] == 'http://uri6.com'
assert ',title2,' == result[0][2]
assert ',title2,' == result[1][2]
assert ',title2,' == result[2][2]
assert ',title,' == result[3][2]
assert ',title,' == result[4][2]
assert ',title,' == result[5][2]
def test_load_separator():
"""test method."""