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

Make existing="refresh" a synonym for "overwrite" for new upload #390

Merged
merged 2 commits into from
Feb 16, 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
15 changes: 8 additions & 7 deletions dandi/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,21 @@ def test_new_upload_extant_skip(mocker, text_dandiset):
iter_upload_spy.assert_not_called()


def test_new_upload_extant_eq_overwrite(mocker, text_dandiset):
@pytest.mark.parametrize("existing", ["overwrite", "refresh"])
def test_new_upload_extant_eq_overwrite(existing, mocker, text_dandiset):
iter_upload_spy = mocker.spy(DandiAPIClient, "iter_upload")
text_dandiset["reupload"](existing="overwrite")
text_dandiset["reupload"](existing=existing)
iter_upload_spy.assert_not_called()


@pytest.mark.parametrize("existing", ["overwrite", "refresh"])
def test_new_upload_extant_neq_overwrite(
local_dandi_api, mocker, text_dandiset, tmp_path
existing, local_dandi_api, mocker, text_dandiset, tmp_path
):
dandiset_id = text_dandiset["dandiset_id"]
(text_dandiset["dspath"] / "file.txt").write_text("This is different text.\n")
iter_upload_spy = mocker.spy(DandiAPIClient, "iter_upload")
text_dandiset["reupload"](existing="overwrite")
text_dandiset["reupload"](existing=existing)
iter_upload_spy.assert_called()
download(
f"{local_dandi_api['instance'].api}/dandisets/{dandiset_id}/versions/draft",
Expand All @@ -330,10 +332,9 @@ def test_new_upload_extant_neq_overwrite(
).read_text() == "This is different text.\n"


@pytest.mark.parametrize("existing", ["refresh", "force"])
def test_new_upload_extant_reupload(existing, mocker, text_dandiset):
def test_new_upload_extant_force(mocker, text_dandiset):
iter_upload_spy = mocker.spy(DandiAPIClient, "iter_upload")
text_dandiset["reupload"](existing=existing)
text_dandiset["reupload"](existing="force")
iter_upload_spy.assert_called()


Expand Down
6 changes: 2 additions & 4 deletions dandi/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,10 @@ def process_path(path, relpath):
yield skip_file("file exists")
return
# Logic below only for overwrite and reupload
if existing == "overwrite":
if existing == "overwrite" or existing == "refresh":
if extant["sha256"] == sha256_digest:
yield skip_file("file exists")
return
elif existing == "refresh":
pass
elif existing == "force":
pass
else:
Expand Down Expand Up @@ -807,7 +805,7 @@ def process_path(path, relpath):
# Upload file
#
if extant is not None:
lgr.info("Replacing asset %s", extant["uuid"])
lgr.debug("Replacing asset %s", extant["uuid"])
client.delete_asset(ds_identifier, "draft", extant["uuid"])
yield {"status": "uploading"}
for r in client.iter_upload(ds_identifier, "draft", metadata, str(path)):
Expand Down