From 8b8887e559e02eadac832a89f7012872040e1cbc Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Fri, 10 Nov 2023 02:27:52 +0100 Subject: [PATCH] CLI: Set defaults for user details in profile setup 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. --- aiida/cmdline/params/options/commands/setup.py | 6 +++--- tests/cmdline/commands/test_setup.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/aiida/cmdline/params/options/commands/setup.py b/aiida/cmdline/params/options/commands/setup.py index 88d7216072..1c66b27793 100644 --- a/aiida/cmdline/params/options/commands/setup.py +++ b/aiida/cmdline/params/options/commands/setup.py @@ -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 ) diff --git a/tests/cmdline/commands/test_setup.py b/tests/cmdline/commands/test_setup.py index 4818a220ca..fc4fb9a637 100644 --- a/tests/cmdline/commands/test_setup.py +++ b/tests/cmdline/commands/test_setup.py @@ -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: