adding test_append_tag_at_index
This commit is contained in:
parent
64409de63e
commit
ec74961762
23
buku
23
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
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user