return tuple when interactive=False

pull/2828/head
Alex Tokar 2021-11-29 14:03:30 -08:00
parent 55d009b667
commit 2d1b37f9aa
2 changed files with 5 additions and 15 deletions

View File

@ -346,12 +346,8 @@ class Keystore:
cls, password: str,
keystore_dir: Optional[Path] = None,
interactive: bool = True,
return_mnemonic: bool = False
) -> Union['Keystore', Tuple['Keystore', str]]:
"""Generate a new nucypher keystore for use with characters"""
if return_mnemonic and interactive:
raise ValueError("The two values: report_mnemonic and interactive, may not both be `True`")
mnemonic = Mnemonic(_MNEMONIC_LANGUAGE)
__words = mnemonic.generate(strength=_ENTROPY_BITS)
if interactive:
@ -360,10 +356,10 @@ class Keystore:
path = Keystore.__save(secret=__secret, password=password, keystore_dir=keystore_dir)
keystore = cls(keystore_path=path)
if return_mnemonic:
return keystore, __words
if interactive:
return keystore
return keystore
return keystore, __words
@staticmethod
def _confirm_generate(__words: str) -> None:

View File

@ -116,20 +116,14 @@ def test_keystore_invalid_password(tmpdir):
_keystore = Keystore.generate('short', keystore_dir=tmpdir)
def test_keystore_generate_report_mnemonic_true(tmpdir):
def test_keystore_generate_report_interactive_false(tmpdir):
_keystore, words = Keystore.generate(
INSECURE_DEVELOPMENT_PASSWORD,
keystore_dir=tmpdir,
interactive=False,
return_mnemonic=True)
interactive=False)
assert len(words.split(" ")) == 24
def test_keystore_generate_report_mnemonic_blocked_by_interactive(tmpdir):
with pytest.raises(ValueError, match="The two values: report_mnemonic and interactive, may not both be `True`"):
_keystore = Keystore.generate(INSECURE_DEVELOPMENT_PASSWORD, keystore_dir=tmpdir, return_mnemonic=True)
def test_keystore_derive_crypto_power_without_unlock(tmpdir):
keystore = Keystore.generate(INSECURE_DEVELOPMENT_PASSWORD, keystore_dir=tmpdir)
with pytest.raises(Keystore.Locked):