Merge pull request #465 from rachmadaniHaryono/bugfix/update

simplify test_update_rec_update_all_bookmark
This commit is contained in:
Jana 2020-08-10 08:09:40 +05:30 committed by GitHub
commit 964746d323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 26 deletions

4
buku
View File

@ -337,6 +337,8 @@ class BukuCrypt:
BookmarkVar = Tuple[int, str, Optional[str], str, str, int]
# example:
# (1, 'http://example.com', 'example title', ',tags1,', 'randomdesc', 0))
class BukuDb:
@ -4181,7 +4183,7 @@ def print_rec_with_filter(records, field_filter=0):
sys.exit(1)
def print_single_rec(row, idx=0): # NOQA
def print_single_rec(row: BookmarkVar, idx: Optional[int] = 0): # NOQA
"""Print a single DB record.
Handles both search results and individual record.

View File

@ -1051,33 +1051,17 @@ def test_update_rec_invalid_tag(caplog, invalid_tag):
@pytest.mark.parametrize('read_in_retval', ['y', 'n', ''])
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)
caplog.set_level(logging.DEBUG)
with mock.patch('buku.read_in', return_value=read_in_retval):
import buku
bdb = buku.BukuDb()
bdb = 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)]:
print('caplog records: {}'.format(caplog.records))
for idx, record in enumerate(caplog.records):
print('idx:{};{};message:{};levelname:{}'.format(
idx, record, record.getMessage(), record.levelname))
else:
raise e
assert res if read_in_retval == 'y' else not res
if read_in_retval == 'y':
assert caplog.records[0].getMessage() == \
"update_rec query: " \
"\"UPDATE bookmarks SET tags = ?\", args: [',tags1,']"
else:
assert not caplog.records
@pytest.mark.parametrize(