Skip to content

Commit

Permalink
Provide tests for the feature that ensures email existence for contac…
Browse files Browse the repository at this point in the history
…t persons
  • Loading branch information
candleindark committed Apr 11, 2024
1 parent e53ff14 commit 6e7a3a2
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions dandischema/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Asset,
BaseType,
CommonModel,
Contributor,
DandiBaseModel,
Dandiset,
DigestType,
Expand Down Expand Up @@ -691,3 +692,53 @@ def test_embargoedaccess() -> None:
)
]
)


def _non_contact_person_roles_args() -> List[List[RoleType]]:
"""
Return a list of role lists that each do not contain the role of a contact person
"""
return [[], [RoleType.Author, RoleType.DataCurator], [RoleType.Funder]]


def _contact_person_roles_args() -> List[List[RoleType]]:
"""
Return a list of role lists that each contains the role of a contact person
"""
return [
role_lst + [RoleType.ContactPerson]
for role_lst in _non_contact_person_roles_args()
]


class TestContributor:
@pytest.mark.parametrize("roles", _contact_person_roles_args())
def test_contact_person_with_email(self, roles: List[RoleType]) -> None:
"""
Test creating a `Contributor` instance as a contact person with an email
"""
Contributor(email="nemo@dandiarchive.org", roleName=roles)

@pytest.mark.parametrize("roles", _contact_person_roles_args())
def test_contact_person_without_email(self, roles: List[RoleType]) -> None:
"""
Test creating a `Contributor` instance as a contact person without an email
"""
with pytest.raises(
pydantic.ValidationError, match="Contact person must have an email address"
):
Contributor(roleName=roles)

@pytest.mark.parametrize("roles", _non_contact_person_roles_args())
def test_non_contact_person_with_email(self, roles: List[RoleType]) -> None:
"""
Test creating a `Contributor` instance as a non-contact person with an email
"""
Contributor(email="nemo@dandiarchive.org", 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)

0 comments on commit 6e7a3a2

Please sign in to comment.