mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 19:48:31 +02:00
update password mock to use rich console instead of getpass
This commit is contained in:
parent
4636f1a3ef
commit
1461f03511
2 changed files with 11 additions and 6 deletions
|
@ -10,6 +10,7 @@ from keyring import backend
|
||||||
from keyring import errors
|
from keyring import errors
|
||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
from unittest.mock import Mock
|
||||||
from .helpers import get_fixture
|
from .helpers import get_fixture
|
||||||
import toml
|
import toml
|
||||||
|
|
||||||
|
@ -183,6 +184,8 @@ def toml_version(working_dir):
|
||||||
@fixture
|
@fixture
|
||||||
def mock_password(request):
|
def mock_password(request):
|
||||||
def _mock_password():
|
def _mock_password():
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
password = get_fixture(request, "password")
|
password = get_fixture(request, "password")
|
||||||
user_input = get_fixture(request, "user_input")
|
user_input = get_fixture(request, "user_input")
|
||||||
|
|
||||||
|
@ -195,11 +198,13 @@ def mock_password(request):
|
||||||
if not password:
|
if not password:
|
||||||
password = Exception("Unexpected call for password")
|
password = Exception("Unexpected call for password")
|
||||||
|
|
||||||
# @todo replace with with rich.console.Console().input(password=True)
|
mock_console = Mock(wraps=Console(stderr=True))
|
||||||
# since getpass is no longer used
|
mock_console.input = Mock()
|
||||||
return patch("getpass.getpass", side_effect=password)
|
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
|
@fixture
|
||||||
|
|
|
@ -164,12 +164,12 @@ def config_var_in_memory(
|
||||||
|
|
||||||
@then("we should be prompted for a password")
|
@then("we should be prompted for a password")
|
||||||
def password_was_called(cli_run):
|
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")
|
@then("we should not be prompted for a password")
|
||||||
def password_was_not_called(cli_run):
|
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}"))
|
@then(parse("the cache directory should contain the files\n{file_list}"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue