Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_delete_rec_index_and_delay_commit(index, delay_commit, input_retval):
"""test delete rec, index and delay commit."""
bdb = BukuDb()
bdb_dc = BukuDb() # instance for delay_commit check.
# Fill bookmark
for bookmark in TEST_BOOKMARKS:
bdb.add_rec(*bookmark)
db_len = len(TEST_BOOKMARKS)
n_index = index
with mock.patch('builtins.input', return_value=input_retval):
res = bdb.delete_rec(index=index, delay_commit=delay_commit)
if n_index < 0:
assert not res
elif n_index > db_len:
assert not res
assert len(bdb.get_rec_all()) == db_len
def test_delete_rec_index_and_delay_commit(index, delay_commit, input_retval):
"""test delete rec, index and delay commit."""
bdb = BukuDb()
bdb_dc = BukuDb() # instance for delay_commit check.
# Fill bookmark
for bookmark in TEST_BOOKMARKS:
bdb.add_rec(*bookmark)
db_len = len(TEST_BOOKMARKS)
n_index = index
with mock.patch('builtins.input', return_value=input_retval):
res = bdb.delete_rec(index=index, delay_commit=delay_commit)
if n_index < 0:
assert not res
elif n_index > db_len:
assert not res
def test_delete_rec_range_and_delay_commit(setup, low, high, delay_commit, input_retval):
"""test delete rec, range and delay commit."""
bdb = BukuDb()
bdb_dc = BukuDb() # instance for delay_commit check.
index = 0
is_range = True
# Fill bookmark
for bookmark in TEST_BOOKMARKS:
bdb.add_rec(*bookmark)
db_len = len(TEST_BOOKMARKS)
# use normalized high and low variable
n_low, n_high = normalize_range(db_len=db_len, low=low, high=high)
exp_res = True
if n_high > db_len >= n_low:
exp_db_len = db_len - (db_len + 1 - n_low)
elif n_high == n_low > db_len:
exp_db_len = db_len
def test_update_rec_update_all_bookmark(caplog, read_in_retval):
"""test method."""
if (sys.version_info.major, sys.version_info.minor) == (3, 8):
caplog.set_level(logging.DEBUG)
with mock.patch('buku.read_in', return_value=read_in_retval):
import buku
bdb = buku.BukuDb()
res = bdb.update_rec(index=0, tags_in='tags1')
if read_in_retval != 'y':
assert not res
return
assert res
try:
if (sys.version_info.major, sys.version_info.minor) == (3, 8):
assert caplog.records[0].getMessage() == \
'update_rec query: "UPDATE bookmarks SET tags = ?", args: [\',tags1,\']'
else:
assert caplog.records[0].getMessage() == \
'query: "UPDATE bookmarks SET tags = ?", args: [\',tags1\']'
assert caplog.records[0].levelname == 'DEBUG'
except IndexError as e:
# TODO: fix test
if (sys.version_info.major, sys.version_info.minor) in [(3, 4), (3, 5), (3, 6), (3, 7)]:
def test_list_tags(capsys, setup):
bdb = BukuDb()
# adding bookmarks
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()
prompt(bdb, None, True, listtags=True)
out, err = capsys.readouterr()
assert out == " 1. 1 (2)\n 2. 2 (1)\n 3. 3 (1)\n 4. ant (3)\n 5. bee (3)\n 6. cat (3)\n\n"
assert err == ''
def test_compactdb(setup):
bdb = BukuDb()
# adding bookmarks
for bookmark in TEST_BOOKMARKS:
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_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, 'http://example.com/', 'test', ',es,est,tes,test,', 'a case for replace_tag test', 0)
assert bdb.get_rec_by_id(3) is None
def test_print_rec_hypothesis(caplog, setup, index, low, high, is_range):
"""test when index, low or high is less than 0."""
# setup
caplog.handler.records.clear()
caplog.records.clear()
bdb = BukuDb()
# clear all record first before testing
bdb.delete_rec_all()
bdb.add_rec("http://one.com", "", parse_tags(['cat,ant,bee,1']), "")
db_len = 1
bdb.print_rec(index=index, low=low, high=high, is_range=is_range)
check_print = False
err_msg = ['Actual log:']
err_msg.extend(['{}:{}'.format(x.levelname, x.getMessage()) for x in caplog.records])
if index < 0 or (0 <= index <= db_len and not is_range):
check_print = True
# negative index/range on is_range
elif (is_range and any([low < 0, high < 0])):
assert any([x.levelname == "ERROR" for x in caplog.records]), \
'\n'.join(err_msg)
def test_add_rec_add_invalid_url(caplog, url):
"""test method."""
bdb = BukuDb()
res = bdb.add_rec(url=url)
assert res == -1
caplog.records[0].levelname == 'ERROR'
caplog.records[0].getMessage() == 'Invalid URL'
def __init__(self, api_key, filters=None, private_only=False, public_only=False, toread_only=False, read_only=False):
self.buku = buku.BukuDb()
self.pb = pinboard.Pinboard(api_key)
self.filters = filters
self.private_only = private_only
self.public_only = public_only
self.toread_only = toread_only
self.read_only = read_only