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 da21c5e7e8
commit 578cd28edd
2 changed files with 49 additions and 5 deletions

17
buku
View File

@ -2961,7 +2961,8 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None)
desc = extract_desc(bm_entry) desc = extract_desc(bm_entry)
bookmark_tags = extract_tags(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) bookmark_tags.append(parent_folder)
if unique_tag: if unique_tag:
@ -2979,9 +2980,14 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None)
try: try:
# from python 3.3 on: # from python 3.3 on:
# yield from iterate_children(bm_entry['title'], bm_entry['children']) # 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 yield entry
except Exception: except Exception:
# if any of the properties does not exist, bail out silently # if any of the properties does not exist, bail out silently
logdbg("No 'children' found in bookmark folder - skipping: {}".format(bm_entry['title'])) logdbg("No 'children' found in bookmark folder - skipping: {}".format(bm_entry['title']))
@ -2995,7 +3001,12 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None)
logerr("No children in Root entry found") logerr("No children in Root entry found")
return [] 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): def import_html(html_soup, add_parent_folder_as_tag, newtag):

View File

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