Skip to content
Snippets Groups Projects
Commit 44b44446 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Merge branch 'tests/mandatory_consents' into 'master'

Add tests of has_mandatory_consents property

See merge request !292
parents 016a01ab 3468e18e
No related branches found
No related tags found
1 merge request!292Add tests of has_mandatory_consents property
Pipeline #119256 passed
...@@ -5,6 +5,9 @@ import pytest ...@@ -5,6 +5,9 @@ import pytest
from django.utils import timezone from django.utils import timezone
from greg.models import ( from greg.models import (
Consent,
ConsentChoice,
ConsentType,
OrganizationalUnit, OrganizationalUnit,
Person, Person,
Identity, Identity,
...@@ -190,3 +193,50 @@ def test_person_str(person: Person): ...@@ -190,3 +193,50 @@ def test_person_str(person: Person):
@pytest.mark.django_db @pytest.mark.django_db
def test_person_repr(person: Person): def test_person_repr(person: Person):
assert repr(person) == "Person(id=1, first_name='Test', last_name='Tester')" 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