Skip to content

Commit

Permalink
Clean up person tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderVertegaal committed Feb 5, 2024
1 parent 351e313 commit 32a53a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 41 deletions.
34 changes: 0 additions & 34 deletions backend/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,3 @@ def epistolary_event(db, letter, case_study):
)

return epistolary_event


@pytest.fixture()
def person_unnamed(db):
person = Person.objects.create()
return person


@pytest.fixture()
def person_single_name(db):
person = Person.objects.create()
PersonName.objects.create(person=person, value="Bert")
return person


@pytest.fixture()
def person_multiple_names(db):
person = Person.objects.create()
PersonName.objects.create(person=person, value="Bert")
PersonName.objects.create(person=person, value="Ernie")
PersonName.objects.create(person=person, value="Oscar")
return person

@pytest.fixture()
def person_with_exact_dob(db):
person = Person.objects.create()
PersonDateOfBirth.objects.create(person=person, year_exact=512)
return person

@pytest.fixture()
def person_with_approx_dob(db):
person = Person.objects.create()
PersonDateOfBirth.objects.create(person=person, year_lower=500, year_upper=525)
return person
31 changes: 24 additions & 7 deletions backend/person/tests/test_person_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
def test_person_names(person_unnamed, person_single_name, person_multiple_names):
from person.models import PersonDateOfBirth, PersonName

assert person_unnamed.__str__().startswith("Unknown person #")
assert person_single_name.__str__() == "Bert"
assert person_multiple_names.__str__() == "Bert (aka Ernie, Oscar)"

def test_person_name_for_unnamed_person(person):
assert person.__str__().startswith("Unknown person #")

def test_person_date_of_birth(person_with_exact_dob, person_with_approx_dob):
assert person_with_exact_dob.date_of_birth.__str__().endswith("born in 512")
assert person_with_approx_dob.date_of_birth.__str__().endswith("born c. 500–525")

def test_person_name_for_person_with_single_name(person):
PersonName.objects.create(person=person, value="Bert")
assert person.__str__() == "Bert"


def test_person_name_for_person_with_multiple_names(person):
PersonName.objects.create(person=person, value="Bert")
PersonName.objects.create(person=person, value="Ernie")
PersonName.objects.create(person=person, value="Oscar")
assert person.__str__() == "Bert (aka Ernie, Oscar)"


def test_person_with_exact_date_of_birth(person):
PersonDateOfBirth.objects.create(person=person, year_exact=512)
assert person.date_of_birth.__str__().endswith("born in 512")


def test_person_with_approx_date_of_birth(person):
PersonDateOfBirth.objects.create(person=person, year_lower=500, year_upper=525)
assert person.date_of_birth.__str__().endswith("born c. 500–525")

0 comments on commit 32a53a5

Please sign in to comment.