Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Jul 17, 2024
1 parent 34c3f63 commit 37156fd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 46 deletions.
1 change: 1 addition & 0 deletions apps/geo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,6 @@ def validate(self, data):
return data

def update(self, instance, validated_data):
instance.is_published = True
data = super().update(instance, validated_data)
return data
41 changes: 41 additions & 0 deletions apps/geo/tests/test_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from utils.graphene.tests import GraphQLTestCase

from geo.models import Region
from geo.factories import RegionFactory


class CreateTestMutation(GraphQLTestCase):
Expand Down Expand Up @@ -64,3 +65,43 @@ def _query_check(minput, **kwargs):
content = _query_check(minput)
self.assertNotIn(non_project_member_user, project.members.all())
self.assertEqual(content['data']['createRegion']['errors'][0]['messages'], "Permission Denied")

def test_publish_region(self):
self.publish_region_query = '''
mutation MyMutation($id:ID!){
publishRegion(id: $id) {
ok
errors
}
}
'''
user = UserFactory.create()
other_user = UserFactory.create()
project = ProjectFactory.create()
region = RegionFactory.create(created_by=user)
project.add_member(user)

def _query_check(**kwargs):
return self.query_check(
self.publish_region_query,
variables={'id': region.id},
# minput=minput,
**kwargs
)
_query_check(assert_for_error=True)

# login with user

self.force_login(user)
content = _query_check()
region.refresh_from_db()
self.assertEqual(content['data']['publishRegion']['errors'], None)
self.assertEqual(region.is_published, True)

# login with other user
self.force_login(other_user)
content = _query_check()
self.assertEqual(
content['data']['publishRegion']['errors'][0]['messages'],
'Authorized User can only published the region'
)
47 changes: 1 addition & 46 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3614,22 +3614,12 @@ type CreateProjectJoin {
result: ProjectJoinRequestType
}

<<<<<<< HEAD
type CreateRegion {
errors: [GenericScalar!]
ok: Boolean
result: RegionDetailType
}

||||||| parent of fd4de667e (implemented region in graphql)
=======
type CreateRegion {
errors: [GenericScalar!]
ok: Boolean
result: RegionType
}

>>>>>>> fd4de667e (implemented region in graphql)
type CreateUnifiedConnector {
errors: [GenericScalar!]
ok: Boolean
Expand Down Expand Up @@ -5007,20 +4997,11 @@ type MissingPredictionReviewType {
}

type Mutation {
<<<<<<< HEAD
createRegion(data: RegionInputType!): CreateRegion
<<<<<<< HEAD
createAdminLevel(data: AdminLevelInputType!): CreateAdminLevel
updateAdminLevel(data: AdminLevelInputType!, id: ID!): UpdateAdminLevel
publishRegion(id: ID!): PublishRegion
organizationCreate(data: OrganizationInputType!): OrganizationCreate
||||||| parent of fd4de667e (implemented region in graphql)
=======
createRegion(data: RegionInputType!): CreateRegion
>>>>>>> fd4de667e (implemented region in graphql)
||||||| parent of b652dd00b (publish the geoarea in the project)
=======
publishRegion(data: RegionPublishInputType!, id: ID!): PublishRegion
>>>>>>> b652dd00b (publish the geoarea in the project)
createAssessmentRegSummaryIssue(data: AssessmentRegistrySummaryIssueCreateInputType!): AssessmentRegistryCreateIssue
fileUpload(data: FileUploadInputType!): UploadFile
genericExportCreate(data: GenericExportCreateInputType!): CreateUserGenericExport
Expand Down Expand Up @@ -5897,34 +5878,13 @@ type RegionDetailType {
adminLevels: [AdminLevelType!]
}

<<<<<<< HEAD
input RegionInputType {
title: String!
code: String!
project: ID!
clientId: String
}

||||||| parent of fd4de667e (implemented region in graphql)
=======
input RegionInputType {
clientId: String
project: Int!
code: String!
title: String!
public: Boolean
isPublished: Boolean
regionalGroups: GenericScalar
keyFigures: GenericScalar
populationData: GenericScalar
mediaSources: GenericScalar
cacheIndex: Int
centroid: String
geoOptions: GenericScalar
createdBy: ID
}

>>>>>>> fd4de667e (implemented region in graphql)
type RegionListType {
results: [RegionType!]
totalCount: Int
Expand Down Expand Up @@ -5954,11 +5914,6 @@ input RegionProjectFilterData {
isTest: Boolean
}

input RegionPublishInputType {
isPublished: Boolean
project: Int!
}

type RegionType {
id: ID!
title: String!
Expand Down

0 comments on commit 37156fd

Please sign in to comment.