diff --git a/apps/assessment_registry/mutation.py b/apps/assessment_registry/mutation.py index 27077ad5e9..7884293ddd 100644 --- a/apps/assessment_registry/mutation.py +++ b/apps/assessment_registry/mutation.py @@ -57,7 +57,7 @@ class Arguments: class UpdateAssessmentRegistry(AssessmentRegsitryMutationMixin, PsGrapheneMutation): class Arguments: data = AssessmentRegistryCreateInputType(required=True) - id = graphene.ID(required=False) + id = graphene.ID(required=True) result = graphene.Field(AssessmentRegistryType) serializer_class = AssessmentRegistrySerializer diff --git a/apps/assessment_registry/tests/test_mutation.py b/apps/assessment_registry/tests/test_mutation.py index 64eff90bde..9edd8303d9 100644 --- a/apps/assessment_registry/tests/test_mutation.py +++ b/apps/assessment_registry/tests/test_mutation.py @@ -123,12 +123,121 @@ class TestAssessmentRegistryMutation(GraphQLTestCase): } } ''' + UPDATE_ASSESSMENT_REGISTRY_QUERY = ''' + mutation MyMutation ($projectId: ID!, $input: AssessmentRegistryCreateInputType!, $assessmentRegistryId: ID!) { + project(id:$projectId) { + updateAssessmentRegistry(data: $input, id: $assessmentRegistryId) { + ok + errors + result { + id + affectedGroups + bgPreparedness + bgCountries { + id + } + bgCrisisStartDate + bgCrisisType + confidentiality + confidentialityDisplay + coordinatedJoint + coordinatedJointDisplay + costEstimatesUsd + createdAt + dataCollectionEndDate + dataCollectionStartDate + dataCollectionTechniques + detailsType + detailsTypeDisplay + externalSupport + externalSupportDisplay + family + familyDisplay + metadataComplete + focuses + frequency + frequencyDisplay + language + limitations + modifiedAt + noOfPages + objectives + protectionInfoMgmts + protectionRisks + publicationDate + sampling + sectors + status + focusComplete + lead { + id + } + methodologyAttributes { + unitOfReportingDisplay + unitOfReporting + unitOfAnalysis + unitOfAnalysisDisplay + samplingApproach + samplingAppraochDisplay + proximity + proximityDisplay + id + dataCollectionTechniqueDisplay + dataCollectionTechnique + } + methodologyComplete + additionalDocuments { + documentType + documentTypeDisplay + externalLink + id + file { + id + mimeType + metadata + } + } + additionalDocumentComplete + cna { + answer + id + question { + id + question + sector + subSector + sectorDisplay + subSectorDisplay + } + } + cnaComplete + summaryDimensionMeta { + id + percentageInNeed + } + summarySubDimensionIssue { + id + } + summaryPillarMeta { + id + totalPeopleAssessed + } + summarySubPillarIssue { + id + } + summaryComplete + } + } + } + } +''' def setUp(self): super().setUp() self.member_user = UserFactory.create() self.project1 = ProjectFactory.create() self.lead1 = LeadFactory.create(project=self.project1) + self.lead2 = LeadFactory.create(project=self.project1) self.organization1 = OrganizationFactory.create() self.organization2 = OrganizationFactory.create() self.region = RegionFactory.create() @@ -296,3 +405,189 @@ def _query_check(minput, **kwargs): self.assertIsNotNone(data['summarySubDimensionIssue']) self.assertEqual(data['metadataComplete'], True) self.assertIsNotNone(data['protectionRisks']) + + def test_update_assessment_registry(self): + def _query_check(mutation, minput, variables, **kwargs): + return self.query_check( + mutation, + minput=minput, + variables=variables, + **kwargs + ) + + minput = dict( + bgCrisisStartDate="2023-01-01", + bgCrisisType=self.genum(AssessmentRegistry.CrisisType.EARTH_QUAKE), + bgPreparedness=self.genum(AssessmentRegistry.PreparednessType.WITH_PREPAREDNESS), + confidentiality=self.genum(AssessmentRegistry.ConfidentialityType.UNPROTECTED), + coordinatedJoint=self.genum(AssessmentRegistry.CoordinationType.COORDINATED), + costEstimatesUsd=10, + status=self.genum(AssessmentRegistry.StatusType.PLANNED), + detailsType=self.genum(AssessmentRegistry.Type.INITIAL), + externalSupport=self.genum(AssessmentRegistry.ExternalSupportType.EXTERNAL_SUPPORT_RECIEVED), + family=self.genum(AssessmentRegistry.FamilyType.DISPLACEMENT_TRAKING_MATRIX), + focuses=[ + self.genum(AssessmentRegistry.FocusType.CONTEXT), + self.genum(AssessmentRegistry.FocusType.HUMANITERIAN_ACCESS), + self.genum(AssessmentRegistry.FocusType.DISPLACEMENT) + ], + frequency=self.genum(AssessmentRegistry.FrequencyType.ONE_OFF), + protectionInfoMgmts=[ + self.genum(AssessmentRegistry.ProtectionInfoType.PROTECTION_MONITORING), + self.genum(AssessmentRegistry.ProtectionInfoType.PROTECTION_NEEDS_ASSESSMENT) + ], + protectionRisks=[ + self.genum(AssessmentRegistry.ProtectionRiskType.ABDUCATION_KIDNAPPING), + self.genum(AssessmentRegistry.ProtectionRiskType.ATTACKS_ON_CIVILIANS) + ], + sectors=[ + self.genum(AssessmentRegistry.SectorType.HEALTH), + self.genum(AssessmentRegistry.SectorType.SHELTER), + self.genum(AssessmentRegistry.SectorType.WASH) + ], + lead=self.lead1.id, + locations=[self.geo_area1.id, self.geo_area2.id], + dataCollectionEndDate="2023-01-01", + dataCollectionStartDate="2023-01-01", + dataCollectionTechniques="Test Data", + limitations="test", + objectives="test", + noOfPages=10, + publicationDate="2023-01-01", + sampling="test", + language=[ + self.genum(AssessmentRegistry.Language.ENGLISH), + self.genum(AssessmentRegistry.Language.SPANISH) + ], + bgCountries=[self.region.id], + affectedGroups=[self.genum(AssessmentRegistry.AffectedGroupType.ALL_AFFECTED)], + metadataComplete=True, + additionalDocumentComplete=True, + focusComplete=True, + methodologyComplete=True, + methodologyAttributes=[ + dict( + dataCollectionTechnique=self.genum(MethodologyAttribute.CollectionTechniqueType.SECONDARY_DATA_REVIEW), + proximity=self.genum(MethodologyAttribute.ProximityType.FACE_TO_FACE), + samplingApproach=self.genum(MethodologyAttribute.SamplingApproachType.NON_RANDOM_SELECTION), + samplingSize=10, + unitOfAnalysis=self.genum(MethodologyAttribute.UnitOfAnalysisType.CRISIS), + unitOfReporting=self.genum(MethodologyAttribute.UnitOfReportingType.CRISIS) + ), + ], + additionalDocuments=[ + dict( + documentType=self.genum(AdditionalDocument.DocumentType.ASSESSMENT_DATABASE), + externalLink="", + file=str(self.file.id) + ), + ], + scoreRatings=[ + dict( + scoreType=self.genum(ScoreRating.ScoreCriteria.ASSUMPTIONS), + rating=self.genum(ScoreRating.RatingType.VERY_POOR), + reason="test" + ), + dict( + scoreType=self.genum(ScoreRating.ScoreCriteria.RELEVANCE), + rating=self.genum(ScoreRating.RatingType.VERY_POOR), + reason="test" + ) + ], + scoreAnalyticalDensity=[ + dict( + sector=self.genum(AssessmentRegistry.SectorType.FOOD_SECURITY), + analysisLevelCovered=[ + self.genum(ScoreAnalyticalDensity.AnalysisLevelCovered.ISSUE_UNMET_NEEDS_ARE_DETAILED), + self.genum(ScoreAnalyticalDensity.AnalysisLevelCovered.ISSUE_UNMET_NEEDS_ARE_PRIORITIZED_RANKED), + ], + figureProvided=[ + self.genum(ScoreAnalyticalDensity.FigureProvidedByAssessment.TOTAL_POP_IN_THE_ASSESSED_AREAS), + ], + score=1, + ), + dict( + sector=self.genum(AssessmentRegistry.SectorType.SHELTER), + analysisLevelCovered=[], + score=2 + ) + ], + cna=[ + dict( + answer=True, + question=self.question1.id, + ) + ], + summaryPillarMeta=dict( + totalPeopleAssessed=1000 + ), + summarySubPillarIssue=[ + dict( + summaryIssue=self.summary_issue1.id, + order=1, + ) + ], + summaryDimensionMeta=[ + dict( + percentageInNeed=10, + sector=self.genum(AssessmentRegistry.SectorType.FOOD_SECURITY), + ), + dict( + percentageInNeed=10, + sector=self.genum(AssessmentRegistry.SectorType.SHELTER), + ), + ], + summarySubDimensionIssue=[ + dict( + summaryIssue=self.summary_issue2.id, + sector=self.genum(AssessmentRegistry.SectorType.FOOD_SECURITY), + order=1, + ) + ] + ) + update_minput = dict( + bgCrisisType=self.genum(AssessmentRegistry.CrisisType.LANDSLIDE), + bgPreparedness=self.genum(AssessmentRegistry.PreparednessType.WITHOUT_PREPAREDNESS), + confidentiality=self.genum(AssessmentRegistry.ConfidentialityType.CONFIDENTIAL), + coordinatedJoint=self.genum(AssessmentRegistry.CoordinationType.HARMONIZED), + status=self.genum(AssessmentRegistry.StatusType.ONGOING), + detailsType=self.genum(AssessmentRegistry.Type.MONITORING), + externalSupport=self.genum(AssessmentRegistry.ExternalSupportType.NO_EXTERNAL_SUPPORT_RECEIVED), + family=self.genum(AssessmentRegistry.FamilyType.HUMANITARIAN_NEEDS_OVERVIEW), + frequency=self.genum(AssessmentRegistry.FrequencyType.REGULAR), + lead=self.lead2.id, + language=[ + self.genum(AssessmentRegistry.Language.ENGLISH), + self.genum(AssessmentRegistry.Language.FRENCH) + ], + bgCountries=[self.region.id], + ) + self.force_login(self.member_user) + content = _query_check( + self.CREATE_ASSESSMENT_REGISTRY_QUERY, + minput, + variables={'projectId': self.project1.id}, + okay=False + ) + assessment_registry_id = content['data']['project']['createAssessmentRegistry']['result']['id'] + self.assertIsNotNone(content['data']['project']['createAssessmentRegistry']['result']['id']) + content = _query_check( + self.UPDATE_ASSESSMENT_REGISTRY_QUERY, + update_minput, + variables={'projectId': self.project1.id, 'assessmentRegistryId': assessment_registry_id}, + okay=False + ) + data = content['data']['project']['updateAssessmentRegistry']['result'] + self.assertEqual(data['id'], assessment_registry_id) + self.assertEqual(data['bgCrisisType'], update_minput['bgCrisisType']) + self.assertEqual(data['bgPreparedness'], update_minput['bgPreparedness']) + self.assertEqual(data['confidentiality'], update_minput['confidentiality']) + self.assertEqual(data['coordinatedJoint'], update_minput['coordinatedJoint']) + self.assertEqual(data['status'], update_minput['status']) + self.assertEqual(data['detailsType'], update_minput['detailsType']) + self.assertEqual(data['externalSupport'], update_minput['externalSupport']) + self.assertEqual(data['family'], update_minput['family']) + self.assertEqual(data['frequency'], update_minput['frequency']) + self.assertEqual(data['lead']['id'], str(update_minput['lead'])) + self.assertEqual(data['language'], update_minput['language']) + self.assertEqual(data['bgCountries'][0]['id'], str(update_minput['bgCountries'][0]))