Update testing documentation and improve test structure
All checks were successful
Test pipeline / test (push) Successful in 12s
All checks were successful
Test pipeline / test (push) Successful in 12s
This commit is contained in:
parent
1c84cae93b
commit
eb270cba9b
9 changed files with 617 additions and 20 deletions
95
tests/test_person.py
Normal file
95
tests/test_person.py
Normal file
|
@ -0,0 +1,95 @@
|
|||
import pytest
|
||||
from doi2dataset import Person, Institution
|
||||
|
||||
def test_person_to_dict_with_string_affiliation():
|
||||
"""Test Person.to_dict() with a string affiliation."""
|
||||
person = Person(
|
||||
family_name="Doe",
|
||||
given_name="John",
|
||||
orcid="0000-0001-2345-6789",
|
||||
email="john.doe@example.org",
|
||||
affiliation="Test University",
|
||||
project=["Project A"]
|
||||
)
|
||||
|
||||
result = person.to_dict()
|
||||
|
||||
assert result["family_name"] == "Doe"
|
||||
assert result["given_name"] == "John"
|
||||
assert result["orcid"] == "0000-0001-2345-6789"
|
||||
assert result["email"] == "john.doe@example.org"
|
||||
assert result["project"] == ["Project A"]
|
||||
assert result["affiliation"] == "Test University"
|
||||
|
||||
|
||||
def test_person_to_dict_with_institution_ror():
|
||||
"""Test Person.to_dict() with an Institution that has a ROR ID."""
|
||||
inst = Institution("Test University", "https://ror.org/12345")
|
||||
|
||||
person = Person(
|
||||
family_name="Doe",
|
||||
given_name="John",
|
||||
orcid="0000-0001-2345-6789",
|
||||
email="john.doe@example.org",
|
||||
affiliation=inst,
|
||||
project=["Project A"]
|
||||
)
|
||||
|
||||
result = person.to_dict()
|
||||
|
||||
assert result["affiliation"] == "https://ror.org/12345"
|
||||
# Check other fields too
|
||||
assert result["family_name"] == "Doe"
|
||||
assert result["given_name"] == "John"
|
||||
|
||||
|
||||
def test_person_to_dict_with_institution_display_name_only():
|
||||
"""Test Person.to_dict() with an Institution that has only a display_name."""
|
||||
inst = Institution("Test University") # No ROR ID
|
||||
|
||||
person = Person(
|
||||
family_name="Smith",
|
||||
given_name="Jane",
|
||||
orcid="0000-0001-9876-5432",
|
||||
affiliation=inst
|
||||
)
|
||||
|
||||
result = person.to_dict()
|
||||
|
||||
assert result["affiliation"] == "Test University"
|
||||
assert result["family_name"] == "Smith"
|
||||
assert result["given_name"] == "Jane"
|
||||
|
||||
|
||||
def test_person_to_dict_with_empty_institution():
|
||||
"""Test Person.to_dict() with an Institution that has neither ROR nor display_name."""
|
||||
# Create an Institution with empty values
|
||||
inst = Institution("")
|
||||
|
||||
person = Person(
|
||||
family_name="Brown",
|
||||
given_name="Robert",
|
||||
affiliation=inst
|
||||
)
|
||||
|
||||
result = person.to_dict()
|
||||
|
||||
assert result["affiliation"] == ""
|
||||
assert result["family_name"] == "Brown"
|
||||
assert result["given_name"] == "Robert"
|
||||
|
||||
|
||||
def test_person_to_dict_with_no_affiliation():
|
||||
"""Test Person.to_dict() with no affiliation."""
|
||||
person = Person(
|
||||
family_name="Green",
|
||||
given_name="Alice",
|
||||
orcid="0000-0002-1111-2222"
|
||||
)
|
||||
|
||||
result = person.to_dict()
|
||||
|
||||
assert result["affiliation"] == ""
|
||||
assert result["family_name"] == "Green"
|
||||
assert result["given_name"] == "Alice"
|
||||
assert result["orcid"] == "0000-0002-1111-2222"
|
Loading…
Add table
Add a link
Reference in a new issue