Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
80793d70
Verified
Commit
80793d70
authored
3 years ago
by
Andreas Ellewsen
Browse files
Options
Downloads
Patches
Plain Diff
Add more tests of hierarchical_access to OUs
parent
053a1dca
No related branches found
No related tags found
1 merge request
!283
Add more tests of hierarchical_access to OUs
Pipeline
#116113
passed
3 years ago
Stage: venv update
Stage: tests and linting
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
greg/tests/models/test_sponsor.py
+16
-0
16 additions, 0 deletions
greg/tests/models/test_sponsor.py
gregui/tests/api/views/test_ou.py
+35
-0
35 additions, 0 deletions
gregui/tests/api/views/test_ou.py
with
51 additions
and
0 deletions
greg/tests/models/test_sponsor.py
+
16
−
0
View file @
80793d70
...
@@ -71,3 +71,19 @@ def test_get_allowed_loop(loop_sponsor, looped_units, unit_foo):
...
@@ -71,3 +71,19 @@ def test_get_allowed_loop(loop_sponsor, looped_units, unit_foo):
units
=
loop_sponsor
.
get_allowed_units
()
units
=
loop_sponsor
.
get_allowed_units
()
expected
=
[
i
.
id
for
i
in
looped_units
]
+
[
unit_foo
.
id
]
expected
=
[
i
.
id
for
i
in
looped_units
]
+
[
unit_foo
.
id
]
assert
[
x
.
id
for
x
in
units
]
==
expected
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
}
This diff is collapsed.
Click to expand it.
gregui/tests/api/views/test_ou.py
0 → 100644
+
35
−
0
View file @
80793d70
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
"
},
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment