Skip to content

Commit

Permalink
Replace askyesno() with click.confirm()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Dec 2, 2020
1 parent c7aac72 commit 07d8885
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 102 deletions.
6 changes: 4 additions & 2 deletions dandi/girder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from functools import lru_cache
from pathlib import Path

import click
from keyring.core import get_keyring, load_config, load_env
from keyring.backend import get_all_keyring
from keyring.errors import KeyringError
Expand All @@ -19,7 +20,6 @@

from . import get_logger
from .exceptions import LockingError
from .support.ui import askyesno
from .utils import ensure_datetime, flattened, flatten, remap_dict
from .consts import known_instances_rev, MAX_CHUNK_SIZE

Expand Down Expand Up @@ -912,7 +912,9 @@ def keyring_lookup(service_name, username):
lgr.info("EncryptedKeyring file exists; using as keyring backend")
return (kb, kb.get_password(service_name, username))
lgr.info("EncryptedKeyring file does not exist")
if askyesno("Would you like to establish an encrypted keyring?", default=True):
if click.confirm(
"Would you like to establish an encrypted keyring?", default=True
):
keyring_cfg = Path(keyringrc_file())
if keyring_cfg.exists():
lgr.info("%s exists; refusing to overwrite", keyring_cfg)
Expand Down
77 changes: 0 additions & 77 deletions dandi/support/tests/test_ui.py

This file was deleted.

17 changes: 0 additions & 17 deletions dandi/support/ui.py

This file was deleted.

12 changes: 6 additions & 6 deletions dandi/tests/test_girder.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ def test_keyring_lookup_encrypted_fallback_not_exists_no_create(
# guarantee that an encrypted keyring on the real filesystem isn't found.
monkeypatch.delenv("PYTHON_KEYRING_BACKEND", raising=False)
get_keyring = mocker.patch("dandi.girder.get_keyring", return_value=fail.Keyring())
askyesno = mocker.patch("dandi.girder.askyesno", return_value=False)
confirm = mocker.patch("click.confirm", return_value=False)
with pytest.raises(KeyringError):
girder.keyring_lookup("testservice", "testusername")
get_keyring.assert_called_once_with()
askyesno.assert_called_once_with(
confirm.assert_called_once_with(
"Would you like to establish an encrypted keyring?", default=True
)

Expand All @@ -255,12 +255,12 @@ def test_keyring_lookup_encrypted_fallback_not_exists_create_rcconf(
# guarantee that a fake filesystem is used.
monkeypatch.delenv("PYTHON_KEYRING_BACKEND", raising=False)
get_keyring = mocker.patch("dandi.girder.get_keyring", return_value=fail.Keyring())
askyesno = mocker.patch("dandi.girder.askyesno", return_value=True)
confirm = mocker.patch("click.confirm", return_value=True)
kb, password = girder.keyring_lookup("testservice", "testusername")
assert isinstance(kb, keyfile.EncryptedKeyring)
assert password is None
get_keyring.assert_called_once_with()
askyesno.assert_called_once_with(
confirm.assert_called_once_with(
"Would you like to establish an encrypted keyring?", default=True
)
assert os.path.exists(girder.keyringrc_file())
Expand All @@ -275,13 +275,13 @@ def test_keyring_lookup_encrypted_fallback_not_exists_create_rcconf_exists(
):
monkeypatch.delenv("PYTHON_KEYRING_BACKEND", raising=False)
get_keyring = mocker.patch("dandi.girder.get_keyring", return_value=fail.Keyring())
askyesno = mocker.patch("dandi.girder.askyesno", return_value=True)
confirm = mocker.patch("click.confirm", return_value=True)
fs.create_file(girder.keyringrc_file(), contents="# placeholder\n")
kb, password = girder.keyring_lookup("testservice", "testusername")
assert isinstance(kb, keyfile.EncryptedKeyring)
assert password is None
get_keyring.assert_called_once_with()
askyesno.assert_called_once_with(
confirm.assert_called_once_with(
"Would you like to establish an encrypted keyring?", default=True
)
with open(girder.keyringrc_file()) as fp:
Expand Down

0 comments on commit 07d8885

Please sign in to comment.