commit
ff07e3a99b
34
buku
34
buku
@ -446,6 +446,21 @@ class BukuDb:
|
|||||||
:tag_manual: string of comma-separated tags to add manually
|
: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:
|
if index == 0:
|
||||||
resp = input('Tags will be appended for ALL bookmarks. Enter \x1b[1my\x1b[21m to confirm: ')
|
resp = input('Tags will be appended for ALL bookmarks. Enter \x1b[1my\x1b[21m to confirm: ')
|
||||||
if resp != 'y':
|
if resp != 'y':
|
||||||
@ -455,14 +470,6 @@ class BukuDb:
|
|||||||
else:
|
else:
|
||||||
self.cur.execute('SELECT id, tags FROM bookmarks WHERE id = ?', (index,))
|
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):
|
def delete_tag_at_index(self, index, tag_manual):
|
||||||
""" Delete tags for bookmark at index
|
""" Delete tags for bookmark at index
|
||||||
|
|
||||||
@ -723,8 +730,7 @@ class BukuDb:
|
|||||||
print('No bookmarks deleted')
|
print('No bookmarks deleted')
|
||||||
return
|
return
|
||||||
|
|
||||||
self.cur.execute('DROP TABLE if exists bookmarks')
|
self.delete_all_bookmarks()
|
||||||
self.conn.commit()
|
|
||||||
print('All bookmarks deleted')
|
print('All bookmarks deleted')
|
||||||
else: # Remove a single entry
|
else: # Remove a single entry
|
||||||
try:
|
try:
|
||||||
@ -738,6 +744,14 @@ class BukuDb:
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error('Index out of bound')
|
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):
|
def print_bookmark(self, index, empty=False):
|
||||||
"""Print bookmark details at index or all bookmarks if index is 0
|
"""Print bookmark details at index or all bookmarks if index is 0
|
||||||
Print only bookmarks with blank title or tag if empty is True
|
Print only bookmarks with blank title or tag if empty is True
|
||||||
|
@ -102,6 +102,22 @@ class TestBukuDb(unittest.TestCase):
|
|||||||
curr.close()
|
curr.close()
|
||||||
conn.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
|
||||||
|
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( len(self.bookmarks[0]) + 1 ))
|
||||||
|
|
||||||
# @unittest.skip('skipping')
|
# @unittest.skip('skipping')
|
||||||
def test_get_bookmark_index(self):
|
def test_get_bookmark_index(self):
|
||||||
bdb = BukuDb()
|
bdb = BukuDb()
|
||||||
@ -151,6 +167,24 @@ class TestBukuDb(unittest.TestCase):
|
|||||||
for pair in zip(from_db[1:], new_values):
|
for pair in zip(from_db[1:], new_values):
|
||||||
self.assertEqual(*pair)
|
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')
|
# @unittest.skip('skipping')
|
||||||
def test_refreshdb(self):
|
def test_refreshdb(self):
|
||||||
bdb = BukuDb()
|
bdb = BukuDb()
|
||||||
@ -178,7 +212,16 @@ class TestBukuDb(unittest.TestCase):
|
|||||||
from_db = bdb.get_bookmark_by_index(index)
|
from_db = bdb.get_bookmark_by_index(index)
|
||||||
self.assertIsNone(from_db)
|
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')
|
# @unittest.skip('skipping')
|
||||||
def test_replace_tag(self):
|
def test_replace_tag(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user