Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dandischema/consts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from packaging.version import Version as _Version

DANDI_SCHEMA_VERSION = "0.8.0"
DANDI_SCHEMA_VERSION = "0.8.1"
ALLOWED_INPUT_SCHEMAS = [
"0.4.4",
"0.5.1",
Expand All @@ -17,12 +17,13 @@
"0.6.9",
"0.6.10",
"0.7.0",
"0.8.0",
DANDI_SCHEMA_VERSION,
]

# We establish migrations (back) to only a few recent versions.
# When adding changes, please consider whether a migration path should be added.
ALLOWED_TARGET_SCHEMAS = ["0.6.10", "0.7.0", DANDI_SCHEMA_VERSION]
ALLOWED_TARGET_SCHEMAS = ["0.6.10", "0.7.0", "0.8.0", DANDI_SCHEMA_VERSION]

# This allows multiple schemas for validation, whereas target schemas focus on
# migration.
Expand Down
6 changes: 3 additions & 3 deletions dandischema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,9 @@ class BaseType(DandiBaseModel):
" supported by identifiers.org.",
json_schema_extra={"nskey": "schema"},
)
name: Optional[str] = Field(
None,
name: str = Field(
description="The name of the item.",
min_length=1,
max_length=150,
json_schema_extra={"nskey": "schema"},
)
Expand Down Expand Up @@ -906,7 +906,7 @@ class Contributor(DandiBaseModel):
"people or ROR (ror.org) for institutions.",
json_schema_extra={"nskey": "schema"},
)
name: Optional[str] = Field(None, json_schema_extra={"nskey": "schema"})
name: str = Field(min_length=1, json_schema_extra={"nskey": "schema"})
email: Optional[EmailStr] = Field(None, json_schema_extra={"nskey": "schema"})
url: Optional[AnyHttpUrl] = Field(None, json_schema_extra={"nskey": "schema"})
roleName: Optional[List[RoleType]] = Field(
Expand Down
48 changes: 45 additions & 3 deletions dandischema/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,14 +850,14 @@ def test_contact_person_without_email(self, roles: List[RoleType]) -> None:
with pytest.raises(
pydantic.ValidationError, match="Contact person must have an email address"
):
Contributor(roleName=roles)
Contributor(name="Nemo", roleName=roles)

@pytest.mark.parametrize("roles", _NON_CONTACT_PERSON_ROLES_ARGS)
def test_non_contact_person_without_email(self, roles: List[RoleType]) -> None:
"""
Test creating a `Contributor` instance as a non-contact person without an email
"""
Contributor(roleName=roles)
Contributor(name="Nemo", roleName=roles)

@pytest.mark.parametrize(
"roles", _NON_CONTACT_PERSON_ROLES_ARGS + _CONTACT_PERSON_ROLES_ARGS
Expand All @@ -866,7 +866,49 @@ def test_with_email(self, roles: List[RoleType]) -> None:
"""
Test creating a `Contributor` instance with an email
"""
Contributor(email="nemo@dandiarchive.org", roleName=roles)
Contributor(name="Nemo", email="nemo@dandiarchive.org", roleName=roles)

@pytest.mark.ai_generated
@pytest.mark.parametrize("model", [Contributor, Organization, Person])
@pytest.mark.parametrize("name_kwargs", [{}, {"name": None}, {"name": ""}])
def test_name_required(
self, model: Type[Contributor], name_kwargs: Dict[str, Any]
) -> None:
"""
Test that `name` is required and non-empty for `Contributor` and subclasses

(https://github.com/dandi/dandi-schema/issues/442)
"""
with pytest.raises(pydantic.ValidationError) as exc_info:
model(**name_kwargs)
assert [e["loc"] for e in exc_info.value.errors()] == [("name",)]


@pytest.mark.ai_generated
@pytest.mark.parametrize(
"model",
[
m
for m in vars(models).values()
if isclass(m) and issubclass(m, BaseType) and m.__module__ == models.__name__
],
)
class TestBaseTypeName:
"""
`name` is required and non-empty for `BaseType` and all its subclasses
(https://github.com/dandi/dandi-schema/issues/442)
"""

@pytest.mark.parametrize("name_kwargs", [{}, {"name": None}, {"name": ""}])
def test_name_required(
self, model: Type[BaseType], name_kwargs: Dict[str, Any]
) -> None:
with pytest.raises(pydantic.ValidationError) as exc_info:
model(identifier="UBERON:0004727", **name_kwargs)
assert [e["loc"] for e in exc_info.value.errors()] == [("name",)]

def test_with_name(self, model: Type[BaseType]) -> None:
assert model(name="cochlear nerve").name == "cochlear nerve"


def _get_field_pattern(
Expand Down
Loading
Loading