From 32a53a5d720330415c06281b05b69d1a422a5b7f Mon Sep 17 00:00:00 2001 From: Xander Vertegaal Date: Mon, 5 Feb 2024 16:12:58 +0100 Subject: [PATCH] Clean up person tests --- backend/conftest.py | 34 ---------------------- backend/person/tests/test_person_models.py | 31 +++++++++++++++----- 2 files changed, 24 insertions(+), 41 deletions(-) diff --git a/backend/conftest.py b/backend/conftest.py index 25a685ff..16944be8 100644 --- a/backend/conftest.py +++ b/backend/conftest.py @@ -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 \ No newline at end of file diff --git a/backend/person/tests/test_person_models.py b/backend/person/tests/test_person_models.py index 8fb958ec..3a724a83 100644 --- a/backend/person/tests/test_person_models.py +++ b/backend/person/tests/test_person_models.py @@ -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")