Skip to content

Commit b9b2775

Browse files
committed
test: update tests for the PublishActivity metadata changes
1 parent 9ecdbb4 commit b9b2775

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

dandiapi/api/tests/test_asset.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import json
44
from uuid import uuid4
55

6+
from dandischema.conf import get_instance_config
67
from dandischema.models import AccessType
78
from django.conf import settings
89
from django.db.utils import IntegrityError
910
from django.urls import reverse
1011
import pytest
1112
import requests
1213

14+
from dandiapi import __version__
1315
from dandiapi.api.asset_paths import add_asset_paths, extract_paths
1416
from dandiapi.api.models import Asset, Version
1517
from dandiapi.api.models.asset_paths import AssetPath
@@ -24,6 +26,8 @@
2426

2527
from .fuzzy import HTTP_URL_RE, TIMESTAMP_RE, URN_RE, UTC_ISO_TIMESTAMP_RE, UUID_RE
2628

29+
_SCHEMA_INSTANCE_CONFIG = get_instance_config()
30+
2731
# Model tests
2832

2933

@@ -111,6 +115,9 @@ def test_publish_asset(draft_asset: Asset):
111115
published_asset = draft_asset
112116
published_asset.refresh_from_db()
113117

118+
instance_name = _SCHEMA_INSTANCE_CONFIG.instance_name
119+
instance_identifier = _SCHEMA_INSTANCE_CONFIG.instance_identifier
120+
114121
assert published_asset.blob == draft_blob
115122
assert published_asset.full_metadata == {
116123
**draft_metadata,
@@ -123,10 +130,10 @@ def test_publish_asset(draft_asset: Asset):
123130
'wasAssociatedWith': [
124131
{
125132
'id': URN_RE,
126-
'identifier': 'RRID:SCR_017571',
127-
'name': 'DANDI API',
133+
**({'identifier': instance_identifier} if instance_identifier else {}),
134+
'name': f'{instance_name} API Server',
128135
# TODO: version the API
129-
'version': '0.1.0',
136+
'version': __version__,
130137
'schemaKey': 'Software',
131138
}
132139
],

dandiapi/api/tests/test_tasks.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
from typing import TYPE_CHECKING
77

8+
from dandischema.conf import get_instance_config
89
from django.conf import settings
910
from django.core.files.storage import default_storage
1011
from django.forms.models import model_to_dict
@@ -15,6 +16,7 @@
1516
from zarr_checksum.checksum import EMPTY_CHECKSUM
1617
from zarr_checksum.generators import ZarrArchiveFile
1718

19+
from dandiapi import __version__
1820
from dandiapi.api import tasks
1921
from dandiapi.api.models import Asset, Version
2022
from dandiapi.api.services.permissions.dandiset import add_dandiset_owner
@@ -27,6 +29,9 @@
2729
from rest_framework.test import APIClient
2830

2931

32+
_SCHEMA_INSTANCE_CONFIG = get_instance_config()
33+
34+
3035
@pytest.mark.django_db
3136
def test_calculate_checksum_task(asset_blob_factory):
3237
asset_blob = asset_blob_factory(blob__data=b'known-content', size=13, sha256=None)
@@ -382,6 +387,9 @@ def test_publish_task(
382387

383388
published_version = draft_version.dandiset.versions.latest('created')
384389

390+
instance_name = _SCHEMA_INSTANCE_CONFIG.instance_name
391+
instance_identifier = _SCHEMA_INSTANCE_CONFIG.instance_identifier
392+
385393
assert published_version.metadata == {
386394
**draft_version.metadata,
387395
'publishedBy': {
@@ -392,10 +400,10 @@ def test_publish_task(
392400
'wasAssociatedWith': [
393401
{
394402
'id': URN_RE,
395-
'identifier': 'RRID:SCR_017571',
396-
'name': 'DANDI API',
403+
**({'identifier': instance_identifier} if instance_identifier else {}),
404+
'name': f'{instance_name} API Server',
397405
# TODO: version the API
398-
'version': '0.1.0',
406+
'version': __version__,
399407
'schemaKey': 'Software',
400408
}
401409
],
@@ -452,9 +460,9 @@ def test_publish_task(
452460
'wasAssociatedWith': [
453461
{
454462
'id': URN_RE,
455-
'identifier': 'RRID:SCR_017571',
456-
'name': 'DANDI API',
457-
'version': '0.1.0',
463+
**({'identifier': instance_identifier} if instance_identifier else {}),
464+
'name': f'{instance_name} API Server',
465+
'version': __version__,
458466
'schemaKey': 'Software',
459467
}
460468
],

dandiapi/api/tests/test_version.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
from time import sleep
55
from typing import TYPE_CHECKING
66

7+
from dandischema.conf import get_instance_config
78
from dandischema.models import AccessType
89
from django.conf import settings
910
from freezegun import freeze_time
1011
import pytest
1112

13+
from dandiapi import __version__
1214
from dandiapi.api.models.dandiset import Dandiset
1315
from dandiapi.api.services.metadata import version_aggregate_assets_summary
1416
from dandiapi.api.services.metadata.exceptions import VersionMetadataConcurrentlyModifiedError
@@ -26,6 +28,8 @@
2628

2729
from .fuzzy import HTTP_URL_RE, TIMESTAMP_RE, URN_RE, UTC_ISO_TIMESTAMP_RE, VERSION_ID_RE
2830

31+
_SCHEMA_INSTANCE_CONFIG = get_instance_config()
32+
2933

3034
@pytest.mark.django_db
3135
def test_version_next_published_version_nosave(dandiset):
@@ -302,6 +306,9 @@ def test_version_publish_version(draft_version, asset):
302306
publish_version.doi = fake_doi
303307
publish_version.save()
304308

309+
instance_name = _SCHEMA_INSTANCE_CONFIG.instance_name
310+
instance_identifier = _SCHEMA_INSTANCE_CONFIG.instance_identifier
311+
305312
assert publish_version.dandiset == draft_version.dandiset
306313
assert publish_version.metadata == {
307314
**draft_version.metadata,
@@ -313,10 +320,10 @@ def test_version_publish_version(draft_version, asset):
313320
'wasAssociatedWith': [
314321
{
315322
'id': URN_RE,
316-
'identifier': 'RRID:SCR_017571',
317-
'name': 'DANDI API',
323+
**({'identifier': instance_identifier} if instance_identifier else {}),
324+
'name': f'{instance_name} API Server',
318325
# TODO: version the API
319-
'version': '0.1.0',
326+
'version': __version__,
320327
'schemaKey': 'Software',
321328
}
322329
],

0 commit comments

Comments
 (0)