Skip to content

Commit

Permalink
Revise tests and code for removal of embargoed blob
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Kanzer authored and Aaron Kanzer committed Oct 30, 2024
1 parent ed0bf6b commit 25b4929
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
4 changes: 1 addition & 3 deletions dandiapi/api/services/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ def _build_validatable_version_metadata(version: Version) -> dict:
metadata_for_validation['assetsSummary'] = {
'schemaKey': 'AssetsSummary',
'numberOfBytes': 1
if version.assets.filter(
Q(blob__size__gt=0) | Q(zarr__size__gt=0) | Q(embargoed_blob__size__gt=0)
).exists()
if version.assets.filter(Q(blob__size__gt=0) | Q(zarr__size__gt=0)).exists()
else 0,
'numberOfFiles': 1 if version.assets.exists() else 0,
}
Expand Down
29 changes: 10 additions & 19 deletions dandiapi/api/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,48 +359,39 @@ def test_version_publish_version(draft_version, asset):

@pytest.mark.parametrize(
'asset_type',
["blob", "embargoed_blob", "zarr"],
['blob', 'zarr'],
)
@pytest.mark.django_db()
@pytest.mark.django_db
def test_version_aggregate_assets_summary(
draft_version_factory,
draft_asset_factory,
embargoed_asset_blob_factory,
zarr_archive_factory,
asset_type
draft_version_factory, draft_asset_factory, zarr_archive_factory, asset_type
):
version = draft_version_factory(status=Version.Status.VALID)

if asset_type is 'blob':
if asset_type == 'blob':
asset = draft_asset_factory(status=Asset.Status.VALID)

elif asset_type is 'embargoed_blob':
asset = embargoed_asset_blob_factory(dandiset=version.dandiset)

elif asset_type is 'zarr':
elif asset_type == 'zarr':
zarr: ZarrArchive = zarr_archive_factory(status=ZarrArchiveStatus.UPLOADED)
asset = draft_asset_factory(blob=None, embargoed_blob=None, zarr=zarr)
asset = draft_asset_factory(blob=None, zarr=zarr)

version.assets.add(asset)

version_aggregate_assets_summary(version)
version.refresh_from_db()

assert 1 == version.assets.count()
assert version.assets.count() == 1
asset = version.assets.first()

if asset_type is 'blob':
if asset_type == 'blob':
assert version.metadata['assetsSummary']['numberOfBytes'] == asset.blob.size

elif asset_type is 'embargoed_blob':
assert version.metadata['assetsSummary']['numberOfBytes'] == asset.embargoed_blob.blob.size

elif asset_type is 'zarr':
elif asset_type == 'zarr':
assert version.metadata['assetsSummary']['numberOfBytes'] == asset.size

assert version.metadata['assetsSummary']['numberOfFiles'] == 1
assert version.metadata['assetsSummary']['schemaKey'] == 'AssetsSummary'


@pytest.mark.django_db
def test_version_aggregate_assets_summary_metadata_modified(
draft_version_factory, draft_asset_factory
Expand Down

0 comments on commit 25b4929

Please sign in to comment.