From 43ba2a50f884188f4900f021bedcb9d2c662b80b Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Sun, 28 Apr 2019 08:12:00 +0800 Subject: [PATCH] new: dev: test export db simple case --- tests/test_bukuDb.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 2e33b3d..2d70eef 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -13,7 +13,7 @@ import urllib import zipfile from genericpath import exists from itertools import product -from tempfile import TemporaryDirectory +from tempfile import TemporaryDirectory, NamedTemporaryFile from unittest import mock import unittest @@ -1417,6 +1417,24 @@ def test_exclude_results_from_search(search_results, exclude_results, exp_res): assert exp_res == res +def test_exportdb_empty_db(): + with NamedTemporaryFile(delete=False) as f: + db = BukuDb(dbfile=f.name) + with NamedTemporaryFile(delete=False) as f2: + res = db.exportdb(f2.name) + assert not res + + +def test_exportdb_single_rec(tmpdir): + with NamedTemporaryFile(delete=False) as f: + db = BukuDb(dbfile=f.name) + db.add_rec('http://example.com') + exp_file = tmpdir.join('export') + db.exportdb(exp_file.strpath) + with open(exp_file) as f: + assert f.read() + + # Helper functions for testcases