-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from candleindark/contact-person-email
Add validator to ensure a contact person has email provided
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ def metadata_basic() -> Dict[str, Any]: | |
"contributor": [ | ||
{ | ||
"name": "A_last, A_first", | ||
"email": "[email protected]", | ||
"roleName": [RoleType("dcite:ContactPerson")], | ||
} | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,7 @@ def test_mismatch_key(schema_version: str, schema_key: str) -> None: | |
{ | ||
"schemaKey": "Person", | ||
"name": "Last, first", | ||
"email": "[email protected]", | ||
"roleName": ["dcite:ContactPerson"], | ||
} | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
Asset, | ||
BaseType, | ||
CommonModel, | ||
Contributor, | ||
DandiBaseModel, | ||
Dandiset, | ||
DigestType, | ||
|
@@ -378,6 +379,7 @@ def test_dantimeta_1() -> None: | |
"contributor": [ | ||
{ | ||
"name": "last name, first name", | ||
"email": "[email protected]", | ||
"roleName": [RoleType("dcite:ContactPerson")], | ||
} | ||
], | ||
|
@@ -592,6 +594,7 @@ def test_schemakey_roundtrip() -> None: | |
}, | ||
{ | ||
"name": "last2, first2", | ||
"email": "[email protected]", | ||
"roleName": ["dcite:ContactPerson"], | ||
"schemaKey": "Person", | ||
"affiliation": [], | ||
|
@@ -689,3 +692,43 @@ def test_embargoedaccess() -> None: | |
) | ||
] | ||
) | ||
|
||
|
||
_NON_CONTACT_PERSON_ROLES_ARGS: List[List[RoleType]] = [ | ||
[], | ||
[RoleType.Author, RoleType.DataCurator], | ||
[RoleType.Funder], | ||
] | ||
|
||
_CONTACT_PERSON_ROLES_ARGS: List[List[RoleType]] = [ | ||
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_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_without_email(self, roles: List[RoleType]) -> None: | ||
""" | ||
Test creating a `Contributor` instance as a non-contact person without an email | ||
""" | ||
Contributor(roleName=roles) | ||
|
||
@pytest.mark.parametrize( | ||
"roles", _NON_CONTACT_PERSON_ROLES_ARGS + _CONTACT_PERSON_ROLES_ARGS | ||
) | ||
def test_with_email(self, roles: List[RoleType]) -> None: | ||
""" | ||
Test creating a `Contributor` instance with an email | ||
""" | ||
Contributor(email="[email protected]", roleName=roles) |