-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change
updateUser
endpoint to updateStaffUser
Endpoint only works for staff users, and there is now need for another user update endpoint that can update other user data.
- Loading branch information
1 parent
443444d
commit 16dd1ae
Showing
10 changed files
with
138 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from functools import partial | ||
|
||
from graphene_django_extensions.testing import build_query | ||
from graphene_django_extensions.testing import build_mutation, build_query | ||
|
||
current_user_query = partial(build_query, "currentUser") | ||
|
||
STAFF_UPDATE_MUTATION = build_mutation("updateStaffUser", "UserStaffUpdateMutation") |
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
tests/test_graphql_api/test_user/test_update_permissions.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
from tests.factories import UserFactory | ||
from tilavarauspalvelu.enums import ReservationNotification | ||
|
||
from .helpers import STAFF_UPDATE_MUTATION | ||
|
||
# Applied to all tests | ||
pytestmark = [ | ||
pytest.mark.django_db, | ||
] | ||
|
||
|
||
def test_user__update_staff(graphql): | ||
user = UserFactory.create_superuser(reservation_notification=ReservationNotification.ONLY_HANDLING_REQUIRED) | ||
|
||
data = { | ||
"pk": user.pk, | ||
"reservationNotification": ReservationNotification.NONE.value.upper(), | ||
} | ||
|
||
graphql.force_login(user) | ||
response = graphql(STAFF_UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False | ||
assert response.first_query_object["pk"] == user.pk | ||
|
||
user.refresh_from_db() | ||
assert user.reservation_notification == ReservationNotification.NONE |
84 changes: 84 additions & 0 deletions
84
tests/test_graphql_api/test_user/test_update_staff_permissions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import pytest | ||
|
||
from tests.factories import UserFactory | ||
from tilavarauspalvelu.enums import ReservationNotification, UserRoleChoice | ||
|
||
from .helpers import STAFF_UPDATE_MUTATION | ||
|
||
# Applied to all tests | ||
pytestmark = [ | ||
pytest.mark.django_db, | ||
] | ||
|
||
|
||
def test_user__update__superuser(graphql): | ||
user = UserFactory.create_superuser(reservation_notification=ReservationNotification.ONLY_HANDLING_REQUIRED) | ||
graphql.force_login(user) | ||
|
||
data = { | ||
"pk": user.pk, | ||
"reservationNotification": ReservationNotification.NONE.value.upper(), | ||
} | ||
response = graphql(STAFF_UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False | ||
|
||
user.refresh_from_db() | ||
assert user.reservation_notification == ReservationNotification.NONE | ||
|
||
|
||
def test_user__update__anonymous_user(graphql): | ||
user = UserFactory.create(reservation_notification=ReservationNotification.ONLY_HANDLING_REQUIRED) | ||
|
||
data = { | ||
"pk": user.pk, | ||
"reservationNotification": ReservationNotification.NONE.value.upper(), | ||
} | ||
response = graphql(STAFF_UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.error_message() == "No permission to update." | ||
|
||
|
||
def test_user__update__cannot_update_other_user(graphql): | ||
user = UserFactory.create_superuser(reservation_notification=ReservationNotification.ONLY_HANDLING_REQUIRED) | ||
graphql.login_with_regular_user() | ||
|
||
data = { | ||
"pk": user.pk, | ||
"reservationNotification": ReservationNotification.NONE.value.upper(), | ||
} | ||
response = graphql(STAFF_UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.error_message() == "No permission to update." | ||
|
||
|
||
def test_user__update__regular_user(graphql): | ||
user = UserFactory.create(reservation_notification=ReservationNotification.ONLY_HANDLING_REQUIRED) | ||
graphql.force_login(user) | ||
|
||
data = { | ||
"pk": user.pk, | ||
"reservationNotification": ReservationNotification.NONE.value.upper(), | ||
} | ||
response = graphql(STAFF_UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.error_message() == "No permission to update." | ||
|
||
|
||
def test_user__update__admin_user(graphql): | ||
user = UserFactory.create_with_general_role( | ||
role=UserRoleChoice.ADMIN, | ||
reservation_notification=ReservationNotification.ONLY_HANDLING_REQUIRED, | ||
) | ||
graphql.force_login(user) | ||
|
||
data = { | ||
"pk": user.pk, | ||
"reservationNotification": ReservationNotification.NONE.value.upper(), | ||
} | ||
response = graphql(STAFF_UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False | ||
|
||
user.refresh_from_db() | ||
assert user.reservation_notification == ReservationNotification.NONE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
from graphene_django_extensions import UpdateMutation | ||
|
||
from .permissions import UserPermission | ||
from .serializers import UserUpdateSerializer | ||
from .permissions import UserStaffPermission | ||
from .serializers import UserStaffUpdateSerializer | ||
|
||
__all__ = [ | ||
"UserStaffUpdateMutation", | ||
] | ||
|
||
class UserUpdateMutation(UpdateMutation): | ||
|
||
class UserStaffUpdateMutation(UpdateMutation): | ||
class Meta: | ||
serializer_class = UserUpdateSerializer | ||
permission_classes = [UserPermission] | ||
serializer_class = UserStaffUpdateSerializer | ||
permission_classes = [UserStaffPermission] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters