|
17 | 17 | DOI_PREFIX, |
18 | 18 | INSTANCE_NAME, |
19 | 19 | METADATA_DIR, |
20 | | - basic_publishmeta, |
21 | 20 | skipif_instance_name_not_dandi, |
22 | 21 | skipif_no_network, |
23 | 22 | skipif_no_test_dandiset_metadata_dir, |
@@ -497,35 +496,59 @@ def test_migrate_schemaversion_update() -> None: |
497 | 496 |
|
498 | 497 |
|
499 | 498 | @pytest.mark.ai_generated |
500 | | -def test_migrate_downgrade_releasenotes() -> None: |
501 | | - """Test downgrade from 0.6.11 to 0.6.10 handling releaseNotes field""" |
| 499 | +def test_migrate_downgrade() -> None: |
| 500 | + """Test downgrade from 0.7.0 to 0.6.10 handling releaseNotes and sameAs fields""" |
502 | 501 |
|
503 | | - # Create a basic PublishedDandiset metadata in 0.6.11 format |
504 | | - meta_dict = { |
505 | | - "schemaVersion": "0.6.11", |
| 502 | + # Minimal metadata at current (0.7.0) version |
| 503 | + meta_dict: dict = { |
| 504 | + "schemaKey": "Dandiset", |
| 505 | + "schemaVersion": DANDI_SCHEMA_VERSION, |
| 506 | + "identifier": "DANDI:000000", |
506 | 507 | } |
507 | | - meta_dict.update(basic_publishmeta(dandi_id="999999")) |
508 | 508 |
|
509 | | - # Test 1: Downgrade without releaseNotes (should succeed) |
| 509 | + # Test 1: Downgrade without new fields (should succeed) |
510 | 510 | downgraded = migrate(meta_dict, to_version="0.6.10", skip_validation=True) |
511 | 511 | assert downgraded["schemaVersion"] == "0.6.10" |
512 | 512 | assert "releaseNotes" not in downgraded |
| 513 | + assert "sameAs" not in downgraded |
513 | 514 |
|
514 | 515 | # Test 2: Downgrade with empty releaseNotes (should succeed) |
515 | 516 | meta_dict["releaseNotes"] = "" |
516 | 517 | downgraded = migrate(meta_dict, to_version="0.6.10", skip_validation=True) |
517 | 518 | assert downgraded["schemaVersion"] == "0.6.10" |
518 | 519 | assert "releaseNotes" not in downgraded |
519 | 520 |
|
520 | | - # Test 3: Downgrade with non-empty releaseNotes (should fail) |
| 521 | + # Test 3: Downgrade with None releaseNotes (should succeed) |
| 522 | + meta_dict["releaseNotes"] = None |
| 523 | + downgraded = migrate(meta_dict, to_version="0.6.10", skip_validation=True) |
| 524 | + assert downgraded["schemaVersion"] == "0.6.10" |
| 525 | + assert "releaseNotes" not in downgraded |
| 526 | + |
| 527 | + # Test 4: Downgrade with empty sameAs list (should succeed) |
| 528 | + meta_dict.pop("releaseNotes") |
| 529 | + meta_dict["sameAs"] = [] |
| 530 | + downgraded = migrate(meta_dict, to_version="0.6.10", skip_validation=True) |
| 531 | + assert downgraded["schemaVersion"] == "0.6.10" |
| 532 | + assert "sameAs" not in downgraded |
| 533 | + |
| 534 | + # Test 5: Downgrade with non-empty releaseNotes (should fail) |
| 535 | + meta_dict.pop("sameAs") |
521 | 536 | meta_dict["releaseNotes"] = "Releasing during testing" |
522 | 537 | with pytest.raises(ValueError, match="Cannot downgrade to 0.6.10 from"): |
523 | 538 | migrate(meta_dict, to_version="0.6.10", skip_validation=True) |
524 | 539 |
|
525 | | - # Test 4: No-op migration (already at target version) |
526 | | - meta_dict_0610 = meta_dict.copy() |
527 | | - meta_dict_0610["schemaVersion"] = "0.6.10" |
528 | | - meta_dict_0610.pop("releaseNotes") |
| 540 | + # Test 6: Downgrade with non-empty sameAs (should fail) |
| 541 | + meta_dict.pop("releaseNotes") |
| 542 | + meta_dict["sameAs"] = ["dandi://DANDI-SANDBOX/123456"] |
| 543 | + with pytest.raises(ValueError, match="Cannot downgrade to 0.6.10 from"): |
| 544 | + migrate(meta_dict, to_version="0.6.10", skip_validation=True) |
| 545 | + |
| 546 | + # Test 7: No-op migration (already at target version) |
| 547 | + meta_dict_0610 = { |
| 548 | + "schemaKey": "Dandiset", |
| 549 | + "schemaVersion": "0.6.10", |
| 550 | + "identifier": "DANDI:000000", |
| 551 | + } |
529 | 552 | migrated = migrate(meta_dict_0610, to_version="0.6.10", skip_validation=True) |
530 | 553 | assert migrated == meta_dict_0610 |
531 | 554 | assert migrated is not meta_dict_0610 # but we do create a copy |
|
0 commit comments