Skip to content

Commit 91e2e75

Browse files
committed
test: provide tests for Dandiset.sameAs
1 parent 036a918 commit 91e2e75

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

dandischema/tests/test_models.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,3 +1001,64 @@ class VendoredFieldModel(BaseModel):
10011001
# Validate the invalid vendored fields against the vendored patterns
10021002
with pytest.raises(ValidationError):
10031003
VendoredFieldModel.model_validate(invalid_vendored_fields)
1004+
1005+
1006+
class TestDandisetSameAs:
1007+
def test_not_specified(self, base_dandiset_metadata: dict[str, Any]) -> None:
1008+
"""
1009+
Test the case that `sameAs` is not specified in instantiating a `Dandiset`
1010+
"""
1011+
dandiset = Dandiset.model_validate(base_dandiset_metadata)
1012+
assert dandiset.sameAs is None
1013+
1014+
def test_empty_list(self, base_dandiset_metadata: dict[str, Any]) -> None:
1015+
"""
1016+
Test the case that `sameAs` in a `Dandiset` is initialized to an empty list
1017+
"""
1018+
base_dandiset_metadata["sameAs"] = []
1019+
dandiset = Dandiset.model_validate(base_dandiset_metadata)
1020+
assert dandiset.sameAs == []
1021+
1022+
@pytest.mark.parametrize(
1023+
"dandi_urls",
1024+
[
1025+
["dandi://DANDI-SANDBOX/123456"],
1026+
["dandi://EMBER-DANDI/123456"],
1027+
["dandi://DANDI-SANDBOX/123456", "dandi://EMBER-DANDI/123456"],
1028+
["dandi://A/123456", "dandi://B/654321"],
1029+
],
1030+
)
1031+
def test_with_valid_dandi_urls(
1032+
self, dandi_urls: list[str], base_dandiset_metadata: dict[str, Any]
1033+
) -> None:
1034+
"""
1035+
Test the case that `sameAs` is initialized to a list of valid DANDI URLs
1036+
"""
1037+
base_dandiset_metadata["sameAs"] = dandi_urls
1038+
dandiset = Dandiset.model_validate(base_dandiset_metadata)
1039+
assert dandiset.sameAs == dandi_urls
1040+
1041+
@pytest.mark.parametrize(
1042+
"dandi_urls",
1043+
[
1044+
# List of invalid DANDI URLs
1045+
["http://DANDI-SANDBOX/123456"],
1046+
["dandi://DANDI- SANDBOX/123456"],
1047+
["dandi://"],
1048+
["dandi://DANDI-SANDBOX/123456", "dandi://DANDI- SANDBOX/123456"],
1049+
[42],
1050+
# Value that is not a list
1051+
"DANDI-SANDBOX:123456",
1052+
42,
1053+
],
1054+
)
1055+
def test_with_invalid_dandi_urls(
1056+
self, dandi_urls: Any, base_dandiset_metadata: dict[str, Any]
1057+
) -> None:
1058+
"""
1059+
Test the case that `sameAs` is initialized to an invalid list of DANDI URLs
1060+
or a value that is not a list
1061+
"""
1062+
base_dandiset_metadata["sameAs"] = dandi_urls
1063+
with pytest.raises(ValidationError):
1064+
Dandiset.model_validate(base_dandiset_metadata)

0 commit comments

Comments
 (0)