From 6084c8725cf54487ff490e8fbcadf674c1726704 Mon Sep 17 00:00:00 2001 From: Mohammad Alisafaee <50210674+mohammad-sdsc@users.noreply.github.com> Date: Wed, 6 Nov 2019 16:25:06 +0100 Subject: [PATCH] feat: avoid creation of nested datasets (#796) * feat: avoid creation of nested datasets --- renku/core/management/datasets.py | 6 ++++++ tests/cli/test_datasets.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/renku/core/management/datasets.py b/renku/core/management/datasets.py index 42cd44ae6a..f011e235d0 100644 --- a/renku/core/management/datasets.py +++ b/renku/core/management/datasets.py @@ -115,6 +115,12 @@ def with_dataset(self, name=None, identifier=None): clean_up_required = False if dataset is None: + # Avoid nested datasets: name mustn't have '/' in it + if len(Path(name).parts) > 1: + raise errors.ParameterError( + 'Dataset name {} is not valid.'.format(name) + ) + clean_up_required = True dataset_ref = None identifier = str(uuid.uuid4()) diff --git a/tests/cli/test_datasets.py b/tests/cli/test_datasets.py index 57354ec0ab..f10cd8c0a3 100644 --- a/tests/cli/test_datasets.py +++ b/tests/cli/test_datasets.py @@ -182,6 +182,14 @@ def test_dataset_create_exception_refs(runner, project, client): assert 'a' in result.output +@pytest.mark.parametrize('name', ['dataset/new', '/dataset', 'dataset/']) +def test_dataset_name_is_valid(client, runner, project, name): + """Test dataset name has no '/' character to avoid nested datasets.""" + result = runner.invoke(cli, ['dataset', 'create', name]) + assert 2 == result.exit_code + assert 'is not valid' in result.output + + @pytest.mark.parametrize('output_format', DATASETS_FORMATS.keys()) def test_datasets_list_empty(output_format, runner, project): """Test listing without datasets."""