diff --git a/apps/geo/mutations.py b/apps/geo/mutations.py index f0ed2606c7..e6ff8f98db 100644 --- a/apps/geo/mutations.py +++ b/apps/geo/mutations.py @@ -1,10 +1,11 @@ import graphene + from geo.models import Region from geo.schema import RegionType from geo.serializers import RegionGqSerializer from deep.permissions import ProjectPermissions as PP -from utils.graphene.mutation import PsGrapheneMutation, generate_input_type_for_serializer +from utils.graphene.mutation import GrapheneMutation, generate_input_type_for_serializer RegionInputType = generate_input_type_for_serializer( 'RegionInputType', @@ -12,13 +13,17 @@ ) -class CreateRegion(PsGrapheneMutation): +class CreateRegion(GrapheneMutation): class Arguments: data = RegionInputType(required=True) model = Region serializer_class = RegionGqSerializer result = graphene.Field(RegionType) - permissions = [PP.Permission.UPDATE_PROJECT] + + @classmethod + def check_permissions(cls, *args, **_): + if PP.Permission.UPDATE_PROJECT: + return True class Mutation(): diff --git a/apps/geo/tests/test_mutations.py b/apps/geo/tests/test_mutations.py new file mode 100644 index 0000000000..b349cda80b --- /dev/null +++ b/apps/geo/tests/test_mutations.py @@ -0,0 +1,48 @@ +from user.factories import UserFactory +from project.factories import ProjectFactory +from utils.graphene.tests import GraphQLTestCase + + +class CreateTestMutation(GraphQLTestCase): + def test_create_region_in_project(self): + self.region_query = ''' + mutation MyMutation($input: RegionInputType!){ + createRegion(data: $input) { + ok + errors + result { + id + title + } + } + } + ''' + user = UserFactory.create() + project = ProjectFactory.create( + title="dummy project 1", + created_by=user + ) + project.add_member(user) + + def _query_check(minput, **kwargs): + return self.query_check( + self.region_query, + minput=minput, + **kwargs + ) + # -- Without login + + minput = dict( + project=project.id, + code="NPL", + title="Test", + ) + # without login + _query_check(minput, assert_for_error=True) + + self.force_login(user) + + _query_check(minput) + content = _query_check(minput) + self.assertEqual(content['data']['createRegion']['errors'], None) + self.assertEqual(content['data']['createRegion']['result']['title'], "Test")