Skip to content

Commit

Permalink
CLI: Set defaults for user details in profile setup
Browse files Browse the repository at this point in the history
The user options `--first-name`, `--last-name` and `--institution` in
the `verdi quicksetup/setup` commands were recently made required but
did not provide a default. This would make creating profiles
significantly more complex than always needed. For simple test and demo
profiles the user might not necessarily care about these user details.

Here we add defaults for these options. Even for production profiles
this is a sensible approach since these details can always be freely
updated later on with `verdi user configure`. This is also the reason
that the `--email` does not provide a default because that can not be
changed later on.
  • Loading branch information
sphuber committed Nov 12, 2023
1 parent 1c0b702 commit 8b8887e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aiida/cmdline/params/options/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,21 @@ def get_quicksetup_password(ctx, param, value): # pylint: disable=unused-argume

SETUP_USER_FIRST_NAME = options.USER_FIRST_NAME.clone(
prompt='First name',
default=functools.partial(get_config_option, 'autofill.user.first_name'),
default=lambda: get_config_option('autofill.user.first_name') or 'John',
required=True,
cls=options.interactive.InteractiveOption
)

SETUP_USER_LAST_NAME = options.USER_LAST_NAME.clone(
prompt='Last name',
default=functools.partial(get_config_option, 'autofill.user.last_name'),
default=lambda: get_config_option('autofill.user.last_name') or 'Doe',
required=True,
cls=options.interactive.InteractiveOption
)

SETUP_USER_INSTITUTION = options.USER_INSTITUTION.clone(
prompt='Institution',
default=functools.partial(get_config_option, 'autofill.user.institution'),
default=lambda: get_config_option('autofill.user.institution') or 'Unknown',
required=True,
cls=options.interactive.InteractiveOption
)
Expand Down
16 changes: 16 additions & 0 deletions tests/cmdline/commands/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ def test_quicksetup(self, tmp_path):
backend = profile.storage_cls(profile)
assert backend.get_global_variable('repository|uuid') == backend.get_repository().uuid

def test_quicksetup_default_user(self, tmp_path):
"""Test `verdi quicksetup` and ensure that user details (apart from the email) are optional."""
profile_name = 'testing-default-user-details'
user_email = 'some@email.com'

options = [
'--non-interactive', '--profile', profile_name, '--email', user_email, '--db-port',
self.pg_test.dsn['port'], '--db-backend', self.storage_backend_name, '--repository',
str(tmp_path)
]

self.cli_runner(cmd_setup.quicksetup, options, use_subprocess=False)

config = configuration.get_config()
assert profile_name in config.profile_names

def test_quicksetup_from_config_file(self, tmp_path):
"""Test `verdi quicksetup` from configuration file."""
with tempfile.NamedTemporaryFile('w') as handle:
Expand Down

0 comments on commit 8b8887e

Please sign in to comment.