adding test_compactdb

This commit is contained in:
poikjhn 2016-06-25 20:59:33 +02:00
parent ec2569f142
commit 7304fdbbeb

@ -17,6 +17,25 @@ TEST_TEMP_DBFILE_PATH = join(TEST_TEMP_DBDIR_PATH, 'bookmarks.db')
from buku import BukuDb, parse_tags
TEST_BOOKMARKS = [ ['http://slashdot.org',
'SLASHDOT',
parse_tags(['old,news']),
"News for old nerds, stuff that doesn't matter",
],
['http://www.zażółćgęśląjaźń.pl/',
'ZAŻÓŁĆ',
parse_tags(['zażółć,gęślą,jaźń']),
"Testing UTF-8, zażółć gęślą jaźń.",
],
['https://test.com:8080',
'test',
parse_tags(['test,tes,est,es']),
"a case for replace_tag test",
],
]
@pytest.fixture()
def setup():
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH
@ -34,24 +53,7 @@ class TestBukuDb(unittest.TestCase):
if exists(TEST_TEMP_DBFILE_PATH):
os.remove(TEST_TEMP_DBFILE_PATH)
self.bookmarks = [ ['http://slashdot.org',
'SLASHDOT',
parse_tags(['old,news']),
"News for old nerds, stuff that doesn't matter",
],
['http://www.zażółćgęśląjaźń.pl/',
'ZAŻÓŁĆ',
parse_tags(['zażółć,gęślą,jaźń']),
"Testing UTF-8, zażółć gęślą jaźń.",
],
['https://test.com:8080',
'test',
parse_tags(['test,tes,est,es']),
"a case for replace_tag test",
],
]
self.bookmarks = TEST_BOOKMARKS
def tearDown(self):
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH
@ -163,9 +165,6 @@ class TestBukuDb(unittest.TestCase):
# def test_search_by_tag(self):
# self.fail()
# def test_compactdb(self):
# self.fail()
# @unittest.skip('skipping')
def test_delete_bookmark(self):
bdb = BukuDb()
@ -270,19 +269,34 @@ def test_print_bookmark(capsys, setup):
def test_list_tags(capsys, setup):
bdb = BukuDb()
out, err = capsys.readouterr()
# adding bookmarks
bdb.add_bookmark("http://one.com", "", parse_tags(['cat,ant,bee,1']), "")
bdb.add_bookmark("http://two.com", "", parse_tags(['Cat,Ant,bee,1']), "")
bdb.add_bookmark("http://three.com", "", parse_tags(['Cat,Ant,3,Bee,2']), "")
out, err = capsys.readouterr()
# listing tags, asserting output
out, err = capsys.readouterr()
bdb.list_tags()
out, err = capsys.readouterr()
assert out == " 1. 1\n 2. 2\n 3. 3\n 4. Ant\n 5. ant\n 6. bee\n 7. Bee\n 8. Cat\n 9. cat\n"
assert err == ''
def test_compactdb(setup):
bdb = BukuDb()
# adding bookmarks
for bookmark in TEST_BOOKMARKS:
bdb.add_bookmark(*bookmark)
# manually deleting 2nd index from db, calling compactdb
bdb.cur.execute('DELETE FROM bookmarks WHERE id = ?', (2,))
bdb.compactdb(2)
# asserting bookmarks have correct indices
assert bdb.get_bookmark_by_index(1) == (1, 'http://slashdot.org', 'SLASHDOT', ',news,old,', "News for old nerds, stuff that doesn't matter")
assert bdb.get_bookmark_by_index(2) == (2, 'https://test.com:8080', 'test', ',es,est,tes,test,', 'a case for replace_tag test')
assert bdb.get_bookmark_by_index(3) is None
if __name__ == "__main__":
unittest.main()