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

Fix & test for downloading by asset ID URL #561

Merged
merged 1 commit into from
Apr 13, 2021
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
25 changes: 19 additions & 6 deletions dandi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,25 @@ def download_generator(
elif isinstance(client, DandiAPIClient):
# At least according to our 0.1.0 state of v1
# https://github.com/dandi/dandi-publish/issues/79
down_args = (
dandiset["dandiset"]["identifier"],
dandiset["version"],
asset["asset_id"],
)
metadata = client.get_asset(*down_args)
if "asset_id" in asset_id:
down_args = (
dandiset["dandiset"]["identifier"],
dandiset["version"],
asset_id["asset_id"],
)
metadata = asset
asset = {
"path": metadata["path"],
"size": metadata["contentSize"],
"metadata": metadata,
}
else:
down_args = (
dandiset["dandiset"]["identifier"],
dandiset["version"],
asset["asset_id"],
)
metadata = client.get_asset(*down_args)
d = metadata.get("digest", {})
if "dandi:dandi-etag" in d:
digests = {"dandi-etag": d["dandi:dandi-etag"]}
Expand Down
17 changes: 17 additions & 0 deletions dandi/tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,20 @@ def test_download_item(local_dandi_api, text_dandiset, tmp_path):
tmp_path / "coconut.txt"
]
assert (tmp_path / "coconut.txt").read_text() == "Coconut\n"


def test_download_asset_id(local_dandi_api, text_dandiset, tmp_path):
dandiset_id = text_dandiset["dandiset_id"]
asset = local_dandi_api["client"].get_asset_bypath(
dandiset_id, "draft", "subdir2/coconut.txt"
)
assert asset is not None
download(
f"{local_dandi_api['instance'].api}/dandisets/{dandiset_id}/versions"
f"/draft/assets/{asset['asset_id']}/download/",
tmp_path,
)
assert list(map(Path, find_files(r".*", paths=[tmp_path], dirs=True))) == [
tmp_path / "coconut.txt"
]
assert (tmp_path / "coconut.txt").read_text() == "Coconut\n"