ADD(buku) simplify test & add docu for ff json imp
This commit is contained in:
parent
e6f3debdda
commit
5bc1ab63da
11
buku
11
buku
@ -2887,6 +2887,17 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None)
|
||||
|
||||
Ignore 'SmartBookmark' and 'Separator' entries.
|
||||
|
||||
|
||||
Needed/used fields out of the JSON schema of the bookmarks:
|
||||
|
||||
title : the name/title of the entry
|
||||
tags : ',' separated tags for the bookmark entry
|
||||
typeCode : 1 - uri, 2 - subfolder, 3 - separator
|
||||
annos/{name,value} : following annotation entries are used
|
||||
name : Places/SmartBookmark : identifies smart folder, ignored
|
||||
name : bookmarkPropereties/description : detailed bookmark entry description
|
||||
children : for subfolders, recurse into the child entries
|
||||
|
||||
Parameters
|
||||
----------
|
||||
path : str
|
||||
|
@ -14,6 +14,46 @@ def test_load_from_empty():
|
||||
count = sum(1 for _ in items)
|
||||
assert 0 == count
|
||||
|
||||
def test_load_full_entry():
|
||||
"""test method."""
|
||||
|
||||
# Arrange
|
||||
data = json.loads("""
|
||||
{
|
||||
"title" : "title",
|
||||
"children": [
|
||||
{
|
||||
"dateAdded": 1269200039653000,
|
||||
"guid": "xxxydfalkj",
|
||||
"id": 113,
|
||||
"index": 0,
|
||||
"lastModified": 1305978154986000,
|
||||
"title": "title",
|
||||
"type": "text/x-moz-place",
|
||||
"typeCode": 1,
|
||||
"tags" : "x,y",
|
||||
"uri": "http://uri.com/abc?234&536",
|
||||
"annos" : [{
|
||||
"name": "bookmarkProperties/description",
|
||||
"value": "desc"
|
||||
}]
|
||||
}]
|
||||
}""")
|
||||
|
||||
# Act
|
||||
items = import_firefox_json(data)
|
||||
|
||||
# Assert
|
||||
result = []
|
||||
for item in items:
|
||||
result.append(item)
|
||||
|
||||
assert 1 == len(result)
|
||||
assert 'http://uri.com/abc?234&536' == result[0][0]
|
||||
assert 'title' == result[0][1]
|
||||
assert ',x,y,' == result[0][2]
|
||||
assert 'desc' == result[0][3]
|
||||
|
||||
|
||||
def test_load_no_typecode():
|
||||
"""test method."""
|
||||
@ -88,7 +128,8 @@ def test_load_one_child():
|
||||
"name": "bookmarkProperties/description",
|
||||
"value": "desc"
|
||||
}]
|
||||
}]
|
||||
}
|
||||
]
|
||||
} """)
|
||||
|
||||
# Act
|
||||
@ -115,22 +156,8 @@ def test_load_one_container_child():
|
||||
"typeCode" : 2,
|
||||
"children": [
|
||||
{
|
||||
"guid":"mobile______",
|
||||
"title":"Mobile Lesezeichen",
|
||||
"index":4,
|
||||
"dateAdded":1489602681463000,
|
||||
"lastModified":1519334403977000,
|
||||
"id":330524,
|
||||
"typeCode":2,
|
||||
"annos":[
|
||||
{
|
||||
"name":"mobile/bookmarksRoot",
|
||||
"value":"1",
|
||||
"expires":4,
|
||||
"flags":0
|
||||
}],
|
||||
"type":"text/x-moz-place-container",
|
||||
"root":"mobileFolder"
|
||||
"title":"bookmark folder",
|
||||
"typeCode":2
|
||||
} ]
|
||||
}""")
|
||||
|
||||
@ -150,18 +177,12 @@ def test_load_many_children():
|
||||
# Arrange
|
||||
data = json.loads("""
|
||||
{
|
||||
"guid":"unfiled_____",
|
||||
"title":"Weitere Lesezeichen",
|
||||
"index":3,
|
||||
"dateAdded":1305446109028000,"lastModified":1544905385223000,
|
||||
"id":5,
|
||||
"typeCode":2,
|
||||
"type":"text/x-moz-place-container",
|
||||
"root":"unfiledBookmarksFolder",
|
||||
"children": [
|
||||
{"guid":"_0yvSg7JN7WD","title":"title1","index":0,"dateAdded":1287656058186000,"lastModified":1305978155312000,"id":169,"typeCode":1,"charset":"UTF-8","annos":[{"name":"bookmarkProperties/description","value":"desc3","expires":4,"flags":0}],"type":"text/x-moz-place","uri":"http://uri1.com/#more-74"},
|
||||
{"guid":"YI8BEgRJ1Hio","title":"title2","index":1,"dateAdded":1232202012000000,"lastModified":1305978155291000,"id":157,"typeCode":1,"charset":"ISO-8859-1","annos":[{"name":"bookmarkProperties/description","value":"desc2","expires":4,"flags":0}],"type":"text/x-moz-place","uri":"http://uri2.com/xyz"},
|
||||
{"guid":"XYewkZ6jVnOt","title":"title3","index":2,"dateAdded":1236767103079000,"lastModified":1305978155293000,"id":158,"typeCode":1,"charset":"ISO-8859-1","type":"text/x-moz-place","uri":"http://uri3.com"}
|
||||
{"title":"title1","typeCode":1,"uri":"http://uri1.com/#more-74"},
|
||||
{"title":"title2","typeCode":1,"uri":"http://uri2.com/xyz"},
|
||||
{"title":"title3","typeCode":1,"uri":"http://uri3.com"}
|
||||
]
|
||||
} """)
|
||||
|
||||
@ -188,14 +209,14 @@ def test_load_hierarchical_container():
|
||||
"title" : "title",
|
||||
"typeCode" : 2,
|
||||
"children": [
|
||||
{"title":"title1","index":0,"dateAdded":1287656058186000,"lastModified":1305978155312000,"id":169,"typeCode":1,"charset":"UTF-8","annos":[{"name":"bookmarkProperties/description","value":"desc3","expires":4,"flags":0}],"type":"text/x-moz-place","uri":"http://uri1.com/#more-74"},
|
||||
{"title":"title2","index":1,"dateAdded":1232202012000000,"lastModified":1305978155291000,"id":157,"typeCode":1,"charset":"ISO-8859-1","annos":[{"name":"bookmarkProperties/description","value":"desc2","expires":4,"flags":0}],"type":"text/x-moz-place","uri":"http://uri2.com/xyz"},
|
||||
{"title":"title3","index":2,"dateAdded":1236767103079000,"lastModified":1305978155293000,"id":158,"typeCode":1,"charset":"ISO-8859-1","type":"text/x-moz-place","uri":"http://uri3.com"}
|
||||
{"title":"title1","typeCode":1,"uri":"http://uri1.com/#more-74"},
|
||||
{"title":"title2","typeCode":1,"uri":"http://uri2.com/xyz"},
|
||||
{"title":"title3","typeCode":1,"uri":"http://uri3.com"}
|
||||
]
|
||||
},
|
||||
{"title":"title4","index":0,"dateAdded":1287656058186000,"lastModified":1305978155312000,"id":169,"typeCode":1,"charset":"UTF-8","annos":[{"name":"bookmarkProperties/description","value":"desc3","expires":4,"flags":0}],"type":"text/x-moz-place","uri":"http://uri4.com/#more-74"},
|
||||
{"title":"title5","index":1,"dateAdded":1232202012000000,"lastModified":1305978155291000,"id":157,"typeCode":1,"charset":"ISO-8859-1","annos":[{"name":"bookmarkProperties/description","value":"desc2","expires":4,"flags":0}],"type":"text/x-moz-place","uri":"http://uri5.com/xyz"},
|
||||
{"title":"title6","index":2,"dateAdded":1236767103079000,"lastModified":1305978155293000,"id":158,"typeCode":1,"charset":"ISO-8859-1","type":"text/x-moz-place","uri":"http://uri6.com"}
|
||||
{"title":"title4","typeCode":1,"uri":"http://uri4.com/#more-74"},
|
||||
{"title":"title5","typeCode":1,"uri":"http://uri5.com/xyz"},
|
||||
{"title":"title6","typeCode":1,"uri":"http://uri6.com"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
@ -226,11 +247,6 @@ def test_load_separator():
|
||||
"typeCode" : 2,
|
||||
"children": [
|
||||
{
|
||||
"dateAdded": 1420573322580000,
|
||||
"guid": "C1gVk34FrhSQ",
|
||||
"id": 330511,
|
||||
"index": 35,
|
||||
"lastModified": 1420573322580000,
|
||||
"title": "",
|
||||
"type": "text/x-moz-place-separator",
|
||||
"typeCode": 3
|
||||
|
Loading…
Reference in New Issue
Block a user