mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 19:48:31 +02:00
fix handling of user input (stdin, input, getpass)
This commit is contained in:
parent
f7c12fbede
commit
a6694f5273
3 changed files with 31 additions and 18 deletions
|
@ -88,6 +88,7 @@ Feature: Multiple journals
|
|||
|
||||
Scenario: Don't overwrite main config when decrypting a journal in an alternate config
|
||||
Given the config "editor_encrypted.yaml" exists
|
||||
And we use the password "bad doggie no biscuit" if prompted
|
||||
And we use the config "basic_encrypted.yaml"
|
||||
When we run "jrnl --cf editor_encrypted.yaml --decrypt"
|
||||
Then the config should contain "encrypt: true"
|
||||
|
|
|
@ -182,6 +182,7 @@ def toml_version(working_dir):
|
|||
|
||||
@fixture
|
||||
def mock_password(request):
|
||||
def _mock_password():
|
||||
password = get_fixture(request, "password")
|
||||
user_input = get_fixture(request, "user_input")
|
||||
|
||||
|
@ -192,9 +193,11 @@ def mock_password(request):
|
|||
password = user_input.splitlines()
|
||||
|
||||
if not password:
|
||||
return {}
|
||||
password = Exception("Unexpected call for password")
|
||||
|
||||
return {"getpass": lambda: patch("getpass.getpass", side_effect=password)}
|
||||
return patch("getpass.getpass", side_effect=password)
|
||||
|
||||
return {"getpass": _mock_password}
|
||||
|
||||
|
||||
@fixture
|
||||
|
@ -219,14 +222,21 @@ def should_not():
|
|||
|
||||
@fixture
|
||||
def mock_user_input(request, is_tty):
|
||||
def _generator(target):
|
||||
def _mock_user_input():
|
||||
user_input = get_fixture(request, "user_input", "")
|
||||
user_input = user_input.splitlines() if is_tty else [user_input]
|
||||
|
||||
if not user_input:
|
||||
return {}
|
||||
user_input = Exception("Unexpected call for user input")
|
||||
|
||||
return patch(target, side_effect=user_input)
|
||||
|
||||
return _mock_user_input
|
||||
|
||||
return {
|
||||
"stdin": lambda: patch("sys.stdin.read", side_effect=user_input),
|
||||
"input": lambda: patch("builtins.input", side_effect=user_input),
|
||||
"stdin": _generator("sys.stdin.read"),
|
||||
"input": _generator("builtins.input"),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,10 +20,11 @@ def when_we_change_directory(directory_name):
|
|||
|
||||
|
||||
command = '(?P<command>[^"]+)'
|
||||
input_method = '(?P<input_method>enter|pipe)'
|
||||
input_method = "(?P<input_method>enter|pipe)"
|
||||
user_input = '(?P<user_input>[^"]+)'
|
||||
@when(re(f'we run "jrnl {command}" and {input_method}\n{user_input}'))
|
||||
@when(re(f'we run "jrnl" and {input_method}\n{user_input}'))
|
||||
|
||||
|
||||
@when(parse('we run "jrnl {command}" and {input_method}\n{user_input}'))
|
||||
@when(re(f'we run "jrnl {command}" and {input_method} "{user_input}"'))
|
||||
@when(re(f'we run "jrnl" and {input_method} "{user_input}"'))
|
||||
@when(parse('we run "jrnl {command}"'))
|
||||
|
@ -36,6 +37,7 @@ def we_run_jrnl(cli_run, capsys, keyring):
|
|||
with ExitStack() as stack:
|
||||
mocks = cli_run["mocks"]
|
||||
factories = cli_run["mock_factories"]
|
||||
|
||||
for id in factories:
|
||||
mocks[id] = stack.enter_context(factories[id]())
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue