Skip to content

Commit 66b324f

Browse files
committed
test: provide basic Dandiset metadata through fixture
So that the metadata can be used amount different tests
1 parent d34c40c commit 66b324f

File tree

1 file changed

+60
-42
lines changed

1 file changed

+60
-42
lines changed

dandischema/tests/test_models.py

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,53 @@
4141
_INSTANCE_CONFIG = get_instance_config()
4242

4343

44+
@pytest.fixture
45+
def base_dandiset_metadata() -> Dict[str, Any]:
46+
"""
47+
Fixture providing basic Dandiset metadata for constructing a `Dandiset` instance.
48+
49+
Returns:
50+
Dict[str, Any]
51+
A dictionary containing basic Dandiset metadata without `doi`, `datePublished`,
52+
and `publishedBy`, suitable for constructing a `Dandiset` instance but not a
53+
`PublishedDandiset` instance.
54+
55+
Note:
56+
This metadata is returned by a fixture to ensure that each test receives a fresh
57+
copy of the metadata dictionary.
58+
"""
59+
60+
return {
61+
"identifier": f"{INSTANCE_NAME}:999999",
62+
"id": f"{INSTANCE_NAME}:999999/draft",
63+
"version": "1.0.0",
64+
"name": "testing dataset",
65+
"description": "testing",
66+
"contributor": [
67+
{
68+
"name": "last name, first name",
69+
"email": "someone@dandiarchive.org",
70+
"roleName": [RoleType("dcite:ContactPerson")],
71+
"schemaKey": "Person",
72+
}
73+
],
74+
"license": [LicenseType("spdx:CC-BY-4.0")],
75+
"citation": "Last, first (2021). Test citation.",
76+
"assetsSummary": {
77+
"numberOfBytes": 0,
78+
"numberOfFiles": 0,
79+
"dataStandard": [{"name": "NWB"}],
80+
"approach": [{"name": "electrophysiology"}],
81+
"measurementTechnique": [{"name": "two-photon microscopy technique"}],
82+
"species": [{"name": "Human"}],
83+
},
84+
"manifestLocation": [
85+
"https://api.dandiarchive.org/api/dandisets/999999/versions/draft/assets/"
86+
],
87+
"url": "https://dandiarchive.org/dandiset/999999/draft",
88+
}
89+
90+
4491
@pytest.mark.parametrize(
4592
("y_type", "anys_value"),
4693
[
@@ -403,46 +450,15 @@ def test_autogenerated_titles() -> None:
403450

404451

405452
@skipif_no_doi_prefix
406-
def test_dandimeta_1() -> None:
453+
def test_dandimeta_1(base_dandiset_metadata) -> None:
407454
"""checking basic metadata for publishing"""
408455

409456
assert DOI_PREFIX is not None
410457

411-
# metadata without doi, datePublished and publishedBy
412-
meta_dict: Dict[str, Any] = {
413-
"identifier": f"{INSTANCE_NAME}:999999",
414-
"id": f"{INSTANCE_NAME}:999999/draft",
415-
"version": "1.0.0",
416-
"name": "testing dataset",
417-
"description": "testing",
418-
"contributor": [
419-
{
420-
"name": "last name, first name",
421-
"email": "someone@dandiarchive.org",
422-
"roleName": [RoleType("dcite:ContactPerson")],
423-
"schemaKey": "Person",
424-
}
425-
],
426-
"license": [LicenseType("spdx:CC-BY-4.0")],
427-
"citation": "Last, first (2021). Test citation.",
428-
"assetsSummary": {
429-
"numberOfBytes": 0,
430-
"numberOfFiles": 0,
431-
"dataStandard": [{"name": "NWB"}],
432-
"approach": [{"name": "electrophysiology"}],
433-
"measurementTechnique": [{"name": "two-photon microscopy technique"}],
434-
"species": [{"name": "Human"}],
435-
},
436-
"manifestLocation": [
437-
"https://api.dandiarchive.org/api/dandisets/999999/versions/draft/assets/"
438-
],
439-
"url": "https://dandiarchive.org/dandiset/999999/draft",
440-
}
441-
442458
# should work for Dandiset but PublishedDandiset should raise an error
443-
Dandiset(**meta_dict)
459+
Dandiset(**base_dandiset_metadata)
444460
with pytest.raises(ValidationError) as exc:
445-
PublishedDandiset(**meta_dict)
461+
PublishedDandiset(**base_dandiset_metadata)
446462

447463
ErrDetail = namedtuple("ErrDetail", ["type", "msg"])
448464

@@ -490,21 +506,23 @@ def test_dandimeta_1() -> None:
490506

491507
# after adding basic meta required to publish: doi, datePublished, publishedBy, assetsSummary,
492508
# so PublishedDandiset should work
493-
meta_dict["url"] = "https://dandiarchive.org/dandiset/999999/0.0.0"
494-
meta_dict["id"] = f"{INSTANCE_NAME}:999999/0.0.0"
495-
meta_dict["version"] = "0.0.0"
496-
meta_dict.update(
509+
base_dandiset_metadata["url"] = "https://dandiarchive.org/dandiset/999999/0.0.0"
510+
base_dandiset_metadata["id"] = f"{INSTANCE_NAME}:999999/0.0.0"
511+
base_dandiset_metadata["version"] = "0.0.0"
512+
base_dandiset_metadata.update(
497513
basic_publishmeta(INSTANCE_NAME, dandi_id="999999", prefix=DOI_PREFIX)
498514
)
499-
meta_dict["assetsSummary"].update(**{"numberOfBytes": 1, "numberOfFiles": 1})
515+
base_dandiset_metadata["assetsSummary"].update(
516+
**{"numberOfBytes": 1, "numberOfFiles": 1}
517+
)
500518

501519
# Test that releaseNotes is optional (can be omitted)
502-
dandiset_without_notes = PublishedDandiset(**meta_dict)
520+
dandiset_without_notes = PublishedDandiset(**base_dandiset_metadata)
503521
assert dandiset_without_notes.releaseNotes is None
504522

505523
# Test that releaseNotes can be set to a string value
506-
meta_dict["releaseNotes"] = "Releasing during testing"
507-
dandiset_with_notes = PublishedDandiset(**meta_dict)
524+
base_dandiset_metadata["releaseNotes"] = "Releasing during testing"
525+
dandiset_with_notes = PublishedDandiset(**base_dandiset_metadata)
508526
assert dandiset_with_notes.releaseNotes == "Releasing during testing"
509527

510528
# Test that releaseNotes appears in model_dump

0 commit comments

Comments
 (0)