Skip to content

Commit 9bf653f

Browse files
committed
Add draft dandiset metadata fixture and use for test with and without datacite API
1 parent d530322 commit 9bf653f

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

dandischema/datacite/tests/test_datacite.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from copy import deepcopy
21
from datetime import datetime
32
import json
43
import os
@@ -59,6 +58,33 @@ def schema() -> Any:
5958
return _get_datacite_schema()
6059

6160

61+
@pytest.fixture(scope="function")
62+
def metadata_draft() -> Dict[str, Any]:
63+
"""Draft dandiset metadata that will trigger unvalidated fallback"""
64+
dandi_id_noprefix = f"000{random.randrange(100, 999)}"
65+
dandi_id = f"DANDI:{dandi_id_noprefix}"
66+
67+
return {
68+
"identifier": dandi_id,
69+
"id": f"{dandi_id}/draft",
70+
"name": "testing draft dataset",
71+
"description": "testing draft",
72+
"contributor": [
73+
{
74+
"name": "A_last, A_first",
75+
"email": "nemo@example.com",
76+
"roleName": [RoleType("dcite:ContactPerson")],
77+
"schemaKey": "Person",
78+
}
79+
],
80+
"license": [LicenseType("spdx:CC-BY-4.0")],
81+
"url": f"https://dandiarchive.org/dandiset/{dandi_id_noprefix}", # DLP, not version url
82+
"doi": f"10.80507/dandi.{dandi_id_noprefix}",
83+
"version": "draft",
84+
# Missing: datePublished, publishedBy, citation, etc. (triggers fallback)
85+
}
86+
87+
6288
@pytest.fixture(scope="function")
6389
def metadata_basic() -> Dict[str, Any]:
6490
dandi_id_noprefix = f"000{random.randrange(100, 999)}"
@@ -615,3 +641,39 @@ def test_deprecated_publish_parameter(metadata_basic: Dict[str, Any]) -> None:
615641

616642
# Check that event is "publish" despite using the deprecated parameter
617643
assert datacite["data"]["attributes"]["event"] == "publish"
644+
645+
646+
def test_draft_dandiset_unvalidated_fallback(metadata_draft: Dict[str, Any]) -> None:
647+
"""Test that draft dandiset metadata uses unvalidated fallback"""
648+
# Should work via unvalidated fallback without raising exception
649+
datacite = to_datacite(metadata_draft)
650+
651+
# Verify basic structure is correct
652+
assert datacite["data"]["type"] == "dois"
653+
assert datacite["data"]["id"] == metadata_draft["doi"]
654+
655+
# Verify key attributes are populated from draft metadata
656+
attrs = datacite["data"]["attributes"]
657+
assert attrs["doi"] == metadata_draft["doi"]
658+
assert attrs["version"] == "draft"
659+
assert attrs["titles"][0]["title"] == metadata_draft["name"]
660+
assert attrs["descriptions"][0]["description"] == metadata_draft["description"]
661+
662+
# Should have creators/contributors from the contributor field
663+
assert len(attrs["creators"]) > 0
664+
assert len(attrs["contributors"]) > 0
665+
666+
# Should NOT have publicationYear (since no datePublished in draft)
667+
assert "publicationYear" not in attrs
668+
669+
670+
@pytest.mark.skipif(
671+
not os.getenv("DATACITE_DEV_PASSWORD"), reason="no datacite password available"
672+
)
673+
def test_draft_dandiset_datacite_api(metadata_draft: Dict[str, Any]) -> None:
674+
"""Test that draft dandiset metadata works with actual DataCite API"""
675+
# Generate DataCite payload
676+
datacite = to_datacite(metadata_draft)
677+
678+
# Post to actual DataCite API
679+
datacite_post(datacite, metadata_draft["doi"])

0 commit comments

Comments
 (0)