Skip to content

Commit

Permalink
Merge pull request #1540 from kabilar/embargoed-zarr
Browse files Browse the repository at this point in the history
Remove `NotImplementedError` to allow for uploading Zarr assets to embargoed Dandisets
  • Loading branch information
yarikoptic authored Nov 27, 2024
2 parents c77910f + 2a1c5ed commit 2210320
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
7 changes: 0 additions & 7 deletions dandi/files/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
ZARR_DELETE_BATCH_SIZE,
ZARR_MIME_TYPE,
ZARR_UPLOAD_BATCH_SIZE,
EmbargoStatus,
)
from dandi.dandiapi import (
RemoteAsset,
Expand Down Expand Up @@ -297,12 +296,6 @@ def iter_upload(
``"done"`` and an ``"asset"`` key containing the resulting
`RemoteAsset`.
"""
# So that older clients don't get away with doing the wrong thing once
# Zarr upload to embargoed Dandisets is implemented in the API:
if dandiset.embargo_status is EmbargoStatus.EMBARGOED:
raise NotImplementedError(
"Uploading Zarr assets to embargoed Dandisets is currently not implemented"
)
asset_path = metadata.setdefault("path", self.path)
client = dandiset.client
lgr.debug("%s: Producing asset", asset_path)
Expand Down
13 changes: 12 additions & 1 deletion dandi/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,23 @@ def sample_dandiset_factory(
return SampleDandisetFactory(local_dandi_api, tmp_path_factory)


# @sweep_embargo can be used along with `new_dandiset` fixture to
# run the test against both embargoed and non-embargoed Dandisets.
# "embargo: bool" argument should be added to the test function.
sweep_embargo = pytest.mark.parametrize("embargo", [True, False])


@pytest.fixture()
def new_dandiset(
request: pytest.FixtureRequest, sample_dandiset_factory: SampleDandisetFactory
) -> SampleDandiset:
kws = {}
if "embargo" in request.node.fixturenames:
kws["embargo"] = request.node.callspec.params["embargo"]
return sample_dandiset_factory.mkdandiset(
f"Sample Dandiset for {request.node.name}"
f"Sample {'Embargoed' if kws.get('embargo') else 'Public'} "
f"Dandiset for {request.node.name}",
**kws,
)


Expand Down
15 changes: 11 additions & 4 deletions dandi/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from pytest_mock import MockerFixture
import zarr

from .fixtures import SampleDandiset
from .fixtures import SampleDandiset, sweep_embargo
from .test_helpers import assert_dirtrees_eq
from ..consts import ZARR_MIME_TYPE, dandiset_metadata_file
from ..consts import ZARR_MIME_TYPE, EmbargoStatus, dandiset_metadata_file
from ..dandiapi import AssetType, RemoteBlobAsset, RemoteZarrAsset
from ..dandiset import Dandiset
from ..download import download
Expand Down Expand Up @@ -151,9 +151,10 @@ def test_upload_download_small_file(
assert (tmp_path / dandiset_id / "file.txt").read_bytes() == contents


@sweep_embargo
@pytest.mark.parametrize("confirm", [True, False])
def test_upload_sync(
confirm: bool, mocker: MockerFixture, text_dandiset: SampleDandiset
confirm: bool, mocker: MockerFixture, text_dandiset: SampleDandiset, embargo: bool
) -> None:
(text_dandiset.dspath / "file.txt").unlink()
confirm_mock = mocker.patch("click.confirm", return_value=confirm)
Expand Down Expand Up @@ -250,7 +251,13 @@ def test_upload_bids_non_nwb_file(bids_dandiset: SampleDandiset) -> None:
assert [asset.path for asset in bids_dandiset.dandiset.get_assets()] == ["README"]


def test_upload_sync_zarr(mocker, zarr_dandiset):
@sweep_embargo
def test_upload_sync_zarr(
mocker: MockerFixture, zarr_dandiset: SampleDandiset, embargo: bool
) -> None:
assert zarr_dandiset.dandiset.embargo_status == (
EmbargoStatus.EMBARGOED if embargo else EmbargoStatus.OPEN
)
rmtree(zarr_dandiset.dspath / "sample.zarr")
zarr.save(zarr_dandiset.dspath / "identity.zarr", np.eye(5))
confirm_mock = mocker.patch("click.confirm", return_value=True)
Expand Down

0 comments on commit 2210320

Please sign in to comment.