Skip to content

Commit

Permalink
add testcase of create region mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Apr 8, 2024
1 parent fd4de66 commit df9b4fa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
11 changes: 8 additions & 3 deletions apps/geo/mutations.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
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',
serializer_class=RegionGqSerializer,
)


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():
Expand Down
48 changes: 48 additions & 0 deletions apps/geo/tests/test_mutations.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit df9b4fa

Please sign in to comment.