|
1 | | -from copy import deepcopy |
2 | 1 | from datetime import datetime |
3 | 2 | import json |
4 | 3 | import os |
@@ -59,6 +58,33 @@ def schema() -> Any: |
59 | 58 | return _get_datacite_schema() |
60 | 59 |
|
61 | 60 |
|
| 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 | + |
62 | 88 | @pytest.fixture(scope="function") |
63 | 89 | def metadata_basic() -> Dict[str, Any]: |
64 | 90 | dandi_id_noprefix = f"000{random.randrange(100, 999)}" |
@@ -615,3 +641,39 @@ def test_deprecated_publish_parameter(metadata_basic: Dict[str, Any]) -> None: |
615 | 641 |
|
616 | 642 | # Check that event is "publish" despite using the deprecated parameter |
617 | 643 | 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