Skip to content

Commit

Permalink
Update testcase of region mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Apr 30, 2024
1 parent d86c9e0 commit 528ba78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
21 changes: 5 additions & 16 deletions apps/geo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
ProjectPropertySerializerMixin,
RemoveNullFieldsMixin,
URLCachedFileField,
IntegerIDField,
)
from rest_framework import serializers
from user_resource.serializers import UserResourceSerializer
Expand Down Expand Up @@ -156,23 +155,17 @@ class Meta:


class RegionGqSerializer(ProjectPropertySerializerMixin, UserResourceSerializer):
project = IntegerIDField()
project = serializers.PrimaryKeyRelatedField(queryset=Project.objects.all())
client_id = serializers.CharField(required=False)

class Meta:
model = Region
exclude = ('geo_options', 'is_published')
fields = ['title', 'code', 'project', 'client_id']

def validate_project(self, project):
try:
project = Project.objects.get(id=project)
except Project.DoesNotExist:
raise serializers.ValidationError(
'Project matching query does not exist'
)

if not project.can_modify(self.context['request'].user):
raise serializers.ValidationError('Permission Denied')
return project.id
return project

def validate(self, data):
if self.instance and self.instance.is_published:
Expand All @@ -182,9 +175,5 @@ def validate(self, data):
def create(self, validated_data):
project = validated_data.pop('project', None)
region = super().create(validated_data)

if project:
project = Project.objects.get(id=project)
project.regions.add(region)

project.regions.add(region)
return region
11 changes: 5 additions & 6 deletions apps/geo/tests/test_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def test_create_region_in_project(self):
user = UserFactory.create()
user2 = UserFactory.create()
project = ProjectFactory.create(
title="dummy project 1",
created_by=user
)
project.add_member(user)
Expand All @@ -34,11 +33,11 @@ def _query_check(minput, **kwargs):
**kwargs
)

minput = dict(
project=project.id,
code="NPL",
title="Test",
)
minput = {
'project': project.id,
'code': 'NPL',
'title': 'Test'
}
# without login
_query_check(minput, assert_for_error=True)

Expand Down
14 changes: 3 additions & 11 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5760,18 +5760,10 @@ type RegionDetailType {
}

input RegionInputType {
clientId: String
project: ID!
code: String!
title: String!
public: Boolean
regionalGroups: GenericScalar
keyFigures: GenericScalar
populationData: GenericScalar
mediaSources: GenericScalar
cacheIndex: Int
centroid: String
createdBy: ID
code: String!
project: ID!
clientId: String
}

type RegionListType {
Expand Down

0 comments on commit 528ba78

Please sign in to comment.