update password mock to use rich console instead of getpass

This commit is contained in:
Jonathan Wren 2022-05-28 13:52:17 -07:00
parent 4636f1a3ef
commit 1461f03511
2 changed files with 11 additions and 6 deletions

View file

@ -10,6 +10,7 @@ from keyring import backend
from keyring import errors
from pytest import fixture
from unittest.mock import patch
from unittest.mock import Mock
from .helpers import get_fixture
import toml
@ -183,6 +184,8 @@ def toml_version(working_dir):
@fixture
def mock_password(request):
def _mock_password():
from rich.console import Console
password = get_fixture(request, "password")
user_input = get_fixture(request, "user_input")
@ -195,11 +198,13 @@ def mock_password(request):
if not password:
password = Exception("Unexpected call for password")
# @todo replace with with rich.console.Console().input(password=True)
# since getpass is no longer used
return patch("getpass.getpass", side_effect=password)
mock_console = Mock(wraps=Console(stderr=True))
mock_console.input = Mock()
mock_console.input.side_effect = password
return {"getpass": _mock_password}
return patch("jrnl.output._get_console", return_value=mock_console)
return {"rich_console_input": _mock_password}
@fixture

View file

@ -164,12 +164,12 @@ def config_var_in_memory(
@then("we should be prompted for a password")
def password_was_called(cli_run):
assert cli_run["mocks"]["getpass"].called
assert cli_run["mocks"]["rich_console_input"].called
@then("we should not be prompted for a password")
def password_was_not_called(cli_run):
assert not cli_run["mocks"]["getpass"].called
assert not cli_run["mocks"]["rich_console_input"].called
@then(parse("the cache directory should contain the files\n{file_list}"))