def test_save(self, _format, mocker):
     mocky = mocker.patch.object(BookmarksConverter, "_dispatcher")
     method = f"_save_to_{_format}"
     instance = BookmarksConverter("filepath")
     instance._export = _format
     instance._format = _format
     instance.save()
     mocky.assert_called_once_with(method)
Example #2
0
def test_from_chrome_json_to_html(source_bookmark_files, result_bookmark_files):
    result_file = Path(result_bookmark_files["from_chrome_json.html"])
    bookmarks = BookmarksConverter(source_bookmark_files["bookmarks_chrome.json"])
    bookmarks.parse("json")
    bookmarks.convert("html")
    bookmarks.save()
    output_file = bookmarks.output_filepath.with_suffix(".html")
    assert cmp(result_file, output_file, shallow=False)
    output_file.unlink()
Example #3
0
def test_from_db_to_html(result_file, source_file, result_bookmark_files):
    result_file = Path(result_bookmark_files[result_file])
    source_file = Path(result_bookmark_files[source_file])
    bookmarks = BookmarksConverter(source_file)
    bookmarks.parse("db")
    bookmarks.convert("html")
    bookmarks.save()
    output_file = bookmarks.output_filepath.with_suffix(".html")
    assert cmp(result_file, output_file, shallow=False)
    output_file.unlink()
 def test_save_to_html(self, result_bookmark_files):
     result_file = result_bookmark_files["from_firefox_json.html"]
     instance = BookmarksConverter(result_file)
     with open(result_file, "r", encoding="utf-8") as file_:
         instance.bookmarks = file_.read()
     output_file = Path(result_file).with_name("output_file.html")
     instance.output_filepath = output_file
     # setting the _export and _format attributes manually.
     instance._export = "html"
     instance._format = "html"
     instance.save()
     assert cmp(result_file, output_file, shallow=False)
     output_file.unlink()
Example #5
0
def test_from_db_to_json_firefox(result_bookmark_files):
    result_file = Path(result_bookmark_files["from_firefox_html.json"])
    source_file = Path(result_bookmark_files["from_firefox_html.db"])
    bookmarks = BookmarksConverter(source_file)
    bookmarks.parse("db")
    # change the root, menu and toolber folder dates, as they are generated
    # when they are created and don't exist in an html file.
    bookmarks._tree.date_added = 1601886171439
    bookmarks._tree.children[0].date_added = 1601886171439
    bookmarks.convert("json")
    bookmarks.save()
    output_file = bookmarks.output_filepath.with_suffix(".json")
    assert cmp(result_file, output_file, shallow=False)
    output_file.unlink()
Example #6
0
def test_from_firefox_json_to_db(
    source_bookmark_files, result_bookmark_files, get_data_from_db
):
    origin = "Firefox"
    result_file = Path(result_bookmark_files["from_firefox_json.db"])
    result_bookmarks, _, _ = get_data_from_db(result_file, origin)
    bookmarks = BookmarksConverter(source_bookmark_files["bookmarks_firefox.json"])
    bookmarks.parse("json")
    bookmarks.convert("db")
    bookmarks.save()
    output_file = bookmarks.output_filepath.with_suffix(".db")
    output_bookmarks, _, _ = get_data_from_db(output_file, origin)
    assert result_bookmarks == output_bookmarks
    output_file.unlink()
Example #7
0
def test_from_chrome_html_to_db(
    source_bookmark_files, result_bookmark_files, get_data_from_db
):
    origin = "Chrome"
    result_file = Path(result_bookmark_files["from_chrome_html.db"])
    result_bookmarks, root_date, other_date = get_data_from_db(result_file, origin)
    bookmarks = BookmarksConverter(source_bookmark_files["bookmarks_chrome.html"])
    bookmarks.parse("html")
    bookmarks.convert("db")
    bookmarks.bookmarks[0].date_added = root_date
    bookmarks.bookmarks[1].date_added = other_date
    bookmarks.save()
    output_file = bookmarks.output_filepath.with_suffix(".db")
    output_bookmarks, _, _ = get_data_from_db(output_file, origin)
    assert result_bookmarks == output_bookmarks
    output_file.unlink()
Example #8
0
def test_from_chrome_html_to_json(
    source_bookmark_files, result_bookmark_files, read_json
):
    result_file = Path(result_bookmark_files["from_chrome_html.json"])
    json_data = read_json(result_file)
    # date_added of "root" folder
    root_date = json_data["date_added"]
    # date_added of "Other Bookmarks" folder
    other_date = json_data["children"][1]["date_added"]
    bookmarks = BookmarksConverter(source_bookmark_files["bookmarks_chrome.html"])
    bookmarks.parse("html")
    bookmarks.convert("json")
    bookmarks.bookmarks["date_added"] = root_date
    bookmarks.bookmarks["children"][1]["date_added"] = other_date
    bookmarks.save()
    output_file = bookmarks.output_filepath.with_suffix(".json")
    assert cmp(result_file, output_file, shallow=False)
    output_file.unlink()
 def test_save_to_db(self, get_data_from_db):
     file_path = "temp.db"
     bookmarks = list()
     for i in range(1, 11):
         parent_id = None if i == 0 else 0
         bookmarks.append(
             Folder(date_added=0,
                    index=0,
                    _id=i,
                    parent_id=parent_id,
                    title="Title"))
     instance = BookmarksConverter(file_path)
     instance.bookmarks = bookmarks
     # setting the _export attribute as not to raise an error
     # setting the _format attribute for the desired output format
     instance._export = instance._format = "db"
     instance.save()
     output_file = instance.output_filepath
     temp_bookmarks, _, _ = get_data_from_db(output_file, None)
     assert bookmarks == temp_bookmarks
     output_file.unlink()
 def test_save_error(self):
     instance = BookmarksConverter("filepath")
     with pytest.raises(RuntimeError) as e:
         instance.save()