From 5c256943187757495057f3f34d87459ba78b2a6d Mon Sep 17 00:00:00 2001 From: poikjhn Date: Tue, 7 Jun 2016 06:22:38 +0200 Subject: [PATCH] adding test_replace_tag --- tests/test_bukuDb.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index c19379c..3644e95 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -38,6 +38,12 @@ class TestBukuDb(unittest.TestCase): 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", + ], ] def tearDown(self): @@ -175,8 +181,39 @@ class TestBukuDb(unittest.TestCase): # def test_list_tags(self): # self.fail() - # def test_replace_tag(self): - # self.fail() + # @unittest.skip('skipping') + def test_replace_tag(self): + bdb = BukuDb() + indices = [] + for bookmark in self.bookmarks: + # adding bookmark, getting index + bdb.add_bookmark(*bookmark) + index = bdb.get_bookmark_index(bookmark[0]) + indices += [index] + # replacing tags + bdb.replace_tag("news", ["__01"]) + bdb.replace_tag("zażółć", ["__02", "__03"]) + # replacing tag which is also a substring of other tag + bdb.replace_tag("es", ["__04"]) + # removing tags + bdb.replace_tag("gęślą") + bdb.replace_tag("old") + # removing nonexistent tag + bdb.replace_tag("_") + # removing nonexistent tag which is also a substring of other tag + bdb.replace_tag("e") + + for url, title, _, _ in self.bookmarks: + # retrieving from db + index = bdb.get_bookmark_index(url) + from_db = bdb.get_bookmark_by_index(index) + # asserting tags were replaced + if title == "SLASHDOT": + self.assertEqual(from_db[3], parse_tags(["__01"])) + elif title == "ZAŻÓŁĆ": + self.assertEqual(from_db[3], parse_tags(["__02", "__03", "jaźń"])) + elif title == "test": + self.assertEqual(from_db[3], parse_tags(["test", "tes", "est", "__04"])) # def test_browse_by_index(self): # self.fail()