ADD(buku) more tests for import_firefox_json

This commit is contained in:
Chris Drexler 2018-12-25 20:43:51 +01:00
parent 61e4cdb7ea
commit e6f3debdda

View File

@ -175,12 +175,104 @@ def test_load_many_children():
assert 3 == len(result)
def test_load_hierarchical_container():
"""test method."""
# Tests TODO:
# separator type code
# multiple tags
# hierarchic folders
# utf-8 encoded titles
# non-generic url
# tags with comma(?), UTF chars, ...
# endurance test (>200 entries)
# Arrange
data = json.loads("""
{
"title" : "title",
"typeCode" : 2,
"children": [
{
"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":"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"}
]
}
""")
# Act
items = import_firefox_json(data)
# Assert
result = []
for item in items:
result.append(item)
assert 6 == len(result)
assert 'http://uri1.com/#more-74' == result[0][0]
assert 'http://uri2.com/xyz' == result[1][0]
assert 'http://uri3.com' == result[2][0]
assert 'http://uri4.com/#more-74' == result[3][0]
assert 'http://uri5.com/xyz' == result[4][0]
assert 'http://uri6.com' == result[5][0]
def test_load_separator():
"""test method."""
# Arrange
data = json.loads("""
{
"title" : "title",
"typeCode" : 2,
"children": [
{
"dateAdded": 1420573322580000,
"guid": "C1gVk34FrhSQ",
"id": 330511,
"index": 35,
"lastModified": 1420573322580000,
"title": "",
"type": "text/x-moz-place-separator",
"typeCode": 3
} ]
}""")
# Act
items = import_firefox_json(data)
# Assert
result = []
for item in items:
result.append(item)
assert 0 == len(result)
def test_load_multiple_tags():
"""test method."""
# Arrange
data = json.loads("""
{
"title" : "title",
"children": [
{
"title" : "title1",
"uri" : "http://uri1",
"tags" : "tag1, tag2",
"typeCode": 1,
"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 ",tag1,tag2," == result[0][2]