summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun <engineerarun@gmail.com>2024-11-17 07:25:07 +0530
committerGitHub <noreply@github.com>2024-11-17 07:25:07 +0530
commit789c08f51094eeb7c0ba4b439b173ae7a8f38aa9 (patch)
treedd0cc4a6ab31ebca2864bd1136c8263c43709f40
parentbfe195ee375e9e89bef6da4473e689441a095c12 (diff)
parentb506b75f83e402e5afbd8ab397df5c146b992844 (diff)
Merge pull request #797 from LeXofLeviafan/lock-specified-dbHEADmaster
[jarun#796] fixed DB not being passed to BukuCrypt from CLI
-rwxr-xr-xbuku8
-rw-r--r--tests/test_cli.py25
2 files changed, 29 insertions, 4 deletions
diff --git a/buku b/buku
index 5b4871f..d4a5894 100755
--- a/buku
+++ b/buku
@@ -6051,7 +6051,7 @@ POSITIONAL ARGUMENTS:
# Fix uppercase tags allowed in releases before v2.7
addarg('--fixtags', action='store_true', help=hide)
# App-use only, not for manual usage
- addarg('--db', nargs=1, help=hide)
+ addarg('--db', nargs=1, default=[None], help=hide)
# Parse the arguments
args = argparser.parse_args(argv)
@@ -6129,9 +6129,9 @@ POSITIONAL ARGUMENTS:
# Handle encrypt/decrypt options at top priority
if args.lock is not None:
- BukuCrypt.encrypt_file(args.lock)
+ BukuCrypt.encrypt_file(args.lock, dbfile=args.db[0])
elif args.unlock is not None:
- BukuCrypt.decrypt_file(args.unlock)
+ BukuCrypt.decrypt_file(args.unlock, dbfile=args.db[0])
order = [s for ss in (args.order or []) for s in re.split(r'\s*,\s*', ss.strip()) if s]
@@ -6184,7 +6184,7 @@ POSITIONAL ARGUMENTS:
args.json,
args.format,
not args.tacit,
- dbfile=args.db[0] if args.db is not None else None,
+ dbfile=args.db[0],
colorize=not args.nc
)
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 2191cdb..d46cc22 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -291,3 +291,28 @@ def test_random_export(_print_rec_with_filter, _sample, bdb, stdin, prompt, rand
calls += [mock.call.bdb.exportdb('export.md', res)]
calls += [mock.call.bdb.close_quit(0)]
assert wrap.mock_calls == calls
+
+
+@pytest.mark.parametrize('db', [None, './foo.db'])
+@pytest.mark.parametrize('action', ['print', 'lock', 'unlock'])
+@mock.patch('buku.BukuCrypt')
+def test_custom_db(_BukuCrypt, BukuDb, stdin, db, action):
+ wrap = mock.Mock()
+ wrap.attach_mock(BukuDb, 'BukuDb')
+ wrap.attach_mock(BukuDb.return_value, 'bdb')
+ wrap.attach_mock(_BukuCrypt, 'BukuCrypt')
+ BukuDb.return_value.get_max_id.return_value = None
+ argv = ['--nostdin'] + ([] if not db else ['--db', db]) + [f'--{action}']
+ with pytest.raises(SystemExit):
+ buku.main(argv)
+ calls = []
+ if action == 'lock':
+ calls += [mock.call.BukuCrypt.encrypt_file(8, dbfile=db)]
+ elif action == 'unlock':
+ calls += [mock.call.BukuCrypt.decrypt_file(8, dbfile=db)]
+ calls += [mock.call.BukuDb(None, 0, True, dbfile=db, colorize=True)]
+ if action == 'print':
+ calls += [mock.call.bdb.get_max_id(),
+ mock.call.bdb.print_rec(None, order=[])]
+ calls += [mock.call.bdb.close_quit(0)]
+ assert wrap.mock_calls == calls