From 076b2eda7a7a4999c789175b2e59a400d50ec2b0 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 21 Aug 2016 18:09:07 -0500 Subject: [PATCH 1/3] adding test_delete_all_bookmarks --- buku | 11 +++++++++-- tests/test_bukuDb.py | 11 ++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/buku b/buku index c109e9e..266e6c7 100755 --- a/buku +++ b/buku @@ -723,8 +723,7 @@ class BukuDb: print('No bookmarks deleted') return - self.cur.execute('DROP TABLE if exists bookmarks') - self.conn.commit() + self.delete_all_bookmarks() print('All bookmarks deleted') else: # Remove a single entry try: @@ -738,6 +737,14 @@ class BukuDb: except IndexError: logger.error('Index out of bound') + def delete_all_bookmarks(self): + """Should only be called inside of delete_bookmark + Drops the bookmark table if it exists + """ + + self.cur.execute('DROP TABLE if exists bookmarks') + self.conn.commit() + def print_bookmark(self, index, empty=False): """Print bookmark details at index or all bookmarks if index is 0 Print only bookmarks with blank title or tag if empty is True diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 68d030a..ae096ed 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -178,7 +178,16 @@ class TestBukuDb(unittest.TestCase): from_db = bdb.get_bookmark_by_index(index) self.assertIsNone(from_db) - # TODO: test deleting all bookmarks (index == 0) + # @unittest.skip('skipping') + def test_delete_all_bookmarks(self): + bdb = BukuDb() + # adding bookmarks + bdb.add_bookmark(*self.bookmarks[0]) + # deleting all bookmarks + bdb.delete_all_bookmarks() + # assert table has been dropped + with self.assertRaises(sqlite3.OperationalError): + bdb.get_bookmark_by_index(0) # @unittest.skip('skipping') def test_replace_tag(self): From 64409de63e7f3664d3111e6fd2a75cf5eb82ce25 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 21 Aug 2016 22:14:46 -0500 Subject: [PATCH 2/3] adding test_get_bookmark_by_index --- tests/test_bukuDb.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index ae096ed..32855b6 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -102,6 +102,22 @@ class TestBukuDb(unittest.TestCase): curr.close() conn.close() + # @unittest.skip('skipping') + def test_get_bookmark_by_index(self): + bdb = BukuDb() + for bookmark in self.bookmarks: + # adding bookmark from self.bookmarks + bdb.add_bookmark(*bookmark) + + # the expected bookmark at index 1 + expected = (1, 'http://slashdot.org', 'SLASHDOT', ',news,old,', + "News for old nerds, stuff that doesn't matter") + bookmark_from_db = bdb.get_bookmark_by_index(1) + # asserting bookmark matches expected + self.assertEqual(expected, bookmark_from_db) + # asserting None returned if index out of range + self.assertIsNone(bdb.get_bookmark_by_index(4)) + # @unittest.skip('skipping') def test_get_bookmark_index(self): bdb = BukuDb() From ec749617629077df8d29880c21c26a71fdad79ee Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 23 Aug 2016 01:10:14 -0500 Subject: [PATCH 3/3] adding test_append_tag_at_index --- buku | 23 +++++++++++++++-------- tests/test_bukuDb.py | 22 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/buku b/buku index 266e6c7..1061fc4 100755 --- a/buku +++ b/buku @@ -446,6 +446,21 @@ class BukuDb: :tag_manual: string of comma-separated tags to add manually """ + self.select_tags_from_bookmarks(index) + resultset = self.cur.fetchall() + for row in resultset: + tags = '%s%s' % (row[1], tag_manual[1:]) + tags = parse_tags([tags]) + self.cur.execute('UPDATE bookmarks SET tags = ? WHERE id = ?', (tags, row[0],)) + + self.conn.commit() + + def select_tags_from_bookmarks(self, index): + """ Select either the tags for one bookmark or all bookmarks + + :param index: int position of record, 0 for all + """ + if index == 0: resp = input('Tags will be appended for ALL bookmarks. Enter \x1b[1my\x1b[21m to confirm: ') if resp != 'y': @@ -455,14 +470,6 @@ class BukuDb: else: self.cur.execute('SELECT id, tags FROM bookmarks WHERE id = ?', (index,)) - resultset = self.cur.fetchall() - for row in resultset: - tags = '%s%s' % (row[1], tag_manual[1:]) - tags = parse_tags([tags]) - self.cur.execute('UPDATE bookmarks SET tags = ? WHERE id = ?', (tags, row[0],)) - - self.conn.commit() - def delete_tag_at_index(self, index, tag_manual): """ Delete tags for bookmark at index diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 32855b6..ca1238f 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -109,14 +109,14 @@ class TestBukuDb(unittest.TestCase): # adding bookmark from self.bookmarks bdb.add_bookmark(*bookmark) - # the expected bookmark at index 1 + # the expected bookmark expected = (1, 'http://slashdot.org', 'SLASHDOT', ',news,old,', "News for old nerds, stuff that doesn't matter") bookmark_from_db = bdb.get_bookmark_by_index(1) # asserting bookmark matches expected self.assertEqual(expected, bookmark_from_db) # asserting None returned if index out of range - self.assertIsNone(bdb.get_bookmark_by_index(4)) + self.assertIsNone(bdb.get_bookmark_by_index( len(self.bookmarks[0]) + 1 )) # @unittest.skip('skipping') def test_get_bookmark_index(self): @@ -167,6 +167,24 @@ class TestBukuDb(unittest.TestCase): for pair in zip(from_db[1:], new_values): self.assertEqual(*pair) + # @unittest.skip('skipping') + def test_append_tag_at_index(self): + bdb = BukuDb() + for bookmark in self.bookmarks: + bdb.add_bookmark(*bookmark) + + # tags to add + old_tags = bdb.get_bookmark_by_index(1)[3] + new_tags = ",foo,bar,baz" + bdb.append_tag_at_index(1, new_tags) + # updated list of tags + from_db = bdb.get_bookmark_by_index(1)[3] + + # checking if new tags were added to the bookmark + self.assertTrue(any( x in new_tags.split(',') for x in from_db.split(',') )) + # checking if old tags still exist + self.assertTrue(any( x in old_tags.split(',') for x in from_db.split(',') )) + # @unittest.skip('skipping') def test_refreshdb(self): bdb = BukuDb()