Skip to content

Commit

Permalink
cli: adds workflow name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rokas Maciulaitis committed Feb 5, 2020
1 parent 9335c2a commit d361f38
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
19 changes: 19 additions & 0 deletions reana_client/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ def format_session_uri(reana_server_url, path, access_token):
path=path, access_token=access_token)


def validate_workflow_name(ctx, _, workflow_name):
"""Validate workflow name."""
not_allowed_characters = ['.']
if workflow_name:
for item in not_allowed_characters:
if item in workflow_name:
click.echo(
click.style(
'Workflow name {} contains illegal '
'character "{}""'.format(
workflow_name,
item
),
fg='red'),
err=True)
sys.exit(1)
return workflow_name


class NotRequiredIf(click.Option):
"""Allow only one of two arguments to be missing."""

Expand Down
3 changes: 2 additions & 1 deletion reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from reana_client.cli.utils import (add_access_token_options,
add_workflow_option, check_connection,
filter_data, format_session_uri,
parse_parameters)
parse_parameters, validate_workflow_name)
from reana_client.config import (ERROR_MESSAGES, TIMECHECK,
reana_yaml_default_file_path)
from reana_client.utils import (get_workflow_name_and_run_number,
Expand Down Expand Up @@ -203,6 +203,7 @@ def workflow_workflows(ctx, sessions, _filter, output_format, access_token,
'-n', '--name',
'-w', '--workflow',
default='',
callback=validate_workflow_name,
help='Optional name of the workflow. [default is "workflow"]')
@click.option(
'--skip-validation',
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,20 @@ def test_workflow_create_successful(create_yaml_workflow_schema):
assert response["workflow_name"] in result.output


def test_workflow_create_not_valid_name(create_yaml_workflow_schema):
"""Test workflow create when creation is successfull."""
env = {'REANA_SERVER_URL': 'localhost'}
illegal_workflow_name = 'workflow.name'
runner = CliRunner(env=env)
result = runner.invoke(cli, ['create', '-n', illegal_workflow_name])
message = 'Workflow name {} contains illegal character "{}"'.format(
illegal_workflow_name,
'.'
)
assert message in result.output
assert result.exit_code == 1


def test_create_workflow_from_json(create_yaml_workflow_schema):
"""Test create workflow from json specification."""
status_code = 201
Expand Down

0 comments on commit d361f38

Please sign in to comment.