Skip to content
Snippets Groups Projects
Verified Commit 7a299160 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Add tests of has_mandatory_consents property

parent a4fae612
No related branches found
No related tags found
No related merge requests found
Pipeline #118044 failed
......@@ -5,6 +5,9 @@ import pytest
from django.utils import timezone
from greg.models import (
Consent,
ConsentChoice,
ConsentType,
OrganizationalUnit,
Person,
Identity,
......@@ -190,3 +193,47 @@ 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment