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
72717d01
Commit
72717d01
authored
1 year ago
by
Marte Fossum
Browse files
Options
Downloads
Patches
Plain Diff
Make sponsororanizationalunit endpoint match doc
parent
d77541bf
No related branches found
Branches containing commit
No related tags found
1 merge request
!433
Make sponsororanizationalunit endpoint match doc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
greg/api/views/sponsor.py
+24
-18
24 additions, 18 deletions
greg/api/views/sponsor.py
greg/tests/api/test_sponsor.py
+12
-11
12 additions, 11 deletions
greg/tests/api/test_sponsor.py
greg/tests/management/test_import_usernames.py
+0
-1
0 additions, 1 deletion
greg/tests/management/test_import_usernames.py
with
36 additions
and
30 deletions
greg/api/views/sponsor.py
+
24
−
18
View file @
72717d01
...
...
@@ -97,21 +97,24 @@ class SponsorOrgunitLinkView(
automatic
=
automatic
,
source
=
source
,
)
serializer
=
self
.
serializer_class
(
sponsor_orgunit
,
many
=
True
)
return
Response
(
serializer
.
data
)
SponsorOrganizationalUnit
.
objects
.
create
(
sponsor
=
Sponsor
.
objects
.
get
(
id
=
kwargs
[
"
sponsor_id
"
]),
organizational_unit
=
OrganizationalUnit
.
objects
.
get
(
id
=
kwargs
[
"
orgunit_id
"
]),
hierarchical_access
=
hierarchical_access
,
automatic
=
automatic
,
source
=
source
,
)
else
:
SponsorOrganizationalUnit
.
objects
.
create
(
sponsor
=
Sponsor
.
objects
.
get
(
id
=
kwargs
[
"
sponsor_id
"
]),
organizational_unit
=
OrganizationalUnit
.
objects
.
get
(
id
=
kwargs
[
"
orgunit_id
"
]
),
hierarchical_access
=
hierarchical_access
,
automatic
=
automatic
,
source
=
source
,
)
try
:
sponsor_orgunit
=
self
.
queryset
.
get
(
sponsor__id
=
sponsor_id
,
organizational_unit__id
=
orgunit_id
)
except
SponsorOrganizationalUnit
.
DoesNotExist
:
return
Response
({})
sponsor_orgunit
=
self
.
queryset
.
filter
(
sponsor__id
=
sponsor_id
,
organizational_unit__id
=
orgunit_id
)
serializer
=
self
.
serializer_class
(
sponsor_orgunit
,
many
=
True
)
serializer
=
self
.
serializer_class
(
sponsor_orgunit
)
return
Response
(
serializer
.
data
)
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -137,10 +140,13 @@ class SponsorOrgunitLinkView(
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
"""
Returns a given SponsorOrganizationalUnit object
"""
(
sponsor_id
,
orgunit_id
)
=
self
.
_extract_sponsor_and_orgunit
(
kwargs
)
unit
=
self
.
queryset
.
filter
(
sponsor__id
=
sponsor_id
,
organizational_unit__id
=
orgunit_id
)
serializer
=
self
.
serializer_class
(
unit
,
many
=
True
)
try
:
unit
=
self
.
queryset
.
get
(
sponsor__id
=
sponsor_id
,
organizational_unit__id
=
orgunit_id
)
except
SponsorOrganizationalUnit
.
DoesNotExist
:
return
Response
({})
serializer
=
self
.
serializer_class
(
unit
)
return
Response
(
serializer
.
data
)
def
_extract_sponsor_and_orgunit
(
self
,
request_data
):
...
...
This diff is collapsed.
Click to expand it.
greg/tests/api/test_sponsor.py
+
12
−
11
View file @
72717d01
...
...
@@ -176,7 +176,8 @@ def test_add_sponsor_unit_link_with_no_access_parameter(
response
=
client
.
post
(
create_sponsor_link_url
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
response_body
=
response
.
json
()
assert
len
(
response_body
)
==
1
assert
response_body
[
"
sponsor
"
]
==
sponsor_id
assert
response_body
[
"
organizational_unit
"
]
==
unit_foo
.
id
# Check that the unit is attached to the sponsor
sponsor_lookup_response
=
client
.
get
(
sponsor_url
,
kwargs
=
{
"
id
"
:
sponsor_id
})
...
...
@@ -204,9 +205,10 @@ def test_retrieve_sponsor_orgunit(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_guy
.
id
,
"
orgunit_id
"
:
unit_foo
.
id
},
)
spons
or_unit
=
client
.
get
(
url
).
json
()
re
spons
e_body
=
client
.
get
(
url
).
json
()
assert
len
(
sponsor_unit
)
==
1
assert
response_body
[
"
sponsor
"
]
==
sponsor_guy
.
id
assert
response_body
[
"
organizational_unit
"
]
==
unit_foo
.
id
@pytest.mark.django_db
...
...
@@ -219,9 +221,9 @@ def test_no_sponsor_orgunit_exists(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_foo
.
id
,
"
orgunit_id
"
:
unit_foo
.
id
},
)
spons
or_unit
=
client
.
get
(
url
).
json
()
re
spons
e_body
=
client
.
get
(
url
).
json
()
assert
len
(
sponsor_unit
)
==
0
assert
not
response_body
@pytest.mark.django_db
...
...
@@ -254,8 +256,8 @@ def test_update_sponsor_orgunit(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_guy
.
id
,
"
orgunit_id
"
:
unit_foo
.
id
},
)
assert
sponsor_org_unit
.
hierarchical_access
is
False
response_data
=
client
.
post
(
url
,
data
=
data
).
json
()
[
0
]
assert
not
sponsor_org_unit
.
hierarchical_access
response_data
=
client
.
post
(
url
,
data
=
data
).
json
()
assert
response_data
[
"
hierarchical_access
"
]
==
data
[
"
hierarchical_access
"
]
assert
response_data
[
"
automatic
"
]
==
data
[
"
automatic
"
]
...
...
@@ -278,7 +280,7 @@ def test_create_new_sponsor_orgunit(
kwargs
=
{
"
sponsor_id
"
:
sponsor_foo
.
id
,
"
orgunit_id
"
:
unit_foo
.
id
},
)
sponsor_unit
=
client
.
get
(
get_url
).
json
()
assert
len
(
sponsor_unit
)
==
0
assert
not
sponsor_unit
post_url
=
reverse
(
"
v1:sponsor_orgunit-detail
"
,
...
...
@@ -286,9 +288,8 @@ def test_create_new_sponsor_orgunit(
)
response_data
=
client
.
post
(
post_url
,
data
=
data
).
json
()
assert
len
(
response_data
)
==
1
response_data
=
response_data
[
0
]
assert
response_data
[
"
sponsor
"
]
==
sponsor_foo
.
id
assert
response_data
[
"
organizational_unit
"
]
==
unit_foo
.
id
assert
response_data
[
"
hierarchical_access
"
]
==
data
[
"
hierarchical_access
"
]
assert
response_data
[
"
automatic
"
]
==
data
[
"
automatic
"
]
assert
response_data
[
"
source
"
]
==
data
[
"
source
"
]
This diff is collapsed.
Click to expand it.
greg/tests/management/test_import_usernames.py
+
0
−
1
View file @
72717d01
...
...
@@ -221,7 +221,6 @@ def test_different_feide_id_already_exists(
assert
person_identities
[
0
].
value
==
"
foobar@test.no
"
call_command
(
"
import_usernames_from_cerebrum
"
,
"
--without-usernames
"
,
"
--commit
"
)
person_identities
=
person_three
.
identities
.
filter
(
type
=
usr_id_type
)
print
(
person_identities
)
assert
len
(
person_identities
)
==
2
assert
person_identities
[
0
].
value
==
"
foobar@test.no
"
assert
person_identities
[
1
].
value
==
"
foobar@inst.no
"
...
...
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