Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Fail early in verdi presto when profile name already exists #6488

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/aiida/cmdline/commands/cmd_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def verdi_presto(
from aiida.manage.configuration import create_profile, load_profile
from aiida.orm import Computer

if profile_name in ctx.obj.config.profile_names:
raise click.BadParameter(f'The profile `{profile_name}` already exists.', param_hint='--profile-name')

postgres_config_kwargs = {
'profile_name': profile_name,
'postgres_hostname': postgres_hostname,
Expand Down
22 changes: 21 additions & 1 deletion tests/cmdline/commands/test_presto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for ``verdi presto``."""

import textwrap

import pytest
from aiida.cmdline.commands.cmd_presto import get_default_presto_profile_name, verdi_presto
from aiida.manage.configuration import profile_context
Expand Down Expand Up @@ -50,7 +52,7 @@ def detect_rabbitmq_config(**kwargs):

@pytest.mark.requires_rmq
@pytest.mark.usefixtures('empty_config')
def test_presto_with_rmq(pytestconfig, run_cli_command, monkeypatch):
def test_presto_with_rmq(pytestconfig, run_cli_command):
"""Test the ``verdi presto``."""
result = run_cli_command(verdi_presto, ['--non-interactive'])
assert 'Created new profile `presto`.' in result.output
Expand Down Expand Up @@ -91,3 +93,21 @@ def test_presto_overdose(run_cli_command, config_with_profile_factory):
config_with_profile_factory(name='presto-10')
result = run_cli_command(verdi_presto)
assert 'Created new profile `presto-11`.' in result.output


@pytest.mark.requires_psql
@pytest.mark.usefixtures('empty_config')
def test_presto_profile_name_exists(run_cli_command, config_with_profile_factory):
"""Test ``verdi presto`` fails early if the specified profile name already exists."""
profile_name = 'custom-presto'
config_with_profile_factory(name=profile_name)
options = ['--non-interactive', '--use-postgres', '--profile-name', profile_name]
result = run_cli_command(verdi_presto, options, raises=True)
# Matching for the complete literal output as a way to test that nothing else of the command was run, such as
# configuring the broker or creating a database for PostgreSQL
assert result.output == textwrap.dedent("""\
Usage: presto [OPTIONS]
Try 'presto --help' for help.

Error: Invalid value for --profile-name: The profile `custom-presto` already exists.
""")