diff --git a/greg/tests/models/test_person.py b/greg/tests/models/test_person.py index f9fc4958d84c12635169b29455d96d0db4a2cb54..a83731beaad0ff2d04946fcd9ab4a8ca30d80894 100644 --- a/greg/tests/models/test_person.py +++ b/greg/tests/models/test_person.py @@ -5,6 +5,9 @@ import pytest from django.utils import timezone from greg.models import ( + Consent, + ConsentChoice, + ConsentType, OrganizationalUnit, Person, Identity, @@ -190,3 +193,50 @@ def test_person_str(person: Person): @pytest.mark.django_db def test_person_repr(person: Person): assert repr(person) == "Person(id=1, first_name='Test', last_name='Tester')" + + +@pytest.mark.django_db +def test_person_has_mandatory_consents(person): + """ + No consents exists. + + Should return True + """ + assert person.has_mandatory_consents is True + + +@pytest.mark.django_db +def test_person_has_mandatory_consents_only_optional(person): + """ + An optional consent exists, and the person has not given consent. + + Should return True + """ + ConsentType.objects.create(user_allowed_to_change=True) + assert person.has_mandatory_consents is True + + +@pytest.mark.django_db +def test_person_has_mandatory_consents_mandatory_exists(person): + """ + A mandatory consent exists, and the person has not given it. + + Should return False + """ + ConsentType.objects.create(user_allowed_to_change=True, mandatory=True) + assert person.has_mandatory_consents is False + + +@pytest.mark.django_db +def test_person_has_mandatory_consents_mandatory_given(person): + """ + A mandatory consent exists, and the person has given it. + + Should return True + """ + ct = ConsentType.objects.create(user_allowed_to_change=True, mandatory=True) + cc = ConsentChoice.objects.create(consent_type=ct) + Consent.objects.create( + person=person, type=ct, choice=cc, consent_given_at=timezone.now() + ) + assert person.has_mandatory_consents is True