Skip to content
Snippets Groups Projects

Add tests of has_mandatory_consents property

Merged Andreas Ellewsen requested to merge tests/mandatory_consents into master
1 file
+ 50
0
Compare changes
  • Side-by-side
  • Inline
@@ -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
Loading