Use _rec instead of _bm.
This commit is contained in:
parent
9c7768e84d
commit
84834a2355
83
buku.py
83
buku.py
@ -70,7 +70,7 @@ logdbg = logger.debug
|
||||
logerr = logger.error
|
||||
|
||||
|
||||
class BMHTMLParser(HTMLParser.HTMLParser):
|
||||
class BukuHTMLParser(HTMLParser.HTMLParser):
|
||||
'''Class to parse and fetch the title
|
||||
from a HTML page, if available
|
||||
'''
|
||||
@ -446,7 +446,7 @@ class BukuDb:
|
||||
|
||||
return (conn, cur)
|
||||
|
||||
def get_bm_by_id(self, index):
|
||||
def get_rec_by_id(self, index):
|
||||
'''Get a bookmark from database by its ID.
|
||||
|
||||
:return: bookmark data as a tuple, or None, if index is not found
|
||||
@ -459,7 +459,7 @@ class BukuDb:
|
||||
else:
|
||||
return results[0]
|
||||
|
||||
def get_bm_id(self, url):
|
||||
def get_rec_id(self, url):
|
||||
'''Check if URL already exists in DB
|
||||
|
||||
:param url: URL to search
|
||||
@ -473,8 +473,8 @@ class BukuDb:
|
||||
|
||||
return resultset[0][0]
|
||||
|
||||
def add_bm(self, url, title_in=None, tags_in=None, desc=None, immutable=0,
|
||||
delay_commit=False):
|
||||
def add_rec(self, url, title_in=None, tags_in=None, desc=None, immutable=0,
|
||||
delay_commit=False):
|
||||
'''Add a new bookmark
|
||||
|
||||
:param url: URL to bookmark
|
||||
@ -493,7 +493,7 @@ class BukuDb:
|
||||
return False
|
||||
|
||||
# Ensure that the URL does not exist in DB already
|
||||
id = self.get_bm_id(url)
|
||||
id = self.get_rec_id(url)
|
||||
if id != -1:
|
||||
logerr('URL [%s] already exists at index %d', url, id)
|
||||
return False
|
||||
@ -536,10 +536,10 @@ class BukuDb:
|
||||
if not delay_commit:
|
||||
self.conn.commit()
|
||||
if self.chatty:
|
||||
self.print_bm(self.cur.lastrowid)
|
||||
self.print_rec(self.cur.lastrowid)
|
||||
return True
|
||||
except Exception as e:
|
||||
logerr('add_bm(): %s', e)
|
||||
logerr('add_rec(): %s', e)
|
||||
return False
|
||||
|
||||
def append_tag_at_index(self, index, tags_in):
|
||||
@ -567,7 +567,7 @@ class BukuDb:
|
||||
tags = parse_tags([tags])
|
||||
self.cur.execute(query, (tags, row[0],))
|
||||
if self.chatty:
|
||||
self.print_bm(row[0])
|
||||
self.print_rec(row[0])
|
||||
|
||||
self.conn.commit()
|
||||
return True
|
||||
@ -613,14 +613,14 @@ class BukuDb:
|
||||
|
||||
self.cur.execute(query, (parse_tags([tags]), row[0],))
|
||||
if self.chatty:
|
||||
self.print_bm(row[0])
|
||||
self.print_rec(row[0])
|
||||
|
||||
self.conn.commit()
|
||||
|
||||
return True
|
||||
|
||||
def update_bm(self, index, url=None, title_in=None, tags_in=None,
|
||||
desc=None, immutable=-1, threads=4):
|
||||
def update_rec(self, index, url=None, title_in=None, tags_in=None,
|
||||
desc=None, immutable=-1, threads=4):
|
||||
'''Update an existing record at index
|
||||
Update all records if index is 0 and url is not specified.
|
||||
URL is an exception because URLs are unique in DB.
|
||||
@ -712,7 +712,7 @@ class BukuDb:
|
||||
elif not to_update and not tag_modified:
|
||||
ret = self.refreshdb(index, threads)
|
||||
if ret and index and self.chatty:
|
||||
self.print_bm(index)
|
||||
self.print_rec(index)
|
||||
return ret
|
||||
|
||||
if title_to_insert is not None:
|
||||
@ -739,7 +739,7 @@ class BukuDb:
|
||||
self.cur.execute(query, arguments)
|
||||
self.conn.commit()
|
||||
if self.cur.rowcount and self.chatty:
|
||||
self.print_bm(index)
|
||||
self.print_rec(index)
|
||||
|
||||
if self.cur.rowcount == 0:
|
||||
logerr('No matching index %d', index)
|
||||
@ -983,8 +983,8 @@ class BukuDb:
|
||||
self.conn.commit()
|
||||
print('Index %d moved to %d' % (row[0], index))
|
||||
|
||||
def delete_bm(self, index, low=0, high=0, is_range=False,
|
||||
delay_commit=False):
|
||||
def delete_rec(self, index, low=0, high=0, is_range=False,
|
||||
delay_commit=False):
|
||||
'''Delete a single record or remove the table if index is None
|
||||
|
||||
:param index: DB index of deleted entry
|
||||
@ -1056,7 +1056,7 @@ class BukuDb:
|
||||
pos = len(results) - 1
|
||||
while pos >= 0:
|
||||
idx = results[pos][0]
|
||||
self.delete_bm(idx, delay_commit=True)
|
||||
self.delete_rec(idx, delay_commit=True)
|
||||
|
||||
# Commit at every 200th removal
|
||||
if pos % 200 == 0:
|
||||
@ -1082,7 +1082,7 @@ class BukuDb:
|
||||
print('All bookmarks deleted')
|
||||
return True
|
||||
|
||||
def print_bm(self, index):
|
||||
def print_rec(self, index):
|
||||
'''Print bookmark details at index or all bookmarks if index is 0
|
||||
Note: URL is printed on top because title may be blank
|
||||
|
||||
@ -1360,10 +1360,10 @@ Buku bookmarks</H3>
|
||||
if comment_tag:
|
||||
desc = comment_tag.text[0:comment_tag.text.find('\n')]
|
||||
|
||||
self.add_bm(tag['href'], tag.string, ('%s%s%s' %
|
||||
(DELIM, tag['tags'], DELIM))
|
||||
if tag.has_attr('tags') else None,
|
||||
desc, 0, True)
|
||||
self.add_rec(tag['href'], tag.string, ('%s%s%s' %
|
||||
(DELIM, tag['tags'], DELIM))
|
||||
if tag.has_attr('tags') else None,
|
||||
desc, 0, True)
|
||||
|
||||
self.conn.commit()
|
||||
infp.close()
|
||||
@ -1385,7 +1385,7 @@ Buku bookmarks</H3>
|
||||
# Parse url
|
||||
url = line[index + 2:index + 2 + url_end_delim]
|
||||
|
||||
self.add_bm(url, title, None, None, 0, True)
|
||||
self.add_rec(url, title, None, None, 0, True)
|
||||
|
||||
self.conn.commit()
|
||||
infp.close()
|
||||
@ -1415,7 +1415,7 @@ Buku bookmarks</H3>
|
||||
|
||||
resultset = indb_cur.fetchall()
|
||||
for row in resultset:
|
||||
self.add_bm(row[1], row[2], row[3], row[4], row[5], True)
|
||||
self.add_rec(row[1], row[2], row[3], row[4], row[5], True)
|
||||
|
||||
if len(resultset):
|
||||
self.conn.commit()
|
||||
@ -1575,7 +1575,7 @@ def get_page_title(resp):
|
||||
:return: title fetched from parsed page
|
||||
'''
|
||||
|
||||
parser = BMHTMLParser()
|
||||
parser = BukuHTMLParser()
|
||||
|
||||
try:
|
||||
parser.feed(resp.data.decode(errors='replace'))
|
||||
@ -2455,7 +2455,7 @@ def main():
|
||||
if len(keywords) > 1:
|
||||
tags = parse_tags(keywords[1:])
|
||||
|
||||
bdb.add_bm(args.add[0], title_in, tags, desc_in, args.immutable)
|
||||
bdb.add_rec(args.add[0], title_in, tags, desc_in, args.immutable)
|
||||
|
||||
# Update record
|
||||
if update:
|
||||
@ -2476,13 +2476,13 @@ def main():
|
||||
tags = None
|
||||
|
||||
if len(args.update) == 0:
|
||||
bdb.update_bm(0, url_in, title_in, tags, desc_in, args.immutable,
|
||||
args.threads)
|
||||
bdb.update_rec(0, url_in, title_in, tags, desc_in, args.immutable,
|
||||
args.threads)
|
||||
else:
|
||||
for idx in args.update:
|
||||
if is_int(idx):
|
||||
bdb.update_bm(int(idx), url_in, title_in, tags, desc_in,
|
||||
args.immutable, args.threads)
|
||||
bdb.update_rec(int(idx), url_in, title_in, tags, desc_in,
|
||||
args.immutable, args.threads)
|
||||
elif '-' in idx and is_int(idx.split('-')[0]) \
|
||||
and is_int(idx.split('-')[1]):
|
||||
lower = int(idx.split('-')[0])
|
||||
@ -2492,12 +2492,13 @@ def main():
|
||||
|
||||
# Update only once if range starts from 0 (all)
|
||||
if lower == 0:
|
||||
bdb.update_bm(0, url_in, title_in, tags, desc_in,
|
||||
args.immutable, args.threads)
|
||||
bdb.update_rec(0, url_in, title_in, tags, desc_in,
|
||||
args.immutable, args.threads)
|
||||
else:
|
||||
for _id in range(lower, upper + 1):
|
||||
bdb.update_bm(_id, url_in, title_in, tags, desc_in,
|
||||
args.immutable, args.threads)
|
||||
bdb.update_rec(_id, url_in, title_in, tags,
|
||||
desc_in, args.immutable,
|
||||
args.threads)
|
||||
if interrupted:
|
||||
break
|
||||
|
||||
@ -2554,11 +2555,11 @@ def main():
|
||||
vals = str(args.delete[0]).split('-')
|
||||
if len(vals) == 2 and is_int(vals[0]) and is_int(vals[1]):
|
||||
if int(vals[0]) == int(vals[1]):
|
||||
bdb.delete_bm(int(vals[0]))
|
||||
bdb.delete_rec(int(vals[0]))
|
||||
elif int(vals[0]) < int(vals[1]):
|
||||
bdb.delete_bm(0, int(vals[0]), int(vals[1]), True)
|
||||
bdb.delete_rec(0, int(vals[0]), int(vals[1]), True)
|
||||
else:
|
||||
bdb.delete_bm(0, int(vals[1]), int(vals[0]), True)
|
||||
bdb.delete_rec(0, int(vals[1]), int(vals[0]), True)
|
||||
else:
|
||||
logerr('Invalid index or range')
|
||||
bdb.close_quit(1)
|
||||
@ -2573,18 +2574,18 @@ def main():
|
||||
# Index delete order - highest to lowest
|
||||
ids.sort(key=lambda x: int(x), reverse=True)
|
||||
for idx in ids:
|
||||
bdb.delete_bm(int(idx))
|
||||
bdb.delete_rec(int(idx))
|
||||
except ValueError:
|
||||
logerr('Invalid index or range')
|
||||
|
||||
# Print records
|
||||
if args.print is not None:
|
||||
if len(args.print) == 0:
|
||||
bdb.print_bm(0)
|
||||
bdb.print_rec(0)
|
||||
else:
|
||||
for idx in args.print:
|
||||
if is_int(idx):
|
||||
bdb.print_bm(int(idx))
|
||||
bdb.print_rec(int(idx))
|
||||
elif '-' in idx and is_int(idx.split('-')[0]) \
|
||||
and is_int(idx.split('-')[1]):
|
||||
lower = int(idx.split('-')[0])
|
||||
@ -2592,7 +2593,7 @@ def main():
|
||||
if lower > upper:
|
||||
lower, upper = upper, lower
|
||||
for _id in range(lower, upper + 1):
|
||||
bdb.print_bm(_id)
|
||||
bdb.print_rec(_id)
|
||||
else:
|
||||
logerr('Invalid index or range')
|
||||
bdb.close_quit(1)
|
||||
|
@ -103,41 +103,41 @@ class TestBukuDb(unittest.TestCase):
|
||||
conn.close()
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_get_bm_by_id(self):
|
||||
def test_get_rec_by_id(self):
|
||||
for bookmark in self.bookmarks:
|
||||
# adding bookmark from self.bookmarks
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
|
||||
# the expected bookmark
|
||||
expected = (1, 'http://slashdot.org', 'SLASHDOT', ',news,old,',
|
||||
"News for old nerds, stuff that doesn't matter", 0)
|
||||
bookmark_from_db = self.bdb.get_bm_by_id(1)
|
||||
bookmark_from_db = self.bdb.get_rec_by_id(1)
|
||||
# asserting bookmark matches expected
|
||||
self.assertEqual(expected, bookmark_from_db)
|
||||
# asserting None returned if index out of range
|
||||
self.assertIsNone(self.bdb.get_bm_by_id(len(self.bookmarks[0]) + 1))
|
||||
self.assertIsNone(self.bdb.get_rec_by_id(len(self.bookmarks[0]) + 1))
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_get_bm_id(self):
|
||||
def test_get_rec_id(self):
|
||||
for idx, bookmark in enumerate(self.bookmarks):
|
||||
# adding bookmark from self.bookmarks to database
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
# asserting index is in order
|
||||
idx_from_db = self.bdb.get_bm_id(bookmark[0])
|
||||
idx_from_db = self.bdb.get_rec_id(bookmark[0])
|
||||
self.assertEqual(idx + 1, idx_from_db)
|
||||
|
||||
# asserting -1 is returned for nonexistent url
|
||||
idx_from_db = self.bdb.get_bm_id("http://nonexistent.url")
|
||||
idx_from_db = self.bdb.get_rec_id("http://nonexistent.url")
|
||||
self.assertEqual(-1, idx_from_db)
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_add_bm(self):
|
||||
def test_add_rec(self):
|
||||
for bookmark in self.bookmarks:
|
||||
# adding bookmark from self.bookmarks to database
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
# retrieving bookmark from database
|
||||
index = self.bdb.get_bm_id(bookmark[0])
|
||||
from_db = self.bdb.get_bm_by_id(index)
|
||||
index = self.bdb.get_rec_id(bookmark[0])
|
||||
from_db = self.bdb.get_rec_by_id(index)
|
||||
self.assertIsNotNone(from_db)
|
||||
# comparing data
|
||||
for pair in zip(from_db[1:], bookmark):
|
||||
@ -146,17 +146,17 @@ class TestBukuDb(unittest.TestCase):
|
||||
# TODO: tags should be passed to the api as a sequence...
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_update_bm(self):
|
||||
def test_update_rec(self):
|
||||
old_values = self.bookmarks[0]
|
||||
new_values = self.bookmarks[1]
|
||||
|
||||
# adding bookmark and getting index
|
||||
self.bdb.add_bm(*old_values)
|
||||
index = self.bdb.get_bm_id(old_values[0])
|
||||
self.bdb.add_rec(*old_values)
|
||||
index = self.bdb.get_rec_id(old_values[0])
|
||||
# updating with new values
|
||||
self.bdb.update_bm(index, *new_values)
|
||||
self.bdb.update_rec(index, *new_values)
|
||||
# retrieving bookmark from database
|
||||
from_db = self.bdb.get_bm_by_id(index)
|
||||
from_db = self.bdb.get_rec_by_id(index)
|
||||
self.assertIsNotNone(from_db)
|
||||
# checking if values are updated
|
||||
for pair in zip(from_db[1:], new_values):
|
||||
@ -165,14 +165,14 @@ class TestBukuDb(unittest.TestCase):
|
||||
# @unittest.skip('skipping')
|
||||
def test_append_tag_at_index(self):
|
||||
for bookmark in self.bookmarks:
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
|
||||
# tags to add
|
||||
old_tags = self.bdb.get_bm_by_id(1)[3]
|
||||
old_tags = self.bdb.get_rec_by_id(1)[3]
|
||||
new_tags = ",foo,bar,baz"
|
||||
self.bdb.append_tag_at_index(1, new_tags)
|
||||
# updated list of tags
|
||||
from_db = self.bdb.get_bm_by_id(1)[3]
|
||||
from_db = self.bdb.get_rec_by_id(1)[3]
|
||||
|
||||
# checking if new tags were added to the bookmark
|
||||
self.assertTrue(split_and_test_membership(new_tags, from_db))
|
||||
@ -182,17 +182,17 @@ class TestBukuDb(unittest.TestCase):
|
||||
# @unittest.skip('skipping')
|
||||
def test_append_tag_at_all_indices(self):
|
||||
for bookmark in self.bookmarks:
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
|
||||
# tags to add
|
||||
new_tags = ",foo,bar,baz"
|
||||
# record of original tags for each bookmark
|
||||
old_tagsets = {i: self.bdb.get_bm_by_id(i)[3] for i in inclusive_range(1, len(self.bookmarks))}
|
||||
old_tagsets = {i: self.bdb.get_rec_by_id(i)[3] for i in inclusive_range(1, len(self.bookmarks))}
|
||||
|
||||
with mock.patch('builtins.input', return_value='y'):
|
||||
self.bdb.append_tag_at_index(0, new_tags)
|
||||
# updated tags for each bookmark
|
||||
from_db = [(i, self.bdb.get_bm_by_id(i)[3]) for i in inclusive_range(1, len(self.bookmarks))]
|
||||
from_db = [(i, self.bdb.get_rec_by_id(i)[3]) for i in inclusive_range(1, len(self.bookmarks))]
|
||||
for index, tagset in from_db:
|
||||
# checking if new tags added to bookmark
|
||||
self.assertTrue(split_and_test_membership(new_tags, tagset))
|
||||
@ -203,9 +203,9 @@ class TestBukuDb(unittest.TestCase):
|
||||
def test_delete_tag_at_index(self):
|
||||
# adding bookmarks
|
||||
for bookmark in self.bookmarks:
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
|
||||
get_tags_at_idx = lambda i: self.bdb.get_bm_by_id(i)[3]
|
||||
get_tags_at_idx = lambda i: self.bdb.get_rec_by_id(i)[3]
|
||||
# list of two-tuples, each containg bookmark index and corresponding tags
|
||||
tags_by_index = [(i, get_tags_at_idx(i)) for i in inclusive_range(1, len(self.bookmarks))]
|
||||
|
||||
@ -219,16 +219,16 @@ class TestBukuDb(unittest.TestCase):
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_refreshdb(self):
|
||||
self.bdb.add_bm("https://www.google.com/ncr", "?")
|
||||
self.bdb.add_rec("https://www.google.com/ncr", "?")
|
||||
self.bdb.refreshdb(1)
|
||||
from_db = self.bdb.get_bm_by_id(1)
|
||||
from_db = self.bdb.get_rec_by_id(1)
|
||||
self.assertEqual(from_db[2], "Google")
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_searchdb(self):
|
||||
# adding bookmarks
|
||||
for bookmark in self.bookmarks:
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
|
||||
get_first_tag = lambda x: ''.join(x[2].split(',')[:2])
|
||||
for i, bookmark in enumerate(self.bookmarks):
|
||||
@ -250,7 +250,7 @@ class TestBukuDb(unittest.TestCase):
|
||||
def test_search_by_tag(self):
|
||||
# adding bookmarks
|
||||
for bookmark in self.bookmarks:
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
|
||||
with mock.patch('buku.prompt'):
|
||||
get_first_tag = lambda x: ''.join(x[2].split(',')[:2])
|
||||
@ -266,7 +266,7 @@ class TestBukuDb(unittest.TestCase):
|
||||
def test_search_and_open_in_broswer_by_range(self):
|
||||
# adding bookmarks
|
||||
for bookmark in self.bookmarks:
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
|
||||
# simulate user input, select range of indices 1-3
|
||||
index_range = '1-%s' % len(self.bookmarks)
|
||||
@ -293,7 +293,7 @@ class TestBukuDb(unittest.TestCase):
|
||||
def test_search_and_open_all_in_browser(self):
|
||||
# adding bookmarks
|
||||
for bookmark in self.bookmarks:
|
||||
self.bdb.add_bm(*bookmark)
|
||||
self.bdb.add_rec(*bookmark)
|
||||
|
||||
# simulate user input, select 'a' to open all bookmarks in results
|
||||
with mock.patch('builtins.input', side_effect=['a']):
|
||||
@ -316,38 +316,38 @@ class TestBukuDb(unittest.TestCase):
|
||||
self.assertEqual(arg_list, expected)
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_delete_bm(self):
|
||||
def test_delete_rec(self):
|
||||
# adding bookmark and getting index
|
||||
self.bdb.add_bm(*self.bookmarks[0])
|
||||
index = self.bdb.get_bm_id(self.bookmarks[0][0])
|
||||
self.bdb.add_rec(*self.bookmarks[0])
|
||||
index = self.bdb.get_rec_id(self.bookmarks[0][0])
|
||||
# deleting bookmark
|
||||
self.bdb.delete_bm(index)
|
||||
self.bdb.delete_rec(index)
|
||||
# asserting it doesn't exist
|
||||
from_db = self.bdb.get_bm_by_id(index)
|
||||
from_db = self.bdb.get_rec_by_id(index)
|
||||
self.assertIsNone(from_db)
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_delete_bm_yes(self):
|
||||
# checking that "y" response causes delete_bm to return True
|
||||
def test_delete_rec_yes(self):
|
||||
# checking that "y" response causes delete_rec to return True
|
||||
with mock.patch('builtins.input', return_value='y'):
|
||||
self.assertTrue(self.bdb.delete_bm(0))
|
||||
self.assertTrue(self.bdb.delete_rec(0))
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_delete_bm_no(self):
|
||||
# checking that non-"y" response causes delete_bm to return None
|
||||
def test_delete_rec_no(self):
|
||||
# checking that non-"y" response causes delete_rec to return None
|
||||
with mock.patch('builtins.input', return_value='n'):
|
||||
self.assertFalse(self.bdb.delete_bm(0))
|
||||
self.assertFalse(self.bdb.delete_rec(0))
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
def test_cleardb(self):
|
||||
# adding bookmarks
|
||||
self.bdb.add_bm(*self.bookmarks[0])
|
||||
self.bdb.add_rec(*self.bookmarks[0])
|
||||
# deleting all bookmarks
|
||||
with mock.patch('builtins.input', return_value='y'):
|
||||
self.bdb.cleardb()
|
||||
# assert table has been dropped
|
||||
with self.assertRaises(sqlite3.OperationalError) as ctx_man:
|
||||
self.bdb.get_bm_by_id(0)
|
||||
self.bdb.get_rec_by_id(0)
|
||||
|
||||
err_msg = str(ctx_man.exception)
|
||||
self.assertEqual(err_msg, 'no such table: bookmarks')
|
||||
@ -357,8 +357,8 @@ class TestBukuDb(unittest.TestCase):
|
||||
indices = []
|
||||
for bookmark in self.bookmarks:
|
||||
# adding bookmark, getting index
|
||||
self.bdb.add_bm(*bookmark)
|
||||
index = self.bdb.get_bm_id(bookmark[0])
|
||||
self.bdb.add_rec(*bookmark)
|
||||
index = self.bdb.get_rec_id(bookmark[0])
|
||||
indices += [index]
|
||||
# replacing tags
|
||||
self.bdb.replace_tag("news", ["__01"])
|
||||
@ -375,8 +375,8 @@ class TestBukuDb(unittest.TestCase):
|
||||
|
||||
for url, title, _, _ in self.bookmarks:
|
||||
# retrieving from db
|
||||
index = self.bdb.get_bm_id(url)
|
||||
from_db = self.bdb.get_bm_by_id(index)
|
||||
index = self.bdb.get_rec_id(url)
|
||||
from_db = self.bdb.get_rec_by_id(index)
|
||||
# asserting tags were replaced
|
||||
if title == "SLASHDOT":
|
||||
self.assertEqual(from_db[3], parse_tags(["__01"]))
|
||||
@ -405,11 +405,11 @@ class TestBukuDb(unittest.TestCase):
|
||||
# self.fail()
|
||||
|
||||
|
||||
def test_print_bm(capsys, caplog, setup):
|
||||
def test_print_rec(capsys, caplog, setup):
|
||||
bdb = BukuDb()
|
||||
out, err = capsys.readouterr()
|
||||
# calling with nonexistent index
|
||||
bdb.print_bm(1)
|
||||
bdb.print_rec(1)
|
||||
out, err = capsys.readouterr()
|
||||
|
||||
for record in caplog.records():
|
||||
@ -418,26 +418,26 @@ def test_print_bm(capsys, caplog, setup):
|
||||
assert (out, err) == ('', '')
|
||||
|
||||
# adding bookmarks
|
||||
bdb.add_bm("http://full-bookmark.com", "full", parse_tags(['full,bookmark']), "full bookmark")
|
||||
bdb.add_bm("http://blank-title.com", "", parse_tags(['blank,title']), "blank title")
|
||||
bdb.add_bm("http://empty-tags.com", "empty tags", parse_tags(['']), "empty tags")
|
||||
bdb.add_bm("http://all-empty.com", "", parse_tags(['']), "all empty")
|
||||
bdb.add_rec("http://full-bookmark.com", "full", parse_tags(['full,bookmark']), "full bookmark")
|
||||
bdb.add_rec("http://blank-title.com", "", parse_tags(['blank,title']), "blank title")
|
||||
bdb.add_rec("http://empty-tags.com", "empty tags", parse_tags(['']), "empty tags")
|
||||
bdb.add_rec("http://all-empty.com", "", parse_tags(['']), "all empty")
|
||||
out, err = capsys.readouterr()
|
||||
|
||||
# printing first bookmark
|
||||
bdb.print_bm(1)
|
||||
bdb.print_rec(1)
|
||||
out, err = capsys.readouterr()
|
||||
assert out == "\x1b[1m\x1b[93m1. \x1b[0m\x1b[92mhttp://full-bookmark.com\x1b[0m\n \x1b[91m>\x1b[0m full\n \x1b[91m+\x1b[0m full bookmark\n \x1b[91m#\x1b[0m bookmark,full\n\n"
|
||||
assert err == ''
|
||||
|
||||
# printing all bookmarks
|
||||
bdb.print_bm(0)
|
||||
bdb.print_rec(0)
|
||||
out, err = capsys.readouterr()
|
||||
assert out == "\x1b[1m\x1b[93m1. \x1b[0m\x1b[92mhttp://full-bookmark.com\x1b[0m\n \x1b[91m>\x1b[0m full\n \x1b[91m+\x1b[0m full bookmark\n \x1b[91m#\x1b[0m bookmark,full\n\n\x1b[1m\x1b[93m2. \x1b[0m\x1b[92mhttp://blank-title.com\x1b[0m\n \x1b[91m+\x1b[0m blank title\n \x1b[91m#\x1b[0m blank,title\n\n\x1b[1m\x1b[93m3. \x1b[0m\x1b[92mhttp://empty-tags.com\x1b[0m\n \x1b[91m>\x1b[0m empty tags\n \x1b[91m+\x1b[0m empty tags\n\n\x1b[1m\x1b[93m4. \x1b[0m\x1b[92mhttp://all-empty.com\x1b[0m\n \x1b[91m+\x1b[0m all empty\n\n"
|
||||
assert err == ''
|
||||
|
||||
# printing all bookmarks with empty fields
|
||||
bdb.print_bm(0, empty=True)
|
||||
bdb.print_rec(0, empty=True)
|
||||
out, err = capsys.readouterr()
|
||||
assert out == "\x1b[1m3 records found\x1b[21m\n\n\x1b[1m\x1b[93m2. \x1b[0m\x1b[92mhttp://blank-title.com\x1b[0m\n \x1b[91m+\x1b[0m blank title\n \x1b[91m#\x1b[0m blank,title\n\n\x1b[1m\x1b[93m3. \x1b[0m\x1b[92mhttp://empty-tags.com\x1b[0m\n \x1b[91m>\x1b[0m empty tags\n \x1b[91m+\x1b[0m empty tags\n\n\x1b[1m\x1b[93m4. \x1b[0m\x1b[92mhttp://all-empty.com\x1b[0m\n \x1b[91m+\x1b[0m all empty\n\n"
|
||||
assert err == ''
|
||||
@ -447,9 +447,9 @@ def test_list_tags(capsys, setup):
|
||||
bdb = BukuDb()
|
||||
|
||||
# adding bookmarks
|
||||
bdb.add_bm("http://one.com", "", parse_tags(['cat,ant,bee,1']), "")
|
||||
bdb.add_bm("http://two.com", "", parse_tags(['Cat,Ant,bee,1']), "")
|
||||
bdb.add_bm("http://three.com", "", parse_tags(['Cat,Ant,3,Bee,2']), "")
|
||||
bdb.add_rec("http://one.com", "", parse_tags(['cat,ant,bee,1']), "")
|
||||
bdb.add_rec("http://two.com", "", parse_tags(['Cat,Ant,bee,1']), "")
|
||||
bdb.add_rec("http://three.com", "", parse_tags(['Cat,Ant,3,Bee,2']), "")
|
||||
|
||||
# listing tags, asserting output
|
||||
out, err = capsys.readouterr()
|
||||
@ -464,16 +464,16 @@ def test_compactdb(setup):
|
||||
|
||||
# adding bookmarks
|
||||
for bookmark in TEST_BOOKMARKS:
|
||||
bdb.add_bm(*bookmark)
|
||||
bdb.add_rec(*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_bm_by_id(1) == (1, 'http://slashdot.org', 'SLASHDOT', ',news,old,', "News for old nerds, stuff that doesn't matter", 0)
|
||||
assert bdb.get_bm_by_id(2) == (2, 'https://test.com:8080', 'test', ',es,est,tes,test,', 'a case for replace_tag test', 0)
|
||||
assert bdb.get_bm_by_id(3) is None
|
||||
assert bdb.get_rec_by_id(1) == (1, 'http://slashdot.org', 'SLASHDOT', ',news,old,', "News for old nerds, stuff that doesn't matter", 0)
|
||||
assert bdb.get_rec_by_id(2) == (2, 'https://test.com:8080', 'test', ',es,est,tes,test,', 'a case for replace_tag test', 0)
|
||||
assert bdb.get_rec_by_id(3) is None
|
||||
|
||||
# Helper functions for testcases
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user