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
86e39a98
Commit
86e39a98
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
GREG-91: Fixing formatting
parent
de45c9c7
No related branches found
No related tags found
1 merge request
!126
GREG-91: Expand sponsor api
Pipeline
#98515
failed
3 years ago
Stage: venv update
Stage: tests and linting
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
greg/api/urls.py
+12
-5
12 additions, 5 deletions
greg/api/urls.py
greg/api/views/sponsor.py
+13
-8
13 additions, 8 deletions
greg/api/views/sponsor.py
greg/tests/api/test_sponsor.py
+24
-14
24 additions, 14 deletions
greg/tests/api/test_sponsor.py
with
49 additions
and
27 deletions
greg/api/urls.py
+
12
−
5
View file @
86e39a98
...
...
@@ -11,7 +11,11 @@ from greg.api.views.person import (
IdentityViewSet
,
)
from
greg.api.views.role_type
import
RoleTypeViewSet
from
greg.api.views.sponsor
import
SponsorViewSet
,
SponsorGuestsViewSet
,
SponsorOrgunitLinkView
from
greg.api.views.sponsor
import
(
SponsorViewSet
,
SponsorGuestsViewSet
,
SponsorOrgunitLinkView
,
)
router
=
DefaultRouter
(
trailing_slash
=
False
)
router
.
register
(
r
"
persons
"
,
PersonViewSet
,
basename
=
"
person
"
)
...
...
@@ -52,8 +56,11 @@ urlpatterns += [
SponsorGuestsViewSet
.
as_view
({
"
get
"
:
"
list
"
}),
name
=
"
sponsor_guests-list
"
,
),
re_path
(
r
"
^sponsors/(?P<sponsor_id>[0-9]+)/orgunit/(?P<orgunit_id>[0-9]+)$
"
,
SponsorOrgunitLinkView
.
as_view
(
{
"
get
"
:
"
retrieve
"
,
"
post
"
:
"
create
"
,
"
delete
"
:
"
destroy
"
}),
name
=
"
sponsor_orgunit-detail
"
)
re_path
(
r
"
^sponsors/(?P<sponsor_id>[0-9]+)/orgunit/(?P<orgunit_id>[0-9]+)$
"
,
SponsorOrgunitLinkView
.
as_view
(
{
"
get
"
:
"
retrieve
"
,
"
post
"
:
"
create
"
,
"
delete
"
:
"
destroy
"
}
),
name
=
"
sponsor_orgunit-detail
"
,
),
]
This diff is collapsed.
Click to expand it.
greg/api/views/sponsor.py
+
13
−
8
View file @
86e39a98
...
...
@@ -25,7 +25,7 @@ class SponsorViewSet(ModelViewSet):
lookup_field
=
"
id
"
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
"""
Overridden method to handle exception
"""
"""
Overridden method to handle exception
"""
instance
=
self
.
get_object
()
try
:
self
.
perform_destroy
(
instance
)
...
...
@@ -63,11 +63,14 @@ class SponsorGuestsViewSet(mixins.ListModelMixin, GenericViewSet):
return
qs
class
SponsorOrgunitLinkView
(
mixins
.
CreateModelMixin
,
mixins
.
RetrieveModelMixin
,
mixins
.
DestroyModelMixin
,
GenericViewSet
):
"""
Endpoint that allows manipulation of links between a sponsor and the units he is attached to
"""
class
SponsorOrgunitLinkView
(
mixins
.
CreateModelMixin
,
mixins
.
RetrieveModelMixin
,
mixins
.
DestroyModelMixin
,
GenericViewSet
,
):
"""
Endpoint that allows manipulation of links between a sponsor and the units he is attached to
"""
queryset
=
OrganizationalUnit
.
objects
.
all
().
order_by
(
"
id
"
)
serializer_class
=
OrganizationalUnitSerializer
pagination_class
=
PrimaryKeyCursorPagination
...
...
@@ -78,12 +81,14 @@ class SponsorOrgunitLinkView(mixins.CreateModelMixin,
(
sponsor_id
,
orgunit_id
)
=
self
.
_extract_sponsor_and_orgunit
(
kwargs
)
hierarchical_access
=
request
.
data
.
get
(
"
hierarchical_access
"
)
sponsor
=
Sponsor
.
objects
.
get
(
id
=
sponsor_id
)
sponsor
.
units
.
add
(
orgunit_id
,
through_defaults
=
{
'
hierarchical_access
'
:
hierarchical_access
})
sponsor
.
units
.
add
(
orgunit_id
,
through_defaults
=
{
"
hierarchical_access
"
:
hierarchical_access
}
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
"""
Overridden because a delete at this endpoint should not attempt to delete the organizational unit,
"""
Overridden because a delete at this endpoint should not attempt to delete the organizational unit,
but the link between the sponsor and the unit
"""
(
sponsor_id
,
orgunit_id
)
=
self
.
_extract_sponsor_and_orgunit
(
kwargs
)
sponsor
=
Sponsor
.
objects
.
filter
(
id
=
sponsor_id
).
get
()
...
...
This diff is collapsed.
Click to expand it.
greg/tests/api/test_sponsor.py
+
24
−
14
View file @
86e39a98
...
...
@@ -66,12 +66,12 @@ def test_add_sponsor_with_unit(client, unit_foo: OrganizationalUnit):
assert
len
(
sponsor_lookup_response_body
[
"
results
"
])
==
1
assert
len
(
sponsor_lookup_response_body
[
"
results
"
][
0
][
"
units
"
])
==
0
data
=
{
"
hierarchical_access
"
:
True
}
data
=
{
"
hierarchical_access
"
:
True
}
create_sponsor_link_url
=
reverse
(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_id
,
"
orgunit_id
"
:
unit_foo
.
id
})
create_sponsor_link_url
=
reverse
(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_id
,
"
orgunit_id
"
:
unit_foo
.
id
},
)
response
=
client
.
post
(
create_sponsor_link_url
,
data
=
data
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
...
...
@@ -84,17 +84,19 @@ def test_add_sponsor_with_unit(client, unit_foo: OrganizationalUnit):
@pytest.mark.django_db
def
test_remove_sponsor_orgunit_link
(
client
,
sponsor_guy
:
Sponsor
,
unit_foo
:
OrganizationalUnit
):
def
test_remove_sponsor_orgunit_link
(
client
,
sponsor_guy
:
Sponsor
,
unit_foo
:
OrganizationalUnit
):
sponsor_detail_url
=
reverse
(
"
v1:sponsor-detail
"
,
kwargs
=
{
"
id
"
:
sponsor_guy
.
id
})
response_get
=
client
.
get
(
sponsor_detail_url
).
json
()
assert
len
(
response_get
[
"
units
"
])
==
0
data
=
{
"
hierarchical_access
"
:
True
}
data
=
{
"
hierarchical_access
"
:
True
}
sponsor_orgunit_url
=
reverse
(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_guy
.
id
,
"
orgunit_id
"
:
unit_foo
.
id
})
sponsor_orgunit_url
=
reverse
(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_guy
.
id
,
"
orgunit_id
"
:
unit_foo
.
id
},
)
response
=
client
.
post
(
sponsor_orgunit_url
,
data
=
data
)
assert
response
.
status_code
==
status
.
HTTP_204_NO_CONTENT
...
...
@@ -111,8 +113,13 @@ def test_remove_sponsor_orgunit_link(client, sponsor_guy: Sponsor, unit_foo: Org
@pytest.mark.django_db
def
test_delete_sponsor_connected_to_identity_not_allowed
(
client
,
sponsor_guy
:
Sponsor
,
person_foo
:
Person
,
person_foo_verified
:
Identity
,
unit_foo
:
OrganizationalUnit
):
def
test_delete_sponsor_connected_to_identity_not_allowed
(
client
,
sponsor_guy
:
Sponsor
,
person_foo
:
Person
,
person_foo_verified
:
Identity
,
unit_foo
:
OrganizationalUnit
,
):
sponsor_detail_url
=
reverse
(
"
v1:sponsor-detail
"
,
kwargs
=
{
"
id
"
:
sponsor_guy
.
id
})
response_get
=
client
.
get
(
sponsor_detail_url
).
json
()
assert
len
(
response_get
[
"
units
"
])
==
0
...
...
@@ -125,7 +132,10 @@ def test_delete_sponsor_connected_to_identity_not_allowed(client, sponsor_guy: S
assert
response_get
[
"
id
"
]
==
sponsor_guy
.
id
# Remove the identity and try to delete the sponsor again
url_delete
=
reverse
(
"
v1:person_identity-detail
"
,
kwargs
=
{
"
person_id
"
:
person_foo
.
id
,
"
id
"
:
person_foo_verified
.
id
})
url_delete
=
reverse
(
"
v1:person_identity-detail
"
,
kwargs
=
{
"
person_id
"
:
person_foo
.
id
,
"
id
"
:
person_foo_verified
.
id
},
)
client
.
delete
(
url_delete
)
response_delete
=
client
.
delete
(
sponsor_detail_url
)
...
...
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