Skip to content

Commit 450898b

Browse files
Andreas Bleulerrokroskar
authored andcommitted
fix(datasets): strip query string from data filenames
When adding data to a dataset from a URL which includes a query string, this query string used to be present in the filenaeme. This is now fixed.
1 parent ae2b000 commit 450898b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ def request_callback(request):
156156
'https://example.com/file',
157157
callback=request_callback
158158
)
159+
rsps.add_callback(
160+
responses.GET,
161+
'http://example.com/file.ext?foo=bar',
162+
callback=request_callback
163+
)
159164
yield rsps
160165

161166

renku/api/datasets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ def _add_from_url(self, dataset, path, url, link=False, **kwargs):
189189
# Respect the directory struture inside the source path.
190190
relative_to = kwargs.pop('relative_to', None)
191191
if relative_to:
192-
dst_path = Path(url).resolve().absolute().relative_to(
192+
dst_path = Path(u.path).resolve().absolute().relative_to(
193193
Path(relative_to).resolve().absolute()
194194
)
195195
else:
196-
dst_path = os.path.basename(url)
196+
dst_path = os.path.basename(u.path)
197197

198198
dst = path.joinpath(dst_path).absolute()
199199

tests/cli/test_datasets.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def test_datasets_import(data_file, data_repository, runner, project, client):
7575
)
7676
assert 0 == result.exit_code
7777

78+
# add data from any URL (not a git repo)
79+
result = runner.invoke(
80+
cli.cli,
81+
['dataset', 'add', 'dataset', 'http://example.com/file.ext?foo=bar'],
82+
catch_exceptions=False,
83+
)
84+
assert 0 == result.exit_code
85+
assert os.stat('data/dataset/file.ext')
86+
7887

7988
@pytest.mark.parametrize('output_format', DATASETS_FORMATS.keys())
8089
def test_datasets_list_empty(output_format, runner, project):

0 commit comments

Comments
 (0)