-
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.
Add endpoint for updating user language
- Loading branch information
1 parent
16dd1ae
commit f9723d2
Showing
7 changed files
with
134 additions
and
3 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
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,43 @@ | ||
import pytest | ||
|
||
from tests.factories import UserFactory | ||
from tilavarauspalvelu.enums import Language | ||
|
||
from .helpers import UPDATE_MUTATION | ||
|
||
# Applied to all tests | ||
pytestmark = [ | ||
pytest.mark.django_db, | ||
] | ||
|
||
|
||
def test_user__update__language(graphql): | ||
user = UserFactory.create_superuser(preferred_language=Language.EN.value) | ||
|
||
data = { | ||
"pk": user.pk, | ||
"preferredLanguage": Language.FI.value.upper(), | ||
} | ||
|
||
graphql.force_login(user) | ||
response = graphql(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.preferred_language == Language.FI.value | ||
|
||
|
||
def test_user__update__language_not_available(graphql): | ||
user = UserFactory.create_superuser(preferred_language=Language.EN.value) | ||
|
||
data = { | ||
"pk": user.pk, | ||
"preferredLanguage": "UK", | ||
} | ||
|
||
graphql.force_login(user) | ||
response = graphql(UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.has_schema_errors is True, response |
67 changes: 67 additions & 0 deletions
67
tests/test_graphql_api/test_user/test_update_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,67 @@ | ||
import pytest | ||
|
||
from tests.factories import UserFactory | ||
from tilavarauspalvelu.enums import Language | ||
|
||
from .helpers import UPDATE_MUTATION | ||
|
||
# Applied to all tests | ||
pytestmark = [ | ||
pytest.mark.django_db, | ||
] | ||
|
||
|
||
def test_user__update__language__superuser(graphql): | ||
user = UserFactory.create_superuser() | ||
|
||
data = { | ||
"pk": user.pk, | ||
"preferredLanguage": Language.FI.value.upper(), | ||
} | ||
|
||
graphql.force_login(user) | ||
response = graphql(UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False | ||
|
||
|
||
def test_user__update__language__regular_user(graphql): | ||
user = UserFactory.create() | ||
|
||
data = { | ||
"pk": user.pk, | ||
"preferredLanguage": Language.FI.value.upper(), | ||
} | ||
|
||
graphql.force_login(user) | ||
response = graphql(UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False | ||
|
||
|
||
def test_user__update__language__other_user(graphql): | ||
user = UserFactory.create_superuser() | ||
|
||
data = { | ||
"pk": user.pk, | ||
"preferredLanguage": Language.FI.value.upper(), | ||
} | ||
|
||
graphql.login_with_regular_user() | ||
response = graphql(UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.error_message() == "No permission to update." | ||
|
||
|
||
def test_user__update__language__admin(graphql): | ||
user = UserFactory.create_with_general_role() | ||
|
||
data = { | ||
"pk": user.pk, | ||
"preferredLanguage": Language.FI.value.upper(), | ||
} | ||
|
||
graphql.force_login(user) | ||
response = graphql(UPDATE_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False |
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
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