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

Merge branch 'GREG-210-test-hierarchical-access' into 'master'

Add more tests of hierarchical_access to OUs

See merge request !283
parents dd63d7a0 80793d70
No related branches found
No related tags found
1 merge request!283Add more tests of hierarchical_access to OUs
Pipeline #117176 failed
......@@ -71,3 +71,19 @@ def test_get_allowed_loop(loop_sponsor, looped_units, unit_foo):
units = loop_sponsor.get_allowed_units()
expected = [i.id for i in looped_units] + [unit_foo.id]
assert [x.id for x in units] == expected
@pytest.mark.django_db
def test_get_allowed(sponsor_foo, unit1, unit2):
"""Verify that hierarchical_access controls access to allowed units"""
spu = sponsor_ou_relation(sponsor=sponsor_foo, organizational_unit=unit1)
unit2.parent = unit1
unit2.save()
# Without hier access only get unit connected to
assert sponsor_foo.get_allowed_units() == {unit1}
# With hier access also get units below
spu.hierarchical_access = True
spu.save()
assert sponsor_foo.get_allowed_units() == {unit1, unit2}
import pytest
from django.urls import reverse
from rest_framework import status
from greg.models import OrganizationalUnit, SponsorOrganizationalUnit
@pytest.mark.django_db
def test_hierarchy_access_sponsor_ous(client, user_sponsor, unit_bar, log_in):
"""
Verify that setting hierarchical access makes sub units visible for
sponsors.
"""
url = reverse("gregui-v1:ou-list")
log_in(user_sponsor)
# add extra unit not visible without hierarchical access
unit_bar.parent = OrganizationalUnit.objects.get(pk=1)
unit_bar.save()
# Only direct connection visible
response = client.get(url)
assert response.status_code == status.HTTP_200_OK
assert response.json() == [{"id": 1, "en": "Foo EN", "nb": "Foo NB"}]
# Tree visible with hierarchy access
sou = SponsorOrganizationalUnit.objects.get(pk=1)
sou.hierarchical_access = True
sou.save()
response = client.get(url)
assert response.status_code == status.HTTP_200_OK
assert response.json() == [
{"id": 1, "en": "Foo EN", "nb": "Foo NB"},
{"id": 2, "en": "Bar EN", "nb": "Bar NB"},
]
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