From 727141b5e240071460294bde624e51481c01d310 Mon Sep 17 00:00:00 2001 From: Chris Drexler Date: Sun, 30 Dec 2018 14:12:49 +0100 Subject: [PATCH] FIX(buku) ff json import folder w/o children - fixes jarun/Buku#340 - replaced error with warning - proper warning message added - test added --- buku | 6 +++--- tests/test_import_firefox_json.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/buku b/buku index a9aaf88..337364b 100755 --- a/buku +++ b/buku @@ -3027,7 +3027,7 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None) .format(bm_entry['uri'], bm_entry['title'], tags, desc)) yield (bm_entry['uri'], bm_entry['title'], tags, desc, 0, True, False) except Exception as e: - LOGERR(e) + LOGERR("Error parsing entry '{}' Exception '{}'".format(bm_entry['title'], e)) elif TypeCode.folder.value == typeCode: try: @@ -3037,9 +3037,9 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None) for entry in iterate_children( parent_folder+"/"+bm_entry['title'], bm_entry['children']): yield entry - except Exception as e: + except Exception: # if any of the properties does not exist, bail out silently - LOGERR(e) + LOGDBG("No 'children' found in bookmark folder - skipping: {}".format(bm_entry['title'])) elif TypeCode.separator.value == typeCode: LOGDBG("Unknown typeCode found : {}".format(typeCode)) diff --git a/tests/test_import_firefox_json.py b/tests/test_import_firefox_json.py index b068330..44efd66 100644 --- a/tests/test_import_firefox_json.py +++ b/tests/test_import_firefox_json.py @@ -110,6 +110,25 @@ def test_load_invalid_typecode(): assert len(result) == 0 +def test_load_folder_with_no_children(): + """test method.""" + + # Arrange + data = json.loads(""" + { + "title" : "title", + "typeCode" : 2 + } """) + + # Act + items = import_firefox_json(data) + + # Assert + result = [] + for item in items: + result.append(item) + + assert 0 == len(result) def test_load_one_child(): """test method."""